forked from fluentassertions/fluentassertions
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 fluentassertions#918
- Loading branch information
1 parent
2dc2217
commit 9356b83
Showing
13 changed files
with
312 additions
and
144 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,92 @@ | ||
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(Func<FailReason> failReasonFunc) | ||
{ | ||
if (predecessorSucceeded) | ||
{ | ||
return predecessor.FailWith(failReasonFunc); | ||
} | ||
|
||
return new Continuation(predecessor, false); | ||
} | ||
|
||
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 bool Succeeded => predecessor.Succeeded; | ||
|
||
public string[] Discard() | ||
{ | ||
return predecessor.Discard(); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
predecessor.Dispose(); | ||
} | ||
} | ||
} |
Oops, something went wrong.