There is not much you can do here (except raising the issue on github like one mentioned in this comment, or this one for nullable value types). Using MemberNotNullWhenAttribute
even if you had access to source code and compiled your version, I'm afraid, won't do much here, cause foo
is not a member of AndConstraint
returned by NotBeNull
.
So you have options of using !
here or chaining assertions which is a little bit cumbersome cause FluentAssertions
for some reason loses type information or writing your own method which wiil encapsulate this check.
For chaining assertions option you can do something like this:
foo.Should().NotBeNull()
.And
.Match<Foo>(f => f.Value == 5);
Or using BeEquivalentTo
for example:
foo.Should().NotBeNull()
.And
.BeEquivalentTo(new Foo {Value = 5});
Note that BeEquivalentTo
sometimes is pretty cumbersome to use also due to it's approach to comparing objects:
Objects are equivalent when both object graphs have equally named properties with the same value, irrespective of the type of those objects. Two properties are also equal if one type can be converted to another and the result is equal. The type of a collection property is ignored as long as the collection implements IEnumerable<T>
and all items in the collection are structurally equal.