Beispiel #1
0
 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);
     }
 }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
 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();
     }
 }