Esempio n. 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();
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 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();
        }
Esempio n. 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();
        }
Esempio n. 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();   
        }
Esempio n. 9
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();
        }
Esempio n. 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);
        }
Esempio n. 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());
        }