diff --git a/Source/aweXpect/That/ThatGeneric.CompliesWith.cs b/Source/aweXpect/That/ThatGeneric.CompliesWith.cs index c25bfd12f..0f8179a5d 100644 --- a/Source/aweXpect/That/ThatGeneric.CompliesWith.cs +++ b/Source/aweXpect/That/ThatGeneric.CompliesWith.cs @@ -49,6 +49,7 @@ private sealed class CompliesWithConstraint private readonly ManualExpectationBuilder _itemExpectationBuilder; private readonly RepeatedCheckOptions _options; private bool _isNegated; + private bool _isOnceNegated; public CompliesWithConstraint(ExpectationBuilder expectationBuilder, ExpectationGrammars grammars, Action> expectations, RepeatedCheckOptions options) @@ -67,7 +68,7 @@ public async Task IsMetBy( ConstraintResult isMatch = await _itemExpectationBuilder.IsMetBy(actual, context, cancellationToken); if (isMatch.Outcome == Outcome.Success != _isNegated) { - return NegateIfNegated(isMatch).AppendExpectationText(sb => sb.Append(_options)); + return NegateOnceIfNegated(isMatch).AppendExpectationText(sb => sb.Append(_options)); } if (_options.Timeout > TimeSpan.Zero) @@ -88,23 +89,22 @@ public async Task IsMetBy( isMatch = await _itemExpectationBuilder.IsMetBy(actual, context, cancellationToken); if (isMatch.Outcome == Outcome.Success != _isNegated) { - return NegateIfNegated(isMatch).AppendExpectationText(sb => sb.Append(_options)); + return NegateOnceIfNegated(isMatch).AppendExpectationText(sb => sb.Append(_options)); } } while (sw.Elapsed <= _options.Timeout && !cancellationToken.IsCancellationRequested); } - return NegateIfNegated(isMatch).AppendExpectationText(sb => sb.Append(_options)); + return NegateOnceIfNegated(isMatch).AppendExpectationText(sb => sb.Append(_options)); } public override void AppendExpectation(StringBuilder stringBuilder, string? indentation = null) - { - _itemExpectationBuilder.AppendExpectation(stringBuilder, indentation); - } + => _itemExpectationBuilder.AppendExpectation(stringBuilder, indentation); - private ConstraintResult NegateIfNegated(ConstraintResult constraintResult) + private ConstraintResult NegateOnceIfNegated(ConstraintResult constraintResult) { - if (_isNegated) + if (_isNegated && !_isOnceNegated) { + _isOnceNegated = true; return constraintResult.Negate(); } diff --git a/Tests/aweXpect.Tests/Collections/ThatEnumerable.All.ComplyWith.ImmutableTests.cs b/Tests/aweXpect.Tests/Collections/ThatEnumerable.All.ComplyWith.ImmutableTests.cs index d19f3339e..5cc1e1b62 100644 --- a/Tests/aweXpect.Tests/Collections/ThatEnumerable.All.ComplyWith.ImmutableTests.cs +++ b/Tests/aweXpect.Tests/Collections/ThatEnumerable.All.ComplyWith.ImmutableTests.cs @@ -54,7 +54,7 @@ async Task Act() public sealed class ImmutableNegatedTests { - [Fact(Skip = "TODO: #632")] + [Fact] public async Task WhenEnumerableOnlyContainsEqualValues_ShouldFail() { ImmutableArray subject = [1, 1, 1, 1, 1, 1, 1,]; @@ -66,7 +66,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject is not equal to 1 for all items, - but not all were + but none of 7 were """); } }