Beispiel #1
0
        public async Task Retry_CompletesAfterMaxRetriesExceeded()
        {
            // Arrange
            var counter = 3;
            var e       = new Exception();

            IAsyncOperation OpFactory()
            {
                --counter;
                return(AsyncResult.FromException(e));
            }

            // Act
            var op = AsyncResult.Retry(OpFactory, 1, 1);

            try
            {
                await op;
            }
            catch
            {
            }

            // Assert
            AssertFaulted(op, e);
            Assert.Equal(2, counter);
        }
Beispiel #2
0
        public async Task Retry_CompletesWhenSourceCompletes()
        {
            // Arrange
            var counter = 3;

            IAsyncOperation OpFactory()
            {
                if (--counter > 0)
                {
                    return(AsyncResult.FromException(new Exception()));
                }
                else
                {
                    return(AsyncResult.Delay(1));
                }
            }

            // Act
            var   op = AsyncResult.Retry(OpFactory, 1);
            await op;

            // Assert
            AssertCompleted(op);
        }