public void persistent_messages_sent_to_non_persistent_peers_should_not_generate_a_persist_command() { using (MessageId.PauseIdGeneration()) { var message = new FakeEvent(123).ToTransportMessage(Self); Transport.Send(message, new[] { AnotherNonPersistentPeer }); InnerTransport.ExpectExactly(new TransportMessageSent(message, new[] { AnotherNonPersistentPeer })); } }
public void shoud_not_send_a_completion_message_for_events() { using (MessageId.PauseIdGeneration()) { var @event = new FakeEvent(123); var transportMessageReceived = @event.ToTransportMessage(_peerUp); _transport.RaiseMessageReceived(transportMessageReceived); _transport.Messages.ShouldNotContain(x => x.TransportMessage.MessageTypeId == MessageExecutionCompleted.TypeId); } }
public void should_publish_event_with_message_context() { MessageContext.Current.ShouldBeNull(); var message = new FakeEvent(1); MessageContext context = null; _busMock.Setup(x => x.Publish(message)).Callback(() => context = MessageContext.Current); _bus.Publish(message); MessageContext.Current.ShouldBeNull(); context.ShouldEqual(_context); }
public void should_only_forward_replayed_messages_during_replay_phase() { Transport.Start(); var transportMessageToForward = new FakeCommand(123).ToTransportMessage(); var normalTransportMessage = new FakeEvent(123).ToTransportMessage(); var replayedTransportMessage = transportMessageToForward.ToReplayedTransportMessage(ReplayId); InnerTransport.RaiseMessageReceived(replayedTransportMessage); InnerTransport.RaiseMessageReceived(normalTransportMessage); MessagesForwardedToBus.Count.ShouldEqual(1); MessagesForwardedToBus.Single().Id.ShouldEqual(transportMessageToForward.Id); }
public void should_not_consider_if_peer_is_up_to_publish_events() { using (MessageId.PauseIdGeneration()) { var @event = new FakeEvent(456); SetupPeersHandlingMessage<FakeEvent>(_peerUp, _peerDown); _bus.Start(); _bus.Publish(@event); _transport.ExpectExactly(new TransportMessageSent(@event.ToTransportMessage(_self), new[] { _peerUp, _peerDown })); } }
public void persistent_messages_sent_to_multiple_peers_should_only_be_persisted_for_persistent_ones() { using (MessageId.PauseIdGeneration()) { var message = new FakeEvent(123).ToTransportMessage(Self); var persistCommand = new PersistMessageCommand(message, new[] { AnotherPersistentPeer.Id }).ToTransportMessage(Self); Transport.Send(message, new[] { AnotherPersistentPeer, AnotherNonPersistentPeer }); InnerTransport.ExpectExactly( new TransportMessageSent(message, new[] { AnotherPersistentPeer, AnotherNonPersistentPeer }), new TransportMessageSent(persistCommand, new[] { PersistencePeer }) ); } }
public void should_publish_a_message() { using (MessageId.PauseIdGeneration()) { var message = new FakeEvent(456); SetupPeersHandlingMessage<FakeEvent>(_peerUp); var expectedTransportMessage = message.ToTransportMessage(_self); _bus.Start(); _bus.Publish(message); var sentMessage = _transport.Messages.Single(); expectedTransportMessage.ShouldHaveSamePropertiesAs(sentMessage.TransportMessage); var destination = sentMessage.Targets.Single(); destination.ShouldHaveSamePropertiesAs(_peerUp); } }
public void should_send_a_MessageProcessingFailed_on_unknown_event_error() { SetupPeersHandlingMessage<MessageProcessingFailed>(_peerUp); using (SystemDateTime.PauseTime()) using (MessageId.PauseIdGeneration()) { var message = new FakeEvent(123); var messageJson = JsonConvert.SerializeObject(message); var exception = new Exception("Exception message"); SetupDispatch(message, error: exception); var transportMessageReceived = message.ToTransportMessage(_peerUp); _transport.RaiseMessageReceived(transportMessageReceived); var expectedTransportMessage = new MessageProcessingFailed(transportMessageReceived, messageJson, exception.ToString(), SystemDateTime.UtcNow, new[] { typeof(FakeMessageHandler).FullName }).ToTransportMessage(_self); _transport.Expect(new TransportMessageSent(expectedTransportMessage, _peerUp)); } }
public void should_handle_event_locally() { var message = new FakeEvent(1); var handled = false; SetupDispatch(message, x => handled = true); SetupPeersHandlingMessage<FakeEvent>(_self, _peerUp); _bus.Start(); _bus.Publish(message); handled.ShouldBeTrue(); var sentMessage = _transport.Messages.Single(); sentMessage.Targets.Single().ShouldEqual(_peerUp); }
public void should_not_handle_event_locally_when_local_dispatch_is_disabled() { var message = new FakeEvent(1); var handled = false; SetupDispatch(message, x => handled = true); SetupPeersHandlingMessage<FakeEvent>(_self); _bus.Start(); using (LocalDispatch.Disable()) using (MessageId.PauseIdGeneration()) { _bus.Publish(message); handled.ShouldBeFalse(); _transport.ExpectExactly(new TransportMessageSent(message.ToTransportMessage(_self), _self)); } }
public void should_dispatch_to_event_handler() { IMessage receivedMessage = null; _messageDispatcher.AddInvoker(new EventHandlerInvoker(x => receivedMessage = x, typeof(FakeEvent))); var evt = new FakeEvent(123); Dispatch(evt); receivedMessage.ShouldEqual(evt); }