Computing parameters with pre-existing values ​​in FakeItEasy

It's a bit strange. I'm trying to stub a method that has parameters, I don't care what parameters are, so I ignore the arguments. It looks like this:

List<Foo> ignored; A.CallTo(() => fake.Method(out ignored)) .Returns(something); 

This works without any problems when the cropped method is called like this:

 List<Foo> target; var result = service.Method(out target); 

However, this does not work when target pre-initialized. For instance:

 List<Foo> target = new List<Foo>(); var result = service.Method(out target); 

When I check Tag on a fake, I see that the out parameters are written as <NULL> , so I suspect that they do not match when the final target is already set to something. I tried setting ignored in my test to new List<Foo>() , and also tried A<List<Foo>>.Ignored , but none of them affected the result.

So my question is: does anyone know how to stub a method with out parameters if the value of the out parameter already has a value?

+4
source share
1 answer

Update: since FakeItEasy 1.23.0, the initial value of the out parameters is ignored when matching, so WithAnyArguments not necessary

Five minutes later, and I found an acceptable solution (in this case). Since I'm not interested in what arguments are passed to this method, so if I use the WithAnyArguments() method, then it seems to work; this should probably combine an argument checking everything together.

End Code:

 List<Foo> ignored; A.CallTo(() => fake.Method(out ignored)) .WithAnyArguments() .Returns(something); 

This obviously does not solve the problem if I do not want to ignore all the arguments. I will accept this answer only if we do not have a more complex solution.

+4
source

Source: https://habr.com/ru/post/1392813/


All Articles