Skip to content

Makaopior/NSubstitute.Equivalency

 
 

Repository files navigation

NSubstitute.Equivalency

CI Status NuGet NuGet PRs Welcome

Motivation

For an intro what this library is solving, check out my blog article.

Get it

dotnet add package NSubstituteEquivalency

or

dotnet paket add NSubstituteEquivalency

Release History

3.0.0:

  • breaking change: made ArgEx.IsCollectionEquivalentTo() generic, introduced ArgEx.IsEnumerableEquivalentTo() and ArgEx.IsArrayEquivalentTo() to support various collection types in arguments

2.0.0

  • breaking change: upgraded to FluentAssertions 6.x

1.1.0:

  • feature: added ArgEx.IsCollectionEquivalentTo()

1.0.0: initial nuget release

Use it

var service = Substitute.For<ISomeInterface>();
DoSomethingWith(service);

service.Received()
    .Use(ArgEx.IsEquivalentTo(new Person
    {
        FirstName = "John",
        LastName = "Doe",
        Birthday = new DateTime(1968, 6, 1)
    }));

or

var service = Substitute.For<ISomeInterface>();
DoSomethingWith(service);

service.Received()
    .Use(ArgEx.IsEquivalentTo(new Person
    {
        FirstName = "John",
        LastName = "Doe"
    }, cfg => cfg.Excluding(p => p.Birthday)));

or

var service = Substitute.For<ISomeInterface>();
DoSomethingWith(service);

service.Received()
    .UseArray(ArgEx.IsArrayEquivalentTo(new []
    {
        new Person(){FirstName = "Alice", LastName = "Wonderland", Birthday = new DateTime(1968, 6, 1)},
        new Person(){FirstName = "Bob", LastName = "Peanut", Birthday = new DateTime(1972, 9, 13)},
    }));

or

var service = Substitute.For<ISomeInterface>();
DoSomethingWith(service);

service.Received()
    .UseEnumerable(ArgEx.IsEnumerableEquivalentTo(new []
    {
        new Person(){FirstName = "Alice", LastName = "Wonderland", Birthday = new DateTime(1968, 6, 1)},
        new Person(){FirstName = "Bob", LastName = "Peanut", Birthday = new DateTime(1972, 9, 13)},
    }));

About

Equivalence based argument matcher for NSubstitute

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 95.5%
  • PowerShell 4.5%