Skip to content

Be Not Same into deep #2315

Answered by jnyrup
tisis2 asked this question in Q&A
Sep 22, 2023 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

IEquivalencyStep is what you're looking for.
All user-registered equivalencySteps are run before the built-in, so we can guard against referential equality there.

[Fact]
public void Different_instances()
{
    // Arrange
    var subject = new A { ReferenceType = "", B = new B { PrimitiveType = 42, ValueType = default(Guid) } };
    var clone = new A { ReferenceType = "", B = new B { PrimitiveType = 42, ValueType = default(Guid) } };

    // Act / Assert
    subject.Should().BeEquivalentTo(clone, opt => opt
        .Using(new NotSameEqquivalencyStep()));
}

[Fact]
public void Same_nested_instance()
{
    // Arrange
    B b = new B { PrimitiveType = 42, ValueType = default(Guid) };
    var s…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@tisis2
Comment options

Answer selected by tisis2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants