Example #1
0
        public async Task InvokeAsync_WhenFallbackFails_ReleasesSemaphore()
        {
            var mockSemaphore = new Mock <IIsolationSemaphore>();

            mockSemaphore.Setup(m => m.TryEnter()).Returns(true);

            var exception = new ExpectedTestException("Expected");
            var command   = new FaultingTaskWithEchoThrowingFallbackCommand(exception)
            {
                FallbackSemaphore = mockSemaphore.Object,
            };

            try
            {
                await command.InvokeAsync();
            }
            catch (ExpectedTestException e)
            {
                Assert.Equal(exception, e);
                mockSemaphore.Verify(m => m.Release(), Times.Once);
                return; // Expected.
            }

            AssertX.FailExpectedException();
        }
Example #2
0
        public async Task InvokeAsync_TaskFaultsAndFallbackThrowsNonInstigator()
        {
            var expected  = new ExpectedTestException("foo");
            var mockStats = new Mock <IStats>();
            var command   = new FaultingTaskWithEchoThrowingFallbackCommand(expected)
            {
                Stats = mockStats.Object,
            };

            try
            {
                await command.InvokeAsync();
            }
            catch (ExpectedTestException e)
            {
                if (e != expected)
                {
                    throw;
                }
                mockStats.Verify(m => m.Elapsed("mjolnir command test.FaultingTaskWithEchoThrowingFallback fallback", "Failure", It.IsAny <TimeSpan>()), Times.Once);
                return; // Expected.
            }

            AssertX.FailExpectedException();
        }
Example #3
0
        public async Task InvokeAsync_TaskFaultsAndFallbackThrows_RethrowsFallbackException()
        {
            var expected = new ExpectedTestException("Expected rethrown exception");
            var command  = new FaultingTaskWithEchoThrowingFallbackCommand(expected);

            try
            {
                await command.InvokeAsync();
            }
            catch (ExpectedTestException e)
            {
                Assert.Equal(expected, e);
                return;
            }

            AssertX.FailExpectedException();
        }