fluentassertions: x.Should().NotBeNull().And.Subject returns object rather than the type of x
It turns out that x.Should().NotBeNull().And returns ObjectAssertions having its Subject of type object rather than of x. So you can’t nest assertions.
Foo foo = new Foo();
AndConstraint<ObjectAssertions> c = foo.Should().NotBeNull();
ObjectAssertions a = c.And;
object s = a.Subject; // here I'd expect Foo
How can it be enhanced?
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 19 (18 by maintainers)
I wish I could use this API in strongly-typed manner so could access subject’s properties, e.g.:
In case you want to prevent “possible NullReferenceException” warnings, this may help.
Example usage: