-
-
Notifications
You must be signed in to change notification settings - Fork 544
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensures expectations involving multiple assertions can be cleared
Fixes #918
- Loading branch information
1 parent
68ca857
commit 37cc1bb
Showing
13 changed files
with
273 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System; | ||
|
||
namespace FluentAssertions.Execution | ||
{ | ||
/// <summary> | ||
/// Allows chaining multiple assertion scopes together using <see cref="Continuation.Then"/>. | ||
/// </summary> | ||
/// <remarks> | ||
/// If the parent scope has captured a failed assertion, this class ensures that successive assertions | ||
/// are no longer evaluated. | ||
/// </remarks> | ||
public class ContinuedAssertionScope : IAssertionScope | ||
{ | ||
private readonly AssertionScope predecessor; | ||
private readonly bool predecessorSucceeded; | ||
|
||
public ContinuedAssertionScope(AssertionScope predecessor, bool predecessorSucceeded) | ||
{ | ||
this.predecessorSucceeded = predecessorSucceeded; | ||
this.predecessor = predecessor; | ||
} | ||
|
||
public GivenSelector<T> Given<T>(Func<T> selector) | ||
{ | ||
return predecessor.Given<T>(selector); | ||
} | ||
|
||
public IAssertionScope ForCondition(bool condition) | ||
{ | ||
if (predecessorSucceeded) | ||
{ | ||
return predecessor.ForCondition(condition); | ||
} | ||
|
||
return this; | ||
} | ||
|
||
public Continuation FailWith(string message, params object[] args) | ||
{ | ||
if (predecessorSucceeded) | ||
{ | ||
return predecessor.FailWith(message, args); | ||
} | ||
|
||
return new Continuation(predecessor, false); | ||
} | ||
|
||
public IAssertionScope BecauseOf(string because, params object[] becauseArgs) | ||
{ | ||
return predecessor.BecauseOf(because, becauseArgs); | ||
} | ||
|
||
public Continuation ClearExpectation() | ||
{ | ||
return predecessor.ClearExpectation(); | ||
} | ||
|
||
public IAssertionScope WithExpectation(string message, params object[] args) | ||
{ | ||
return predecessor.WithExpectation(message, args); | ||
} | ||
|
||
public IAssertionScope WithDefaultIdentifier(string identifier) | ||
{ | ||
return predecessor.WithDefaultIdentifier(identifier); | ||
} | ||
|
||
public IAssertionScope UsingLineBreaks => predecessor.UsingLineBreaks; | ||
|
||
public void Dispose() | ||
{ | ||
predecessor?.Dispose(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.