question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

x.Should().NotBeNull().And.Subject returns object rather than the type of x

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:19 (18 by maintainers)

github_iconTop GitHub Comments

1reaction
bkoelmancommented, Jul 15, 2017

In case you want to prevent “possible NullReferenceException” warnings, this may help.

Example usage:

// Assert
Customer firstCustomer = customers[0].ShouldNotBeNull();
firstCustomer.Name.Should().Be("John Doe");
1reaction
abatishchevcommented, Dec 22, 2014

I wish I could use this API in strongly-typed manner so could access subject’s properties, e.g.:

foo.Should().NotBeNull()
      .And.Subject.Bar.NotBeNull();
Read more comments on GitHub >

github_iconTop Results From Across the Web

fluentassertions C# I Don't understand Should().NotBeNull()
I have read through fluentassertions.com and still confused as to what happens if a var is null or not null. so for instance...
Read more >
Tips - Fluent Assertions
BeTrue() , there is most likely a better way to write it. By having Should() as early as possible in the assertion, we...
Read more >
Fluent Assertions - RSSing.com
object theObject = null; theObject.Should().BeNull("because the value is null"); theObject = "whatever"; theObject.Should().BeOfType< ...
Read more >
Terms Aggregation Usage | Elasticsearch.Net and NEST
A multi-bucket value source based aggregation where buckets are dynamically built - one per unique value. See the Elasticsearch documentation on terms ...
Read more >
Objects (Java SE 17 & JDK 17)
Returns the first argument if it is non- null and otherwise returns the non- null value of supplier.get() . Type Parameters: T -...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found