public async Task InvokeAsync_TaskFaultsAndNoFallback_ThrowsCommandException()
        {
            var command = new FaultingTaskWithoutFallbackCommand();
            try
            {
                await command.InvokeAsync();
            }
            catch (CommandFailedException)
            {
                return; // Expected.
            }

            AssertX.FailExpectedException();
        }
Exemple #2
0
        public async Task InvokeAsync_TaskFaultsAndNoFallback_ThrowsCommandException()
        {
            var command = new FaultingTaskWithoutFallbackCommand();

            try
            {
                await command.InvokeAsync();
            }
            catch (CommandFailedException)
            {
                return; // Expected.
            }

            AssertX.FailExpectedException();
        }
Exemple #3
0
        public async Task InvokeAsync_GeneralExceptionFromReturnedTask()
        {
            var mockStats = new Mock<IStats>();
            var mockMetricEvents = new Mock<IMetricEvents>();
            var command = new FaultingTaskWithoutFallbackCommand
            {
                Stats = mockStats.Object,
                MetricEvents = mockMetricEvents.Object,
            };

            await Assert.ThrowsAsync<CommandFailedException>(command.InvokeAsync);

            mockStats.Verify(m => m.Elapsed("mjolnir command test.FaultingTaskWithoutFallback total", "Faulted", It.IsAny<TimeSpan>()), Times.Once);
            mockStats.Verify(m => m.Elapsed("mjolnir command test.FaultingTaskWithoutFallback execute", "Faulted", It.IsAny<TimeSpan>()), Times.Once);
            mockMetricEvents.Verify(m => m.CommandInvoked("test.FaultingTaskWithoutFallback", It.IsAny<double>(), It.IsAny<double>(), "Faulted", "throw"));
            mockMetricEvents.Verify(m => m.RejectedByBulkhead(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
        }
Exemple #4
0
        public async Task InvokeAsync_WhenCommandThrowsException_MarksMetricsCommandFailure()
        {
            var mockMetrics = new Mock <ICommandMetrics>();
            var mockBreaker = CreateMockBreaker(true, mockMetrics);

            var command = new FaultingTaskWithoutFallbackCommand
            {
                CircuitBreaker = mockBreaker.Object,
            };

            try
            {
                await command.InvokeAsync();
            }
            catch (Exception)
            {
                // Expected.
                mockMetrics.Verify(m => m.MarkCommandFailure(), Times.Once);
            }
        }
        public async Task InvokeAsync_GeneralExceptionFromReturnedTask()
        {
            var mockStats = new Mock<IStats>();
            var command = new FaultingTaskWithoutFallbackCommand
            {
                Stats = mockStats.Object
            };

            try
            {
                await command.InvokeAsync();
            }
            catch (CommandFailedException)
            {
                mockStats.Verify(m => m.Elapsed("mjolnir command test.FaultingTaskWithoutFallback total", "Faulted", It.IsAny<TimeSpan>()), Times.Once);
                mockStats.Verify(m => m.Elapsed("mjolnir command test.FaultingTaskWithoutFallback execute", "Faulted", It.IsAny<TimeSpan>()), Times.Once);
                return; // Expected.
            }

            AssertX.FailExpectedException();
        }
Exemple #6
0
        public async Task InvokeAsync_GeneralExceptionFromReturnedTask()
        {
            var mockStats = new Mock <IStats>();
            var command   = new FaultingTaskWithoutFallbackCommand
            {
                Stats = mockStats.Object
            };

            try
            {
                await command.InvokeAsync();
            }
            catch (CommandFailedException)
            {
                mockStats.Verify(m => m.Elapsed("mjolnir command test.FaultingTaskWithoutFallback total", "Faulted", It.IsAny <TimeSpan>()), Times.Once);
                mockStats.Verify(m => m.Elapsed("mjolnir command test.FaultingTaskWithoutFallback execute", "Faulted", It.IsAny <TimeSpan>()), Times.Once);
                return; // Expected.
            }

            AssertX.FailExpectedException();
        }
        public async Task InvokeAsync_WhenCommandThrowsException_MarksMetricsCommandFailure()
        {
            var mockMetrics = new Mock<ICommandMetrics>();
            var mockBreaker = CreateMockBreaker(true, mockMetrics);
            
            var command = new FaultingTaskWithoutFallbackCommand
            {
                CircuitBreaker = mockBreaker.Object,
            };

            var e = await Assert.ThrowsAsync<CommandFailedException>(() => command.InvokeAsync());
            mockMetrics.Verify(m => m.MarkCommandFailure(), Times.Once);
        }
Exemple #8
0
 public async Task InvokeAsync_TaskFaultsAndNoFallback_ThrowsCommandException()
 {
     var command = new FaultingTaskWithoutFallbackCommand();
     await Assert.ThrowsAsync<CommandFailedException>(() => command.InvokeAsync());
 }
        public async Task InvokeAsync_WhenCommandThrowsException_MarksMetricsCommandFailure()
        {
            var mockMetrics = new Mock<ICommandMetrics>();
            var mockBreaker = CreateMockBreaker(true, mockMetrics);
            
            var command = new FaultingTaskWithoutFallbackCommand
            {
                CircuitBreaker = mockBreaker.Object,
            };

            try
            {
                await command.InvokeAsync();
            }
            catch (Exception)
            {
                // Expected.
                mockMetrics.Verify(m => m.MarkCommandFailure(), Times.Once);
            }
        }