public async Task InvokeAsync_SuccessAndFallbackImplemented()
        {
            var mockStats = new Mock <IStats>();
            var command   = new SuccessfulEchoCommandWithFallback("foo")
            {
                Stats = mockStats.Object,
            };

            await command.InvokeAsync();

            mockStats.Verify(m => m.Elapsed(It.IsRegex(".*fallback.*"), It.IsAny <string>(), It.IsAny <TimeSpan>()), Times.Never);
        }
Exemple #2
0
        public async Task InvokeAsync_ThreadPoolRejects_InvokesFallback()
        {
            var exception = new IsolationThreadPoolRejectedException();
            var pool      = new RejectingIsolationThreadPool(exception);

            var command = new SuccessfulEchoCommandWithFallback(new { })
            {
                ThreadPool = pool,
            };

            await command.InvokeAsync(); // Won't throw because there's a successful fallback.

            Assert.True(command.FallbackCalled);
        }
Exemple #3
0
        public async Task InvokeAsync_WhenBreakerRejectedButFallbackDefined_InvokesFallback()
        {
            var expected = new { };

            var mockBreaker = new Mock <ICircuitBreaker>();

            mockBreaker.Setup(m => m.IsAllowing()).Returns(false);

            var command = new SuccessfulEchoCommandWithFallback(expected)
            {
                CircuitBreaker = mockBreaker.Object,
            };

            var result = await command.InvokeAsync();

            Assert.True(command.FallbackCalled);
            Assert.Equal(expected, result);
        }