-
Notifications
You must be signed in to change notification settings - Fork 731
Closed
Description
Description
The documentation of GivenSelector<T>.ForCondition says
The condition will not be evaluated if the prior assertion failed [...]
When wrapped in an AssertionScope that is no longer the case.
From AssertionScope
Starts an unnamed scope within which multiple assertions can be executed
and which will not throw until the scope is disposed.
Maybe it's just an unfortunate reality, but it prevents writing guards to prevent e.g. NullReferenceExceptions in a fluent way.
Looks related to #1325
Complete minimal example reproducing the issue
using var _ = new AssertionScope();
string subject = null;
Execute.Assertion
.Given(() => subject)
.ForCondition(s => s is not null)
.FailWith("but is was null")
.Then
.ForCondition(s => s.GetHashCode() == 42) // this predicate is invoked
.FailWith("it should be 42");Expected behavior:
The second predicate should not be invoked
Actual behavior:
The predicate was invoked.
Versions
- Fluent Assertions
develop@ e9c847c