public async Task When_Sending_A_Command_And_The_Policy_Is_Not_In_The_Registry_Async() { _exception = await Catch.ExceptionAsync(() => _commandProcessor.SendAsync(_myCommand)); //_should_throw_an_exception _exception.Should().BeOfType <KeyNotFoundException>(); //_should_give_the_name_of_the_missing_policy _exception.Should().NotBeNull(); _exception.Message.Should().Contain("The given key 'MyDivideByZeroPolicy' was not present in the dictionary"); }
public async Task When_There_Are_Multiple_Possible_Command_Handlers_Async() { _exception = await Catch.ExceptionAsync(() => _commandProcessor.SendAsync(_myCommand)); //_should_fail_because_multiple_receivers_found _exception.Should().BeOfType <ArgumentException>(); //_should_have_an_error_message_that_tells_you_why = () => _exception _exception.Should().NotBeNull(); _exception.Message.Should().Contain("More than one handler was found for the typeof command Paramore.Brighter.Core.Tests.CommandProcessors.TestDoubles.MyCommand - a command should only have one handler."); }
public async Task When_There_Are_Multiple_Subscribers_Async() { _exception = await Catch.ExceptionAsync(() => _commandProcessor.PublishAsync(_myEvent)); //_should_not_throw_an_exception _exception.Should().BeNull(); //_should_publish_the_command_to_the_first_event_handler _receivedMessages.Should().Contain(nameof(MyEventHandlerAsync), _myEvent.Id); //_should_publish_the_command_to_the_second_event_handler _receivedMessages.Should().Contain(nameof(MyOtherEventHandlerAsync), _myEvent.Id); }
public async Task When_The_Message_Is_Already_In_The_Command_Store_Async() { await _sqlCommandStore.AddAsync(_raisedCommand, _contextKey); _exception = await Catch.ExceptionAsync(() => _sqlCommandStore.AddAsync(_raisedCommand, _contextKey)); //_should_succeed_even_if_the_message_is_a_duplicate _exception.Should().BeNull(); var exists = await _sqlCommandStore.ExistsAsync <MyCommand>(_raisedCommand.Id, _contextKey); exists.Should().BeTrue(); }
public async Task Command_Is_Not_Stored_If_The_Handler_Is_Not_Successful() { Guid id = Guid.NewGuid(); await Catch.ExceptionAsync(async() => await _commandProcessor.SendAsync(new MyCommandToFail() { Id = id })); var exists = await _inbox.ExistsAsync <MyCommandToFail>(id, typeof(MyStoredCommandToFailHandlerAsync).FullName); exists.Should().BeFalse(); }
public async Task When_The_Message_Is_Already_In_The_Inbox_Async() { await _sqlInbox.AddAsync(_raisedCommand, _contextKey); _exception = await Catch.ExceptionAsync(() => _sqlInbox.AddAsync(_raisedCommand, _contextKey)); //_should_succeed_even_if_the_message_is_a_duplicate _exception.Should().BeNull(); var exists = await _sqlInbox.ExistsAsync <MyCommand>(_raisedCommand.Id, _contextKey); AssertionExtensions.Should((bool)exists).BeTrue(); }
public async Task When_Publishing_To_Multiple_Subscribers_Should_Aggregate_Exceptions_Async() { _exception = await Catch.ExceptionAsync(async() => await _commandProcessor.PublishAsync(_myEvent)); //_should_throw_an_aggregate_exception _exception.Should().BeOfType <AggregateException>(); //_should_have_an_inner_exception_from_the_handler ((AggregateException)_exception).InnerException.Should().BeOfType <InvalidOperationException>(); //_should_publish_the_command_to_the_first_event_handler _receivedMessages.Should().Contain(nameof(MyEventHandlerAsync), _myEvent.Id); //_should_publish_the_command_to_the_second_event_handler _receivedMessages.Should().Contain(nameof(MyOtherEventHandlerAsync), _myEvent.Id); }
public async Task When_there_are_multiple_messages_in_the_message_store_and_a_range_by_index_is_fetched() { await _dynamoDbMessageStore.AddAsync(_messageEarliest); await Task.Delay(100); await _dynamoDbMessageStore.AddAsync(_message1); await Task.Delay(100); await _dynamoDbMessageStore.AddAsync(_message2); var exception = await Catch.ExceptionAsync(() => _dynamoDbMessageStore.GetAsync(1, 3)); exception.Should().BeOfType <NotSupportedException>(); }
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>(); }
public async Task When_Monitoring_We_Should_Record_But_Rethrow_Exceptions_Async() { _exception = await Catch.ExceptionAsync(() => _commandProcessor.SendAsync(_command)); _controlBusSender.Observe <MonitorEvent>(); _afterEvent = _controlBusSender.Observe <MonitorEvent>(); //_should_pass_through_the_exception_not_swallow _exception.Should().NotBeNull(); //_should_monitor_the_exception _afterEvent.Exception.Should().BeOfType <Exception>(); //_should_surface_the_error_message _afterEvent.Exception.Message.Should().Contain("monitored"); //_should_have_an_instance_name_after _afterEvent.InstanceName.Should().Be("UnitTests"); //_should_post_the_handler_fullname_to_the_control_bus_after _afterEvent.HandlerFullAssemblyName.Should().Be(typeof(MyMonitoredHandlerThatThrowsAsync).AssemblyQualifiedName); //_should_post_the_handler_name_to_the_control_bus_after _afterEvent.HandlerName.Should().Be(typeof(MyMonitoredHandlerThatThrowsAsync).FullName); //_should_include_the_underlying_request_details_after _afterEvent.RequestBody.Should().Be(_originalRequestAsJson); //should_post_the_time_of_the_request_after _afterEvent.EventTime.AsUtc().Should().BeAfter(_at.AsUtc()); }
public async Task When_Posting_A_Message_And_There_Is_No_Outbox_Async() { _exception = await Catch.ExceptionAsync(() => _commandProcessor.PostAsync(_myCommand)); }
public async void When_There_Is_No_Message_In_The_Sql_Inbox() { var exception = await Catch.ExceptionAsync(() => _dynamoDbInbox.GetAsync <MyCommand>(Guid.NewGuid(), "some key")); exception.Should().BeOfType <RequestNotFoundException <MyCommand> >(); }
public async Task non_throwing_action_should_return_null() { var exception = await Catch.ExceptionAsync(() => new AsyncStub().NonThrowAsync()); exception.ShouldBe(null); }
public async Task throwing_action_should_return_same_exception() { var exception = await Catch.ExceptionAsync(() => new AsyncStub().ThrowAsync()); exception.ShouldBeOfType <InvalidOperationException>(); }