Exemplo n.º 1
0
        public async Task Catch_DelegateIsNotCalledOnSuccess()
        {
            // Arrange
            var called = false;
            var op     = AsyncResult.Delay(1).Catch(e => called = true);

            // Act
            await op;

            // Assert
            Assert.False(called);
        }
Exemplo n.º 2
0
        public async Task Finally_DelegateIsCalledOnSuccess()
        {
            // Arrange
            var called = false;
            var op     = AsyncResult.Delay(1).Finally(() => called = true);

            // Act
            await op;

            // Assert
            Assert.True(called);
        }
Exemplo n.º 3
0
        public async Task Sequence_CompletesWhenAllOperationsComplete()
        {
            // Arrange
            var op1 = AsyncResult.Delay(1);
            var op2 = AsyncResult.Delay(2);

            // Act
            await Promise.Sequence(() => op1, () => op2);

            // Assert
            Assert.True(op1.IsCompleted);
            Assert.True(op2.IsCompleted);
        }
Exemplo n.º 4
0
        public async Task ThenAny_CompletesWhenAllOperationsComplete()
        {
            // Arrange
            var op1 = AsyncResult.Delay(1);
            var op2 = AsyncResult.Delay(2);
            var op3 = new AsyncResult();

            // Act
            await op1.ThenAny(() => new IAsyncOperation[] { op2, op3 });

            // Assert
            Assert.True(op1.IsCompleted);
            Assert.True(op2.IsCompleted);
        }
Exemplo n.º 5
0
        public async Task Catch_CalledIfThenFails()
        {
            // Arrange
            var op          = AsyncResult.Delay(10);
            var thenOp      = op.Then(() => AsyncResult.FaultedOperation);
            var catchCalled = false;
            var catchOp     = thenOp.Catch(e => catchCalled = true);

            // Act
            await catchOp;

            // Assert
            Assert.True(thenOp.IsFaulted);
            Assert.IsType <Exception>(thenOp.Exception);
            Assert.True(catchOp.IsCompletedSuccessfully);
            Assert.True(catchCalled);
        }
Exemplo n.º 6
0
        public async Task Sequence_FailsIfAnyOperationFails()
        {
            // Arrange
            var op1 = AsyncResult.Delay(1);
            var op2 = Promise.Sequence(() => op1, () => throw new NotImplementedException());

            // Act
            try
            {
                await op2;
            }
            catch (NotImplementedException)
            {
            }

            // Assert
            Assert.True(op1.IsCompleted);
            Assert.True(op2.IsFaulted);
        }
Exemplo n.º 7
0
        public async Task Then_NotCalledIfPreviousThenFails()
        {
            // Arrange
            var op          = AsyncResult.Delay(10);
            var thenOp      = op.Then(() => AsyncResult.FaultedOperation);
            var thenCalled  = false;
            var thenOp2     = thenOp.Then(() => thenCalled = true);
            var catchCalled = false;
            var catchOp     = thenOp2.Catch(e => catchCalled = true);

            // Act
            await catchOp;

            // Assert
            Assert.True(thenOp.IsFaulted);
            Assert.True(thenOp2.IsFaulted);
            Assert.True(catchOp.IsCompletedSuccessfully);
            Assert.True(catchCalled);
            Assert.False(thenCalled);
        }