public void should_send_MessageProcessingFailed_if_unable_to_deserialize_message()
        {
            SetupPeersHandlingMessage<MessageProcessingFailed>(_peerUp);

            _bus.Start();

            var command = new FakeCommand(123);
            _messageSerializer.AddSerializationExceptionFor(command.TypeId(), "Serialization error");

            using (SystemDateTime.PauseTime())
            using (MessageId.PauseIdGeneration())
            {
                var transportMessage = command.ToTransportMessage();

                var messageProcessingFailedBytes = new MessageProcessingFailed(null, null, null, DateTime.UtcNow, null).ToTransportMessage().MessageBytes;
                _messageSerializer.AddSerializationFuncFor<MessageProcessingFailed>(x =>
                {
                    x.FailingMessage.ShouldEqual(transportMessage);
                    x.ExceptionUtcTime.ShouldEqual(SystemDateTime.UtcNow);
                    x.ExceptionMessage.ShouldContain("Unable to deserialize message");
                    return messageProcessingFailedBytes;
                });
                
                _transport.RaiseMessageReceived(transportMessage);

                var processingFailedTransportMessage = new TransportMessage(MessageUtil.TypeId<MessageProcessingFailed>(), messageProcessingFailedBytes, _self);
                _transport.ExpectExactly(new TransportMessageSent(processingFailedTransportMessage, _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_send_a_MessageProcessingFailed_on_unknown_error_with_local_processing()
        {
            SetupPeersHandlingMessage<MessageProcessingFailed>(_peerUp);

            using (SystemDateTime.PauseTime())
            using (MessageId.PauseIdGeneration())
            {
                var command = new FakeCommand(123);
                var commandJson = JsonConvert.SerializeObject(command);
                var exception = new Exception("Exception message");
                SetupDispatch(command, error: exception);
                SetupPeersHandlingMessage<FakeCommand>(_self);

                _bus.Start();
                _bus.Send(command);

                var expectedTransportMessage = new MessageProcessingFailed(command.ToTransportMessage(_self), commandJson, exception.ToString(), SystemDateTime.UtcNow, new[] { typeof(FakeMessageHandler).FullName }).ToTransportMessage(_self);
                _transport.Expect(new TransportMessageSent(expectedTransportMessage, _peerUp));
            }
        }