コード例 #1
0
        public async Task InvokeAsync_TaskFaultsAndFallbackSucceeds_ReturnsFallbackResult()
        {
            var command = new FaultingTaskWithSuccessfulFallbackCommand();
            var result  = await command.InvokeAsync();

            Assert.NotNull(result);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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();
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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();
        }
コード例 #7
0
        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);
        }
コード例 #8
0
 public async Task InvokeAsync_TaskFaultsAndFallbackSucceeds_ReturnsFallbackResult()
 {
     var command = new FaultingTaskWithSuccessfulFallbackCommand();
     var result = await command.InvokeAsync();
     Assert.NotNull(result);
 }