forked from fluentassertions/fluentassertions
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc49f11
commit f6a01cd
Showing
6 changed files
with
97 additions
and
24 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,56 @@ | ||
using System; | ||
using System.Globalization; | ||
|
||
namespace FluentAssertions.Execution; | ||
|
||
public class Assertion | ||
{ | ||
private readonly IAssertionScope currentScope; | ||
private Func<string> reason; | ||
private bool? succeeded; | ||
|
||
public Assertion(IAssertionScope currentScope) | ||
{ | ||
this.currentScope = currentScope; | ||
} | ||
|
||
/// <summary> | ||
/// Adds an explanation of why the assertion is supposed to succeed to the scope. | ||
/// </summary> | ||
public Assertion BecauseOf(Reason reason) | ||
{ | ||
return BecauseOf(reason.FormattedMessage, reason.Arguments); | ||
} | ||
|
||
/// <inheritdoc cref="IAssertionScope.BecauseOf(string, object[])"/> | ||
public Assertion BecauseOf(string because, params object[] becauseArgs) | ||
{ | ||
reason = () => | ||
{ | ||
try | ||
{ | ||
string becauseOrEmpty = because ?? string.Empty; | ||
return becauseArgs?.Length > 0 | ||
? string.Format(CultureInfo.InvariantCulture, becauseOrEmpty, becauseArgs) | ||
: becauseOrEmpty; | ||
} | ||
catch (FormatException formatException) | ||
{ | ||
return | ||
$"**WARNING** because message '{because}' could not be formatted with string.Format{Environment.NewLine}{formatException.StackTrace}"; | ||
} | ||
}; | ||
|
||
return this; | ||
} | ||
|
||
/// <inheritdoc cref="IAssertionScope.ForCondition(bool)"/> | ||
public AssertionScope ForCondition(bool condition) | ||
{ | ||
succeeded = condition; | ||
|
||
return this; | ||
} | ||
|
||
} |
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