Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Source/aweXpect/That/ThatGeneric.CompliesWith.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ private sealed class CompliesWithConstraint<T>
private readonly ManualExpectationBuilder<T> _itemExpectationBuilder;
private readonly RepeatedCheckOptions _options;
private bool _isNegated;
private bool _isOnceNegated;

public CompliesWithConstraint(ExpectationBuilder expectationBuilder, ExpectationGrammars grammars,
Action<IThat<T>> expectations, RepeatedCheckOptions options)
Expand All @@ -67,7 +68,7 @@ public async Task<ConstraintResult> 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)
Expand All @@ -88,23 +89,22 @@ public async Task<ConstraintResult> 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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async Task Act()

public sealed class ImmutableNegatedTests
{
[Fact(Skip = "TODO: #632")]
[Fact]
public async Task WhenEnumerableOnlyContainsEqualValues_ShouldFail()
{
ImmutableArray<int> subject = [1, 1, 1, 1, 1, 1, 1,];
Expand All @@ -66,7 +66,7 @@ await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
is not equal to 1 for all items,
but not all were
but none of 7 were
""");
}
}
Expand Down