Skip to content

Commit

Permalink
Name the operands for the implication correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
IT-VBFK committed Dec 29, 2022
1 parent 16f335f commit 4c2accf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
16 changes: 9 additions & 7 deletions Src/FluentAssertions/Primitives/BooleanAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,28 +120,30 @@ public AndConstraint<TAssertions> NotBe(bool unexpected, string because = "", pa
}

/// <summary>
/// Asserts that the value implies the specified <paramref name="implicator"/> value.
/// Asserts that the value implies the specified <paramref name="consequent"/> value.
/// </summary>
/// <param name="implicator">The second value for the implication</param>
/// <param name="consequent">The right hand side 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 = "",
public AndConstraint<TAssertions> Imply(bool consequent,
[CallerArgumentExpression("consequent")] string consequentMessage = "",
string because = "",
params object[] becauseArgs)
{
bool? antecedent = Subject;

Execute.Assertion
.ForCondition(Subject is not null)
.ForCondition(antecedent is not null)
.BecauseOf(because, becauseArgs)
.WithExpectation("Expected {context:boolean} ({0}) to imply {1} ({2}){reason}, ", Subject, implicatorMessage, implicator)
.WithExpectation("Expected {context:antecedent} ({0}) to imply {1} ({2}){reason}, ", antecedent, consequentMessage, consequent)
.FailWith("but found null.")
.Then
.ForCondition(!Subject.Value || implicator)
.ForCondition(!antecedent.Value || consequent)
.FailWith("but it did not.")
.Then
.ClearExpectation();
Expand Down
14 changes: 7 additions & 7 deletions Tests/FluentAssertions.Specs/Primitives/BooleanAssertionSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,23 +183,23 @@ public class Imply
};

[Theory]
[MemberData(nameof(PassingImplications), MemberType = typeof(BooleanAssertionSpecs.Imply))]
public void Subject_implies_implicator(bool? subject, bool implicator)
[MemberData(nameof(PassingImplications))]
public void Subject_implies_implicator(bool? antecedent, bool consequent)
{
// Act / Assert
subject.Should().Imply(implicator);
antecedent.Should().Imply(consequent);
}

[Theory]
[MemberData(nameof(NonPassingImplications), MemberType = typeof(BooleanAssertionSpecs.Imply))]
public void Subject_does_not_imply_implicator(bool? subject, bool implicator)
[MemberData(nameof(NonPassingImplications))]
public void Subject_does_not_imply_implicator(bool? antecedent, bool consequent)
{
// Act
Action act = () => subject.Should().Imply(implicator, nameof(implicator), "because we want to test the {0}", "failure");
Action act = () => antecedent.Should().Imply(consequent, nameof(consequent), "because we want to test the {0}", "failure");

// Assert
act.Should().Throw<XunitException>()
.WithMessage("Expected*to imply *implicator*test the failure*but*");
.WithMessage("Expected*to imply *consequent*test the failure*but*");
}
}
}

0 comments on commit 4c2accf

Please sign in to comment.