papgroup / nsubstitute.fluentassertionsbridge Goto Github PK
View Code? Open in Web Editor NEWa library for bridging between NSubstitute and FluentAssertions
License: MIT License
a library for bridging between NSubstitute and FluentAssertions
License: MIT License
Why should I use this lib instead of https://github.com/benagain/NSubstitute.Verify.That/?
reverse question: benagain/NSubstitute.Verify.That#5
This works as expected:
[Test]
public void Fails_WhenNotCalled()
{
var service = Substitute.For<IRegistrationService>();
var expected = new RegistrationModel() { Username = "Admin", Password = "123456" };
service.Received(1)
.Register(Verify.That<RegistrationModel>(a => a.Should().BeEquivalentTo(expected)));
}
[Test]
public void Fails_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.Received(1)
.Register(Verify.That<RegistrationModel>(a => a.Should().BeEquivalentTo(expected)));
}
[Test]
public void Works_WhenCalled()
{
var service = Substitute.For<IRegistrationService>();
var expected = new RegistrationModel() { Username = "Admin", Password = "123456" };
service.Register(expected);
service.Received(1)
.Register(Verify.That<RegistrationModel>(a => a.Should().BeEquivalentTo(expected)));
}
public class RegistrationModel
{
public string Username { get; set; }
public string Password { get; set; }
}
public interface IRegistrationService
{
void Register(RegistrationModel that);
}
But when you use .ReceivedWithAnyArgs
it suddenly fails:
[Test]
public void Fails_WhenNotCalled()
{
var service = Substitute.For<IRegistrationService>();
var expected = new RegistrationModel() { Username = "Admin", Password = "123456" };
service.ReceivedWithAnyArgs(1)
.Register(Verify.That<RegistrationModel>(a => a.Should().BeEquivalentTo(expected)));
}
[Test]
public void Fails_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.ReceivedWithAnyArgs(1)
.Register(Verify.That<RegistrationModel>(a => a.Should().BeEquivalentTo(expected)));
}
[Test]
public void Works_WhenCalled()
{
var service = Substitute.For<IRegistrationService>();
var expected = new RegistrationModel() { Username = "Admin", Password = "123456" };
service.Register(expected);
service.ReceivedWithAnyArgs(1)
.Register(Verify.That<RegistrationModel>(a => a.Should().BeEquivalentTo(expected)));
}
public class RegistrationModel
{
public string Username { get; set; }
public string Password { get; set; }
}
public interface IRegistrationService
{
void Register(RegistrationModel that);
}
All tests work, except the one in the middle, this now suddenly succeeds, although it should fail:
The test should fail, as before.
FluentAssertionsBridge v 1.0.0
NSubstitute 4.4.0
IList
may have caused this, but apparently did not.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)
which is also wrong.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.