Exemplo n.º 1
0
        public void When_Sending_A_Command_That_Repeatedely_Fails_Break_The_Circuit_Async()
        {
            //First two should be caught, and increment the count
            _firstException  = Catch.Exception(() => AsyncContext.Run(async() => await _commandProcessor.SendAsync(_myCommand)));
            _secondException = Catch.Exception(() => AsyncContext.Run(async() => await _commandProcessor.SendAsync(_myCommand)));
            //this one should tell us that the circuit is broken
            _thirdException = Catch.Exception(() => AsyncContext.Run(async() => await _commandProcessor.SendAsync(_myCommand)));

            //_should_send_the_command_to_the_command_handler
            Assert.True(MyFailsWithDivideByZeroHandlerAsync.ShouldReceive(_myCommand));
            //_should_bubble_up_the_first_exception
            Assert.IsInstanceOf <DivideByZeroException>(_firstException);
            //_should_bubble_up_the_second_exception
            Assert.IsInstanceOf <DivideByZeroException>(_secondException);
            //_should_break_the_circuit_after_two_fails
            Assert.IsInstanceOf <BrokenCircuitException>(_thirdException);
        }
Exemplo n.º 2
0
        public async Task When_Sending_A_Command_That_Repeatedly_Fails_Break_The_Circuit_Async()
        {
            //First two should be caught, and increment the count
            _firstException = await Catch.ExceptionAsync(async() => await _commandProcessor.SendAsync(_myCommand));

            _secondException = await Catch.ExceptionAsync(async() => await _commandProcessor.SendAsync(_myCommand));

            //this one should tell us that the circuit is broken
            _thirdException = await Catch.ExceptionAsync(async() => await _commandProcessor.SendAsync(_myCommand));

            //_should_send_the_command_to_the_command_handler
            MyFailsWithDivideByZeroHandlerAsync.ShouldReceive(_myCommand).Should().BeTrue();
            //_should_bubble_up_the_first_exception
            _firstException.Should().BeOfType <DivideByZeroException>();
            //_should_bubble_up_the_second_exception
            _secondException.Should().BeOfType <DivideByZeroException>();
            //_should_break_the_circuit_after_two_fails
            _thirdException.Should().BeOfType <BrokenCircuitException>();
        }