Watch where you put Received when working with NSubstitute

Problem:

I have a test that I know should be failing but isn’t.

io.Directory.CreateDirectory("bzw").Received();

Solution:

Make sure you have Received in the right location. The line of code above will always pass no matter if the call was made or not. To correct this move Received before CreateDirectory.

io.Directory.Received().CreateDirectory("bzw");
Now the tests evaluates the condition correctly. It would be nice if when Received is last you got a warning or compiler error. But because if the fluent nature of the API and extension methods that code is valid written either way.

Add comment

Loading