Skip to content

Commit

Permalink
Remove CallerArgumentExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
IT-VBFK committed Jan 1, 2023
1 parent 3b134c9 commit 5c1a4f6
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 20 deletions.
4 changes: 1 addition & 3 deletions Src/FluentAssertions/Primitives/BooleanAssertions.cs
Expand Up @@ -123,7 +123,6 @@ public AndConstraint<TAssertions> NotBe(bool unexpected, string because = "", pa
/// Asserts that the value implies the specified <paramref name="consequent"/> value.
/// </summary>
/// <param name="consequent">The right hand side for the implication</param>
/// <remarks>If you want to use the `because` / `becauseArgs` construct, it is **necessary** to use the caller argument expression, because this would lead to unexpected failure messages, when omitted!</remarks>
/// <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.
Expand All @@ -132,7 +131,6 @@ public AndConstraint<TAssertions> NotBe(bool unexpected, string because = "", pa
/// Zero or more objects to format using the placeholders in <paramref name="because"/>.
/// </param>
public AndConstraint<TAssertions> Imply(bool consequent,
[CallerArgumentExpression(nameof(consequent))] string consequentMessage = "",
string because = "",
params object[] becauseArgs)
{
Expand All @@ -141,7 +139,7 @@ public AndConstraint<TAssertions> NotBe(bool unexpected, string because = "", pa
Execute.Assertion
.ForCondition(antecedent is not null)
.BecauseOf(because, becauseArgs)
.WithExpectation($"Expected {{context:antecedent}} ({{0}}) to imply {consequentMessage} ({{1}}){{reason}}, ", antecedent, consequent)
.WithExpectation($"Expected {{context:antecedent}} ({{0}}) to imply consequent ({{1}}){{reason}}, ", antecedent, consequent)
.FailWith("but found null.")
.Then
.ForCondition(!antecedent.Value || consequent)
Expand Down
Expand Up @@ -1816,7 +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 consequent, [System.Runtime.CompilerServices.CallerArgumentExpression("consequent")] string consequentMessage = "", string because = "", params object[] becauseArgs) { }
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 @@ -1841,7 +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 consequent, [System.Runtime.CompilerServices.CallerArgumentExpression("consequent")] string consequentMessage = "", string because = "", params object[] becauseArgs) { }
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 @@ -1816,7 +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 consequent, [System.Runtime.CompilerServices.CallerArgumentExpression("consequent")] string consequentMessage = "", string because = "", params object[] becauseArgs) { }
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 @@ -1816,7 +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 consequent, [System.Runtime.CompilerServices.CallerArgumentExpression("consequent")] string consequentMessage = "", string because = "", params object[] becauseArgs) { }
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 @@ -1767,7 +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 consequent, [System.Runtime.CompilerServices.CallerArgumentExpression("consequent")] string consequentMessage = "", string because = "", params object[] becauseArgs) { }
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 @@ -1816,7 +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 consequent, [System.Runtime.CompilerServices.CallerArgumentExpression("consequent")] string consequentMessage = "", string because = "", params object[] becauseArgs) { }
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 @@ -195,11 +195,11 @@ public void Subject_implies_implicator(bool? antecedent, bool consequent)
public void Subject_does_not_imply_implicator(bool? antecedent, bool consequent)
{
// Act
Action act = () => antecedent.Should().Imply(consequent, nameof(consequent), "because we want to test the {0}", "failure");
Action act = () => antecedent.Should().Imply(consequent, "because we want to test the {0}", "failure");

// Assert
act.Should().Throw<XunitException>()
.WithMessage("Expected*to imply consequent*test the failure*but*");
.WithMessage("Expected antecedent*to imply consequent*test the failure*but*");
}
}
}
10 changes: 1 addition & 9 deletions docs/_pages/booleans.md
Expand Up @@ -28,12 +28,4 @@ Implication: see [here](https://mathworld.wolfram.com/Implies.html)
```csharp
bool anotherBoolean = true;
theBoolean.Should().Imply(anotherBoolean);
```

Passing a custom caller argument expression is beneficial for this assertion to get the second parameter name in the failure message
```csharp
bool anotherBoolean = true;
theBoolean.Should().Imply(anotherBoolean, nameof(anotherBoolean));
```

If you want to use the `because` / `becauseArgs` construct, it is **necessary** to use the caller argument expression, because this would lead to unexpected failure messages, when omitted!
```

0 comments on commit 5c1a4f6

Please sign in to comment.