I am investigating how to test a project. Some information about the project:
- Microservice architecture, with roughly 20 services. About 10 of them with a separate database.
- We use ServiceFabric
- There is a fair bit of service to service communication.
- Each server is a separate repo. With no references to each other.
- There is one common Nuget package, where some things like date to string. This repo does not have any references to any other repos
I would like to be able to write both unit and integration tests, but I am focusing on unit tests for now. The problem is better illustrated by an example.
Let say I want to test AggrigateAllOrdersForUsers in the OrderMs. The code looks like this:
List<AggrigatedOrderTDO> AggrigateAllOrdersForUsers (List<Guid> userIds)
{
var internalUserIds= userService.GetUsers(userIds); -> calls User ms via REST API
var orders = orderHistoryServer.GetOrdersForUsers(internalUserIds); -> calls OrderHistory ms via REST API
var orderTypes = constantsServer.GetOrderTypes(); -> calls Constants ms via REST API
var validTypes = GetValidOrderTypesForOrderAggrigation(orderTypes) -> internal function
return Aggrigate(internalUserIds, orders , validTypes); -> internal function
}
Orders in this case is a complicated object. It has reference to multiple other classes, where ids need to match. It is not trivial to create, and I would like to reuse the code for creating the fake data.
How would you go about mocking/stubbing/faking the external calls here? It is easy to create a fake for userService, but where do I put it in my source tree? Everything is separate. Do duplicate the fakes? Do I create a new userServiceFake repo? Do I go about it in a completly different way?
Kind regards