I have a service method that calls a repository method; for example:
public async Task<bool> MyMethod(string param1, string param2)
{
var result = myRepository.Where(x => x.param1 == param1).ToList();
await myRepository.doStuff(result);
I'm trying to write a test, which currently looks like this:
var data = new List<MyData>() {new MyData {param1 = "1", param2 = "test"}};
var myRepository = Substitute.For<IMyRepository>();
myRepository.Where(x => x.param1 == "1").ReturnsForAnyArgs(data);
var myService = new MyService(myRepository);
bool w = myService.MyMethod("1", "2");
await myRepository.Received().doStuff(data);
However, I'm getting the failure message:
Message: NSubstitute.Exceptions.ReceivedCallsException : Expected to receive a call matching: doStuff(List< MyData>) Actually received no matching calls. Received 1 non-matching call (non-matching arguments indicated with '*' characters): doStuff(*List< MyData>*)
I've also tried an assertion syntax such as:
await myRepository.Received().doStuff(Arg.Is<List<MyData>>(data));
But it makes no difference. Have I missed something here, or is there something wrong with the way I'm checking the list. My guess is that this relates to the way it's comparing the two lists and so it's not seeing them as the same, but unless I'm mistaken, they are exactly the same.
>());` to prove it gets a list. From there you can then narrow down the conditional match https://nsubstitute.github.io/help/argument-matchers/
– Nkosi Jun 04 '19 at 13:37