Skip to content

The FluentAssertions.ArgumentMatchers.FakeItEasy package provides a simple way to use FakeItEasy in combination with FluentAssertions to compare complex objects.

License

Notifications You must be signed in to change notification settings

ronaldbosma/FluentAssertions.ArgumentMatchers.FakeItEasy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nuget

FluentAssertions.ArgumentMatchers.FakeItEasy

The FluentAssertions.ArgumentMatchers.FakeItEasy NuGet package provides a simple way to use FakeItEasy in combination with FluentAssertions to compare complex objects.

IsEquivalentTo

The package has an extension method called IsEquivalentTo for IArgumentConstraintManager<T>. It can be used in the setup and verify stages of a Fake similar to other argument matchers like A<string>.Ignored. The actual.Should().BeEquivalentTo(expected) method is used inside to compare objects. An overload is available so you can pass in configuration to FluentAssertions.

Examples

A.CallTo(() => _fake.DoSomething(A<ComplexType>.That.IsEquivalentTo(expectedComplexType))).Returns(result);

A.CallTo(() => _fake.DoSomething(A<ComplexType>.That.IsEquivalentTo(expectedComplexType))).MustHaveHappenedOnceExactly();

A.CallTo(() => _fake.DoSomething(A<ComplexType>.That.IsEquivalentTo(
    expectedComplexType, 
    options => options.Excluding(c => c.SomeProperty)
))).MustHaveHappenedOnceExactly();

IsEnumerableEquivalentTo

When comparing collections and certain properties need to be ignored, the IsEnumerableEquivalentTo method can be used. The code actual.Should().BeAssignableTo<IEnumerable<TValue>>().Which.Should().BeEquivalentTo(expected, config) is used inside to compare the collections. It's important to note that you need to explicitly use IEnumerable in A<IEnumerable<T>>.That.IsEnumerableEquivalentTo for it to work.

Examples

// Ignore the 'ComplexTypeProperty.IntProperty' property of the ComplexType objects in the collection
A.CallTo(() => _fake.DoSomethingWithCollection(A<IEnumerable<ComplexType>>.That.IsEnumerableEquivalentTo(
    expectedList,
    options => options.Excluding(c => c.ComplexTypeProperty.IntProperty)
))).MustHaveHappenedOnceExactly();

About

The FluentAssertions.ArgumentMatchers.FakeItEasy package provides a simple way to use FakeItEasy in combination with FluentAssertions to compare complex objects.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages