Пример #1
0
        public async Task InvokeAsync_Succeeds_DoesntInvokeFallback()
        {
            const string value   = "value";
            var          command = new SuccessfulEchoCommandWithFallback(value);
            var          result  = await command.InvokeAsync();

            Assert.Equal(value, result);
            Assert.False(command.FallbackCalled);
        }
Пример #2
0
        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);
        }
Пример #3
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);
        }
Пример #4
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);
        }