feel free to use that provided test code in your source code e.g. in tests or doc
If I reverse the behaviour that is also interesting:
[Test]
public void ShouldWorkNowAsICheckForCorrectPasswordNOTBeingReceived_WhenWronglyCalled()
{
var service = Substitute.For<IRegistrationService>();
var expected = new RegistrationModel() { Username = "Admin", Password = "123456" };
service.Register(new RegistrationModel() { Username = "Admin", Password = "but wrong password" });
service.DidNotReceiveWithAnyArgs()
.Register(Verify.That<RegistrationModel>(a => a.Should().BeEquivalentTo(expected)));
}
This fails with:
NSubstitute.Exceptions.ReceivedCallsException : Expected to receive no calls matching:
Register(any DienstausweisControllerTest+ExportAsLogaExcelFile+RegistrationModel)
Actually received 1 matching call:
Register(DienstausweisControllerTest+ExportAsLogaExcelFile+RegistrationModel)
at NSubstitute.Core.ReceivedCallsExceptionThrower.Throw(ICallSpecification callSpecification, IEnumerable`1 matchingCalls, IEnumerable`1 nonMatchingCalls, Quantity requiredQuantity)
at NSubstitute.Routing.Handlers.CheckReceivedCallsHandler.Handle(ICall call)
at NSubstitute.Routing.Route.Handle(ICall call)
at NSubstitute.Core.CallRouter.Route(ICall call)
at NSubstitute.Proxies.CastleDynamicProxy.CastleForwardingInterceptor.Intercept(IInvocation invocation)
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at NSubstitute.Proxies.CastleDynamicProxy.ProxyIdInterceptor.Intercept(IInvocation invocation)
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Castle.Proxies.ObjectProxy_18.Register(RegistrationModel that)
STR
This works as expected:
But when you use
.ReceivedWithAnyArgs
it suddenly fails:What happens
All tests work, except the one in the middle, this now suddenly succeeds, although it should fail:
What should happen
The test should fail, as before.
System
FluentAssertionsBridge v 1.0.0 NSubstitute 4.4.0
Notes
IList
may have caused this, but apparently did not.If I reverse the behaviour that is also interesting:
This fails with:
which is also wrong.