Miko
Miko

Reputation: 129

FluentAssertion - Adding assertion to if statement

I have the following Fluent Assertion which i would like to put in an if statement. I get an error saying I cannot implicitly convert type to bool.

I have tried to explicitly cast it but i still get an error saying cannot convert type to bool.

actors.Cast.Should().Contain(actor => actor.Name == "Emilia Clark");

What would be the best way to check if the statement above is true?

Upvotes: 0

Views: 1026

Answers (2)

Nkosi
Nkosi

Reputation: 247511

What would be the best way to check if the statement above is true?

By doing nothing.

If it is not true the test will fail as it will throw an exception.

//... Code before

//Assert
actors.Cast.Should().Contain(actor => actor.Name == "Emilia Clark");

//...if we reach this far it is true. Carry on.

//...other code

Upvotes: 6

Chris
Chris

Reputation: 597

I assume "Cast" is an IEnumerable<Actor>. You can use Linq ".Any(...)".

if (Cast.Any(actor => actor.Name == "Emilia Clark")) {...}

Upvotes: 1

Related Questions