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); }
public async Task Finally_DelegateIsCalledOnSuccess() { // Arrange var called = false; var op = AsyncResult.Delay(1).Finally(() => called = true); // Act await op; // Assert Assert.True(called); }
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); }
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); }
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); }
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); }
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); }