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.

Should().NotBeNullOrWhiteSpace() ?

See original GitHub issue

Hi!

The Strings page at https://fluentassertions.com/strings says there’s a method : theString.Should().NotBeNullOrWhiteSpace();

…but I am getting : ‘ObjectAssertions’ does not contain a definition for ‘NotBeNullOrWhiteSpace’ …

Oh wait, I am doing this: Result.Should().NotBeNull().And.Should().NotBeNullOrWhiteSpace();

That doesn’t work, but this does:

Result.Should().NotBeNullOrWhiteSpace();

Why is there a difference there?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
jnyrupcommented, May 8, 2021

The misleading/confusing error message with ObjectAssertions is because And return an AndConstraint and then Should resolved to Should(this object) that returns an ObjectAssertions which, as the messages points out, does not contain any NotBeNullOrWhiteSpace method.

0reactions
GiganteXcommented, May 8, 2021

Agreed. But giving that error about ObjectAssertions, I get the feeling he/she wasn’t copying the right example.

But let’s wait until @GiganteX answers him/herself.

It’s a string yes, like this:

image

But when I remove the extra Should() it works nicely!

Read more comments on GitHub >

github_iconTop Results From Across the Web

C# item isn't in List, and not null or whitespace
Hint: look at your while condition - it says "While "the folder name isn't empty, or the folder name is empty". How could...
Read more >
string.Should().NotBeNullOrWhitespace() · Issue #7
A NullOrEmpty already exists, but not one for whitespace. ... This behavior would seem to be provided by the existing NotBeBlank() method.
Read more >
String.IsNullOrWhiteSpace(String) Method (System)
Indicates whether a specified string is null, empty, or consists only of white-space characters.
Read more >
Why is there no string type that enforces non-null ...
My code is littered with checks for empty strings, null strings and whitespace-only strings. I would guess that in most cases, a developer ......
Read more >
How to check if a string has only whitespace or is empty in C#
In C#, the IsNullOrEmpty() method can be used to check if a string is empty or null . But if we want to...
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