New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensures expectations involving multiple assertions can be cleared #925
Merged
dennisdoomen
merged 1 commit into
fluentassertions:master
from
dennisdoomen:BetterContinuation
Sep 27, 2018
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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; | ||
dennisdoomen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 As
IAssertionScope
doesn't have all the public members ofAssertionScope
this is a breaking changeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure. The members of
IAssertionScope
are only used in chaining scenarios. I've included a couple of them, but not all. Any strong opinions?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tried to invoke
AssertionScope
-only members myself, I just looked for changes that could break the public API.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally, you're directly using the
AssertionScope
in ausing
block. The interface is only used for those complex chaining purposes. In the last commit, I've added almost all of them to the interface, just to be sure.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But no, I don't have any strong opinions, except trying to avoid breaking changes.
Just as a note: the remaining differences between
AssertionScope
andIAssertionScope
are:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I know. These are very specific things, mostly only used by
BeEquivalentTo
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So? Approved?