Esempio n. 1
0
        public async Task InvokeAsync_TimesOutAndNoFallback_ThrowsCommandException()
        {
            var command = new TimingOutWithoutFallbackCommand(TimeSpan.FromMilliseconds(100));
            try
            {
                await command.InvokeAsync();
            }
            catch (CommandFailedException)
            {
                return; // Expected.
            }

            AssertX.FailExpectedException();
        }
Esempio n. 2
0
        public async Task InvokeAsync_TimesOutAndNoFallback_ThrowsCommandException()
        {
            var command = new TimingOutWithoutFallbackCommand(TimeSpan.FromMilliseconds(100));

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

            AssertX.FailExpectedException();
        }
Esempio n. 3
0
        public async Task InvokeAsync_WithTimeout_TimesOutAndThrowsCommandException()
        {
            var command = new TimingOutWithoutFallbackCommand(Timeout);

            try
            {
                await command.InvokeAsync();
            }
            catch (CommandFailedException e)
            {
                Assert.True(e.GetBaseException() is OperationCanceledException);
                return;
            }

            AssertX.FailExpectedException();
        }
Esempio n. 4
0
        public async Task InvokeAsync_OperationCanceledException()
        {
            var mockStats = new Mock<IStats>();
            var mockMetricEvents = new Mock<IMetricEvents>();
            var command = new TimingOutWithoutFallbackCommand(TimeSpan.FromMilliseconds(100))
            {
                Stats = mockStats.Object,
                MetricEvents = mockMetricEvents.Object,
            };

            var e = await Assert.ThrowsAsync<CommandTimeoutException>(command.InvokeAsync);

            Assert.True(e.GetBaseException() is OperationCanceledException);
            mockStats.Verify(m => m.Elapsed("mjolnir command test.TimingOutWithoutFallback total", "TimedOut", It.IsAny<TimeSpan>()), Times.Once);
            mockStats.Verify(m => m.Elapsed("mjolnir command test.TimingOutWithoutFallback execute", "TimedOut", It.IsAny<TimeSpan>()), Times.Once);
            mockMetricEvents.Verify(m => m.CommandInvoked("test.TimingOutWithoutFallback", It.IsAny<double>(), It.IsAny<double>(), "TimedOut", "throw"));
            mockMetricEvents.Verify(m => m.RejectedByBulkhead(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
        }
Esempio n. 5
0
        public async Task InvokeAsync_OperationCanceledException()
        {
            var mockStats = new Mock<IStats>();
            var command = new TimingOutWithoutFallbackCommand(TimeSpan.FromMilliseconds(100))
            {
                Stats = mockStats.Object,
            };

            try
            {
                await command.InvokeAsync();
            }
            catch (CommandFailedException e)
            {
                Assert.True(e.GetBaseException() is OperationCanceledException);
                mockStats.Verify(m => m.Elapsed("mjolnir command test.TimingOutWithoutFallback total", "Canceled", It.IsAny<TimeSpan>()), Times.Once);
                mockStats.Verify(m => m.Elapsed("mjolnir command test.TimingOutWithoutFallback execute", "Canceled", It.IsAny<TimeSpan>()), Times.Once);
                return; // Expected.
            }

            AssertX.FailExpectedException();
        }
Esempio n. 6
0
        public async Task InvokeAsync_OperationCanceledException()
        {
            var mockStats = new Mock <IStats>();
            var command   = new TimingOutWithoutFallbackCommand(TimeSpan.FromMilliseconds(100))
            {
                Stats = mockStats.Object,
            };

            try
            {
                await command.InvokeAsync();
            }
            catch (CommandFailedException e)
            {
                Assert.True(e.GetBaseException() is OperationCanceledException);
                mockStats.Verify(m => m.Elapsed("mjolnir command test.TimingOutWithoutFallback total", "Canceled", It.IsAny <TimeSpan>()), Times.Once);
                mockStats.Verify(m => m.Elapsed("mjolnir command test.TimingOutWithoutFallback execute", "Canceled", It.IsAny <TimeSpan>()), Times.Once);
                return; // Expected.
            }

            AssertX.FailExpectedException();
        }
Esempio n. 7
0
 public async Task InvokeAsync_TimesOutAndNoFallback_ThrowsCommandException()
 {
     var command = new TimingOutWithoutFallbackCommand(TimeSpan.FromMilliseconds(100));
     await Assert.ThrowsAsync<CommandTimeoutException>(() => command.InvokeAsync());
 }