Skip to content
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

Add Imply() to BooleanAssertions #2074

Merged
merged 20 commits into from Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 31 additions & 0 deletions Src/FluentAssertions/Primitives/BooleanAssertions.cs
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
IT-VBFK marked this conversation as resolved.
Show resolved Hide resolved
using FluentAssertions.Execution;

namespace FluentAssertions.Primitives;
Expand Down Expand Up @@ -118,6 +119,36 @@ public AndConstraint<TAssertions> NotBe(bool unexpected, string because = "", pa
return new AndConstraint<TAssertions>((TAssertions)this);
}

/// <summary>
/// Asserts that the value implies the specified <paramref name="implicator"/> value.
/// </summary>
/// <param name="implicator">The second value for the implication</param>
/// <param name="because">
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
/// </param>
/// <param name="becauseArgs">
/// Zero or more objects to format using the placeholders in <paramref name="because"/>.
/// </param>
public AndConstraint<TAssertions> Imply(bool implicator,
[CallerArgumentExpression("implicator")] string implicatorMessage = "",
string because = "",
params object[] becauseArgs)
{
Execute.Assertion
.ForCondition(Subject is not null)
.BecauseOf(because, becauseArgs)
.WithExpectation("Expected {context:boolean} ({0}) to imply {1} ({2}){reason}, ", Subject, implicatorMessage, implicator)
.FailWith("but found null.")
.Then
.ForCondition(!Subject.Value || implicator)
.FailWith("but it did not.")
.Then
.ClearExpectation();

return new AndConstraint<TAssertions>((TAssertions)this);
}

/// <inheritdoc/>
public override bool Equals(object obj) =>
throw new NotSupportedException("Equals is not part of Fluent Assertions. Did you mean Be() instead?");
Expand Down
Expand Up @@ -1816,6 +1816,7 @@ namespace FluentAssertions.Primitives
public FluentAssertions.AndConstraint<TAssertions> BeFalse(string because = "", params object[] becauseArgs) { }
public FluentAssertions.AndConstraint<TAssertions> BeTrue(string because = "", params object[] becauseArgs) { }
public override bool Equals(object obj) { }
public FluentAssertions.AndConstraint<TAssertions> Imply(bool implicator, [System.Runtime.CompilerServices.CallerArgumentExpression("implicator")] string implicatorMessage = "", string because = "", params object[] becauseArgs) { }
public FluentAssertions.AndConstraint<TAssertions> NotBe(bool unexpected, string because = "", params object[] becauseArgs) { }
}
public class DateTimeAssertions : FluentAssertions.Primitives.DateTimeAssertions<FluentAssertions.Primitives.DateTimeAssertions>
Expand Down
Expand Up @@ -1841,6 +1841,7 @@ namespace FluentAssertions.Primitives
public FluentAssertions.AndConstraint<TAssertions> BeFalse(string because = "", params object[] becauseArgs) { }
public FluentAssertions.AndConstraint<TAssertions> BeTrue(string because = "", params object[] becauseArgs) { }
public override bool Equals(object obj) { }
public FluentAssertions.AndConstraint<TAssertions> Imply(bool implicator, [System.Runtime.CompilerServices.CallerArgumentExpression("implicator")] string implicatorMessage = "", string because = "", params object[] becauseArgs) { }
public FluentAssertions.AndConstraint<TAssertions> NotBe(bool unexpected, string because = "", params object[] becauseArgs) { }
}
public class DateOnlyAssertions : FluentAssertions.Primitives.DateOnlyAssertions<FluentAssertions.Primitives.DateOnlyAssertions>
Expand Down
Expand Up @@ -1816,6 +1816,7 @@ namespace FluentAssertions.Primitives
public FluentAssertions.AndConstraint<TAssertions> BeFalse(string because = "", params object[] becauseArgs) { }
public FluentAssertions.AndConstraint<TAssertions> BeTrue(string because = "", params object[] becauseArgs) { }
public override bool Equals(object obj) { }
public FluentAssertions.AndConstraint<TAssertions> Imply(bool implicator, [System.Runtime.CompilerServices.CallerArgumentExpression("implicator")] string implicatorMessage = "", string because = "", params object[] becauseArgs) { }
public FluentAssertions.AndConstraint<TAssertions> NotBe(bool unexpected, string because = "", params object[] becauseArgs) { }
}
public class DateTimeAssertions : FluentAssertions.Primitives.DateTimeAssertions<FluentAssertions.Primitives.DateTimeAssertions>
Expand Down
Expand Up @@ -1816,6 +1816,7 @@ namespace FluentAssertions.Primitives
public FluentAssertions.AndConstraint<TAssertions> BeFalse(string because = "", params object[] becauseArgs) { }
public FluentAssertions.AndConstraint<TAssertions> BeTrue(string because = "", params object[] becauseArgs) { }
public override bool Equals(object obj) { }
public FluentAssertions.AndConstraint<TAssertions> Imply(bool implicator, [System.Runtime.CompilerServices.CallerArgumentExpression("implicator")] string implicatorMessage = "", string because = "", params object[] becauseArgs) { }
public FluentAssertions.AndConstraint<TAssertions> NotBe(bool unexpected, string because = "", params object[] becauseArgs) { }
}
public class DateTimeAssertions : FluentAssertions.Primitives.DateTimeAssertions<FluentAssertions.Primitives.DateTimeAssertions>
Expand Down
Expand Up @@ -1767,6 +1767,7 @@ namespace FluentAssertions.Primitives
public FluentAssertions.AndConstraint<TAssertions> BeFalse(string because = "", params object[] becauseArgs) { }
public FluentAssertions.AndConstraint<TAssertions> BeTrue(string because = "", params object[] becauseArgs) { }
public override bool Equals(object obj) { }
public FluentAssertions.AndConstraint<TAssertions> Imply(bool implicator, [System.Runtime.CompilerServices.CallerArgumentExpression("implicator")] string implicatorMessage = "", string because = "", params object[] becauseArgs) { }
public FluentAssertions.AndConstraint<TAssertions> NotBe(bool unexpected, string because = "", params object[] becauseArgs) { }
}
public class DateTimeAssertions : FluentAssertions.Primitives.DateTimeAssertions<FluentAssertions.Primitives.DateTimeAssertions>
Expand Down
Expand Up @@ -1816,6 +1816,7 @@ namespace FluentAssertions.Primitives
public FluentAssertions.AndConstraint<TAssertions> BeFalse(string because = "", params object[] becauseArgs) { }
public FluentAssertions.AndConstraint<TAssertions> BeTrue(string because = "", params object[] becauseArgs) { }
public override bool Equals(object obj) { }
public FluentAssertions.AndConstraint<TAssertions> Imply(bool implicator, [System.Runtime.CompilerServices.CallerArgumentExpression("implicator")] string implicatorMessage = "", string because = "", params object[] becauseArgs) { }
public FluentAssertions.AndConstraint<TAssertions> NotBe(bool unexpected, string because = "", params object[] becauseArgs) { }
}
public class DateTimeAssertions : FluentAssertions.Primitives.DateTimeAssertions<FluentAssertions.Primitives.DateTimeAssertions>
Expand Down