Example #1
0
        public async Task InvokeAsync_ExecuteFaultsAndFallbackNotImplemented()
        {
            var exception = new ExpectedTestException("foo");
            var mockStats = new Mock <IStats>();
            var command   = new FaultingExecuteEchoCommandWithoutFallback(exception)
            {
                Stats = mockStats.Object,
            };

            try
            {
                await command.InvokeAsync();
            }
            catch (CommandFailedException e)
            {
                if (e.GetBaseException() != exception)
                {
                    throw;
                }
                mockStats.Verify(m => m.Elapsed("mjolnir command test.FaultingExecuteEchoCommandWithoutFallback fallback", "NotImplemented", It.IsAny <TimeSpan>()), Times.Once);
                return; // Expected.
            }

            AssertX.FailExpectedException();
        }
Example #2
0
        public void Invoke_FaultingExecute_PropagatesException()
        {
            var expected = new ExpectedTestException("Exception");
            var command  = new FaultingExecuteEchoCommandWithoutFallback(expected);

            var result = Assert.Throws <CommandFailedException>(() =>
            {
                command.Invoke();
            });

            Assert.Equal(expected, result.InnerException);
        }
Example #3
0
        public void InvokeAsync_WhenExceptionThrownFromExecute_HasExpectedExceptionInsideAggregateException()
        {
            var expected = new ExpectedTestException("Exception");
            var command  = new FaultingExecuteEchoCommandWithoutFallback(expected);

            var result = Assert.Throws <AggregateException>(() => {
                var foo = command.InvokeAsync().Result;
            });

            // AggregateException -> CommandFailedException -> ExpectedTestException
            Assert.Equal(expected, result.InnerException.InnerException);
        }
        public async Task InvokeAsync_WhenExecuteThrowsException_RethrowsException()
        {
            var exception = new ExpectedTestException("Expected");

            var mockBreaker = CreateMockBreaker(true);
            var command = new FaultingExecuteEchoCommandWithoutFallback(exception)
            {
                CircuitBreaker = mockBreaker.Object,
            };

            var e = await Assert.ThrowsAsync<CommandFailedException>(() => command.InvokeAsync());
            Assert.True(e.InnerException == exception);
        }
Example #5
0
        public async Task InvokeAsync_CommandExceptionFromExecute_RetainsOriginalExceptionCause()
        {
            var cause   = new ExpectedTestException("Root cause exception");
            var command = new FaultingExecuteEchoCommandWithoutFallback(cause);

            try
            {
                await command.InvokeAsync();
            }
            catch (CommandFailedException e)
            {
                Assert.Equal(cause, e.GetBaseException());
                return;
            }

            AssertX.FailExpectedException();
        }
Example #6
0
        public async Task InvokeAsync_WhenExecuteThrowsException_RethrowsException()
        {
            var exception = new ExpectedTestException("Expected");

            var mockBreaker = CreateMockBreaker(true);
            var command     = new FaultingExecuteEchoCommandWithoutFallback(exception)
            {
                CircuitBreaker = mockBreaker.Object,
            };

            try
            {
                await command.InvokeAsync();
            }
            catch (CommandFailedException e)
            {
                Assert.True(e.InnerException == exception);
                return; // Expected.
            }

            AssertX.FailExpectedException();
        }
        public async Task InvokeAsync_WhenExecuteThrowsException_RethrowsException()
        {
            var exception = new ExpectedTestException("Expected");

            var mockBreaker = CreateMockBreaker(true);
            var command = new FaultingExecuteEchoCommandWithoutFallback(exception)
            {
                CircuitBreaker = mockBreaker.Object,
            };

            try
            {
                await command.InvokeAsync();
            }
            catch (CommandFailedException e)
            {
                Assert.True(e.InnerException == exception);
                return; // Expected.
            }
            
            AssertX.FailExpectedException();
        }
Example #8
0
        public async Task InvokeAsync_ExecuteFaultsAndFallbackNotImplemented()
        {
            var exception = new ExpectedTestException("foo");
            var mockStats = new Mock<IStats>();
            var command = new FaultingExecuteEchoCommandWithoutFallback(exception)
            {
                Stats = mockStats.Object,
            };

            try
            {
                await command.InvokeAsync();
            }
            catch (CommandFailedException e)
            {
                if (e.GetBaseException() != exception) throw;
                mockStats.Verify(m => m.Elapsed("mjolnir command test.FaultingExecuteEchoCommandWithoutFallback fallback", "NotImplemented", It.IsAny<TimeSpan>()), Times.Once);
                return; // Expected.
            }

            AssertX.FailExpectedException();   
        }
        public async Task InvokeAsync_CommandExceptionFromExecute_RetainsOriginalExceptionCause()
        {
            var cause = new ExpectedTestException("Root cause exception");
            var command = new FaultingExecuteEchoCommandWithoutFallback(cause);

            try
            {
                await command.InvokeAsync();
            }
            catch (CommandFailedException e)
            {
                Assert.Equal(cause, e.GetBaseException());
                return;
            }

            AssertX.FailExpectedException();
        }
Example #10
0
        public async Task InvokeAsync_ExecuteFaultsAndFallbackNotImplemented()
        {
            var exception = new ExpectedTestException("foo");
            var mockStats = new Mock<IStats>();
            var command = new FaultingExecuteEchoCommandWithoutFallback(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.FaultingExecuteEchoCommandWithoutFallback fallback", "NotImplemented", It.IsAny<TimeSpan>()), Times.Once);
        }
Example #11
0
        public async Task InvokeAsync_CommandExceptionFromExecute_RetainsOriginalExceptionCause()
        {
            var cause = new ExpectedTestException("Root cause exception");
            var command = new FaultingExecuteEchoCommandWithoutFallback(cause);

            var e = await Assert.ThrowsAsync<CommandFailedException>(() => command.InvokeAsync());
            Assert.Equal(cause, e.GetBaseException());
        }