I am trying to understand principle of Unit testing, Purpose, and Moq. We have complicated Service Call.
The Service Call encompasses numerous Repositories and Services, with dependencies and parameters. We are mocking each method per below. By the time we are done mocking, it seems like people are faking whole test, to product an expected result, which we will receive.
Many articles regarding this discuss this issue.
I guess the question is what is best way to test this and general guidelines? If we want to test expected behavior, its as though we are forging it with moq.
Our team has already conducted unit testing for the underliny repository and services below. Lets say the purpose of the Service Call is to calculate car insurance cost. Other repositories services, find out risks, population group, factors, etc
public async Task ServiceCall(int document, Product product)
{
await _servicecall.MethodA;
await _servicecall.MethodB;
await _servicecall.MethodC;
if...etc
await _repository.MethodD;
await _repository.MethodE;
await _servicecall.MethodF;
await _repository.MethodG;
await _servicecall.MethodF;
}
Moq
for each repository and service within
mock.Setup(b => b.ServiceCallB().ReturnsAsync(etc);
Articles:
https://dev.to/asizikov/you-are-mocking-it-wrong-5gh3
https://medium.com/javascript-scene/mocking-is-a-code-smell-944a70c90a6a