Search code examples
c#.net-corefluent-assertionsawesome-assertions

FluentAssertions Asserting multiple properties of a single object


Is there a way to do something like this using FluentAssertions

response.Satisfy(r =>
    r.Property1== "something" &&
    r.Property2== "anotherthing"));

I am trying to avoid writing multiple Assert statements. This was possible with https://sharptestex.codeplex.com/ which I was using for the longest time. But SharpTestEx does not support .Net Core.


Solution

  • You should be able to use general purpose Match assertion to verify multiple properties of the subject via a predicate

    response.Should()
            .Match<MyResponseObject>((x) => 
                x.Property1 == "something" && 
                x.Property2 == "anotherthing"
            );