public async Task InvokeAsync_TaskFaultsAndFallbackSucceeds_ReturnsFallbackResult() { var command = new FaultingTaskWithSuccessfulFallbackCommand(); var result = await command.InvokeAsync(); Assert.NotNull(result); }
public async Task InvokeAsync_TaskFaultsAndFallbackSucceeds() { var mockStats = new Mock <IStats>(); var command = new FaultingTaskWithSuccessfulFallbackCommand { Stats = mockStats.Object, }; await command.InvokeAsync(); mockStats.Verify(m => m.Elapsed("mjolnir command test.FaultingTaskWithSuccessfulFallback fallback", "Success", It.IsAny <TimeSpan>()), Times.Once); }
public async Task InvokeAsync_WhenFallbackSemaphoreAvailable_InvokesFallbackAndReleasesSemaphore() { var mockSemaphore = new Mock <IIsolationSemaphore>(); mockSemaphore.Setup(m => m.TryEnter()).Returns(true); var command = new FaultingTaskWithSuccessfulFallbackCommand { FallbackSemaphore = mockSemaphore.Object, }; await command.InvokeAsync(); // Shouldn't throw instigator exception. mockSemaphore.Verify(m => m.Release(), Times.Once); }
public async Task InvokeAsync_WhenFallbackSemaphoreNotAvailable_RethrowsInstigatorImmediatelyWithRejectedFallbackStatus() { var mockSemaphore = new Mock <IIsolationSemaphore>(); mockSemaphore.Setup(m => m.TryEnter()).Returns(false); var command = new FaultingTaskWithSuccessfulFallbackCommand { FallbackSemaphore = mockSemaphore.Object, }; try { await command.InvokeAsync(); } catch (CommandFailedException e) { mockSemaphore.Verify(m => m.TryEnter(), Times.Once); Assert.Equal(FallbackStatus.Rejected, e.FallbackStatus); return; } AssertX.FailExpectedException(); }
public async Task InvokeAsync_TaskFaultsAndFallbackSucceeds() { var mockStats = new Mock<IStats>(); var command = new FaultingTaskWithSuccessfulFallbackCommand { Stats = mockStats.Object, }; await command.InvokeAsync(); mockStats.Verify(m => m.Elapsed("mjolnir command test.FaultingTaskWithSuccessfulFallback fallback", "Success", It.IsAny<TimeSpan>()), Times.Once); }
public async Task InvokeAsync_WhenFallbackSemaphoreNotAvailable_RethrowsInstigatorImmediatelyWithRejectedFallbackStatus() { var mockSemaphore = new Mock<IIsolationSemaphore>(); mockSemaphore.Setup(m => m.TryEnter()).Returns(false); var command = new FaultingTaskWithSuccessfulFallbackCommand { FallbackSemaphore = mockSemaphore.Object, }; try { await command.InvokeAsync(); } catch (CommandFailedException e) { mockSemaphore.Verify(m => m.TryEnter(), Times.Once); Assert.Equal(FallbackStatus.Rejected, e.FallbackStatus); return; } AssertX.FailExpectedException(); }
public async Task InvokeAsync_WhenFallbackSemaphoreAvailable_InvokesFallbackAndReleasesSemaphore() { var mockSemaphore = new Mock<IIsolationSemaphore>(); mockSemaphore.Setup(m => m.TryEnter()).Returns(true); var command = new FaultingTaskWithSuccessfulFallbackCommand { FallbackSemaphore = mockSemaphore.Object, }; await command.InvokeAsync(); // Shouldn't throw instigator exception. mockSemaphore.Verify(m => m.Release(), Times.Once); }