public static async Task WhenMet(Action condition, IEnumerable <TimeSpan>?checkIntervals, CancellationToken cancellationToken) { foreach (var timeout in checkIntervals ?? DefaultCheckIntervals) { using (var scope = new AssertionScope()) { try { condition(); } catch (Exception error) { error.Should().BeNull("An exception other than assertion was thrown."); } if (!scope.HasFailures()) { return; } if (!cancellationToken.IsCancellationRequested) { scope.Discard(); } } await Task.Delay(timeout, cancellationToken).SuppressCancellation().ConfigureAwait(false); } }
private bool StrictlyMatchAgainst <T>(object[] subjects, T expectation, int expectationIndex) { using var scope = new AssertionScope(); object subject = subjects[expectationIndex]; IEquivalencyValidationContext equivalencyValidationContext = context.AsCollectionItem <T>(expectationIndex); parent.RecursivelyAssertEquality(new Comparands(subject, expectation, typeof(T)), equivalencyValidationContext); bool failed = scope.HasFailures(); return(!failed); }
private bool StrictlyMatchAgainst <T>(object[] subjects, T expectation, int expectationIndex) { using var scope = new AssertionScope(); object subject = subjects[expectationIndex]; string indexString = expectationIndex.ToString(); IEquivalencyValidationContext equivalencyValidationContext = context.CreateForCollectionItem(indexString, subject, expectation); parent.AssertEqualityUsing(equivalencyValidationContext); bool failed = scope.HasFailures(); return(!failed); }
public static async Task WhenMet(Action condition, IEnumerable <TimeSpan>?checkIntervals, CancellationToken cancellationToken) { foreach (var timeout in (checkIntervals ?? DefaultCheckIntervals)) { using (var scope = new AssertionScope()) { condition.Invoke(); if (!scope.HasFailures()) { return; } if (!cancellationToken.IsCancellationRequested) { scope.Discard(); } } await Task.Delay(timeout, cancellationToken).SuppressCancellation(); } }