public async Task InvokeAsync_TaskFaultsAndFallbackNotImplemented() { var exception = new ExpectedTestException("foo"); var mockStats = new Mock <IStats>(); var command = new FaultingTaskEchoCommandWithoutFallback(exception) { Stats = mockStats.Object, }; try { await command.InvokeAsync(); } catch (CommandFailedException e) { if (e.GetBaseException() != exception) { throw; } mockStats.Verify(m => m.Elapsed("mjolnir command test.FaultingTaskEchoCommandWithoutFallback fallback", "NotImplemented", It.IsAny <TimeSpan>()), Times.Once); return; // Expected. } AssertX.FailExpectedException(); }
public void Invoke_FaultingTask_PropagatesException() { var expected = new ExpectedTestException("Exception"); var command = new FaultingTaskEchoCommandWithoutFallback(expected); var result = Assert.Throws <CommandFailedException>(() => { command.Invoke(); }); Assert.Equal(expected, result.InnerException); }
public void InvokeAsync_WhenExceptionThrownFromTask_HasExpectedExceptionInsideAggregateException() { var expected = new ExpectedTestException("Exception"); var command = new FaultingTaskEchoCommandWithoutFallback(expected); var result = Assert.Throws <AggregateException>(() => { var foo = command.InvokeAsync().Result; }); // AggregateException -> CommandFailedException -> ExpectedTestException Assert.Equal(expected, result.InnerException.InnerException); }
public async Task InvokeAsync_WhenReturnedTaskThrowsException_RethrowsException() { var exception = new ExpectedTestException("Expected"); var mockBreaker = CreateMockBreaker(true); var command = new FaultingTaskEchoCommandWithoutFallback(exception) { CircuitBreaker = mockBreaker.Object, }; var e = await Assert.ThrowsAsync<CommandFailedException>(() => command.InvokeAsync()); Assert.True(e.InnerException == exception); }
public async Task InvokeAsync_CommandExceptionFromTask_RetainsOriginalExceptionCause() { var cause = new ExpectedTestException("Root cause exception"); var command = new FaultingTaskEchoCommandWithoutFallback(cause); try { await command.InvokeAsync(); } catch (CommandFailedException e) { Assert.Equal(cause, e.GetBaseException()); return; } AssertX.FailExpectedException(); }
public async Task InvokeAsync_WhenReturnedTaskThrowsException_RethrowsException() { var exception = new ExpectedTestException("Expected"); var mockBreaker = CreateMockBreaker(true); var command = new FaultingTaskEchoCommandWithoutFallback(exception) { CircuitBreaker = mockBreaker.Object, }; try { await command.InvokeAsync(); } catch (CommandFailedException e) { Assert.True(e.InnerException == exception); return; // Expected. } AssertX.FailExpectedException(); }
public async Task InvokeAsync_TaskFaultsAndFallbackNotImplemented() { var exception = new ExpectedTestException("foo"); var mockStats = new Mock<IStats>(); var command = new FaultingTaskEchoCommandWithoutFallback(exception) { Stats = mockStats.Object, }; try { await command.InvokeAsync(); } catch (CommandFailedException e) { if (e.GetBaseException() != exception) throw; mockStats.Verify(m => m.Elapsed("mjolnir command test.FaultingTaskEchoCommandWithoutFallback fallback", "NotImplemented", It.IsAny<TimeSpan>()), Times.Once); return; // Expected. } AssertX.FailExpectedException(); }
public async Task InvokeAsync_TaskFaultsAndFallbackNotImplemented() { var exception = new ExpectedTestException("foo"); var mockStats = new Mock<IStats>(); var command = new FaultingTaskEchoCommandWithoutFallback(exception) { Stats = mockStats.Object, }; var e = await Assert.ThrowsAsync<CommandFailedException>(command.InvokeAsync); Assert.Equal(exception, e.GetBaseException()); mockStats.Verify(m => m.Elapsed("mjolnir command test.FaultingTaskEchoCommandWithoutFallback fallback", "NotImplemented", It.IsAny<TimeSpan>()), Times.Once); }
public async Task InvokeAsync_CommandExceptionFromTask_RetainsOriginalExceptionCause() { var cause = new ExpectedTestException("Root cause exception"); var command = new FaultingTaskEchoCommandWithoutFallback(cause); var e = await Assert.ThrowsAsync<CommandFailedException>(() => command.InvokeAsync()); Assert.Equal(cause, e.GetBaseException()); }