Giter Club home page Giter Club logo

nsubstitute.fluentassertionsbridge's People

Contributors

alirezashah avatar h-ahmadi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

mjalil siewers

nsubstitute.fluentassertionsbridge's Issues

.ReceivedWithAnyArgs breaks tests/exceptions

STR

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);
      }    

What happens

All tests work, except the one in the middle, this now suddenly succeeds, although it should fail:
grafik

What should happen

The test should fail, as before.

System

FluentAssertionsBridge v 1.0.0
NSubstitute 4.4.0

Notes

  • first thought that I use IList may have caused this, but apparently did not.
  • 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)

which is also wrong.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.