Skip to content

Commit

Permalink
Add Imply() to BooleanAssertions (#2074)
Browse files Browse the repository at this point in the history
  • Loading branch information
IT-VBFK committed Jan 3, 2023
1 parent c6d8bfa commit 482d5a0
Show file tree
Hide file tree
Showing 10 changed files with 216 additions and 133 deletions.
31 changes: 31 additions & 0 deletions Src/FluentAssertions/Primitives/BooleanAssertions.cs
Expand Up @@ -118,6 +118,37 @@ 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="consequent"/> value.
/// </summary>
/// <param name="consequent">The right hand side of 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 consequent,
string because = "",
params object[] becauseArgs)
{
bool? antecedent = Subject;

Execute.Assertion
.ForCondition(antecedent is not null)
.BecauseOf(because, becauseArgs)
.WithExpectation("Expected {context:antecedent} ({0}) to imply consequent ({1}){reason}, ", antecedent, consequent)
.FailWith("but found null.")
.Then
.ForCondition(!antecedent.Value || consequent)
.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 @@ -1822,6 +1822,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 consequent, 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 @@ -1847,6 +1847,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 consequent, 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 @@ -1822,6 +1822,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 consequent, 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 @@ -1822,6 +1822,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 consequent, 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 @@ -1773,6 +1773,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 consequent, 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 @@ -1822,6 +1822,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 consequent, 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

0 comments on commit 482d5a0

Please sign in to comment.