Exemplo n.º 1
0
        public void should_handle_execution_completion_received()
        {
            var messageExecutionCompletedTransportMessage = new MessageExecutionCompleted(MessageId.NextId(), 0, null).ToTransportMessage();

            InnerTransport.RaiseMessageReceived(messageExecutionCompletedTransportMessage);

            var forwardedMessage = MessagesForwardedToBus.Single(x => x.MessageTypeId == MessageExecutionCompleted.TypeId);

            forwardedMessage.ShouldEqualDeeply(messageExecutionCompletedTransportMessage);
        }
Exemplo n.º 2
0
            public void shoud_send_a_completion_message_without_error_code()
            {
                using (MessageId.PauseIdGeneration())
                {
                    var command = new FakeCommand(123);
                    SetupDispatch(command);

                    var transportMessageReceived = command.ToTransportMessage(_peerUp);
                    _transport.RaiseMessageReceived(transportMessageReceived);

                    var messageExecutionCompleted = new MessageExecutionCompleted(transportMessageReceived.Id, 0, null).ToTransportMessage(_self);
                    _transport.ExpectExactly(new TransportMessageSent(messageExecutionCompleted, _peerUp));
                }
            }
Exemplo n.º 3
0
            public void shoud_send_a_completion_message_with_error_code_on_exception()
            {
                using (MessageId.PauseIdGeneration())
                {
                    var command = new FakeCommand(123);
                    SetupDispatch(command, error: new Exception());
                    var transportMessageReceived = command.ToTransportMessage(_peerUp);

                    _transport.RaiseMessageReceived(transportMessageReceived);

                    var expectedTransportMessage = new MessageExecutionCompleted(transportMessageReceived.Id, 1, null).ToTransportMessage(_self);
                    _transport.Expect(new TransportMessageSent(expectedTransportMessage, _peerUp));
                }
            }
        public void shoud_send_a_completion_message_with_domain_exception_error_code()
        {
            using (MessageId.PauseIdGeneration())
            {
                const int domainExceptionValue = 5000;
                var       command = new FakeCommand(123);
                SetupDispatch(command, error: new DomainException(domainExceptionValue, "Domain Exception"));
                var transportMessageReceived = command.ToTransportMessage(_peerUp);

                _transport.RaiseMessageReceived(transportMessageReceived);

                var expectedTransportMessage = new MessageExecutionCompleted(transportMessageReceived.Id, domainExceptionValue).ToTransportMessage(_self);
                _transport.ExpectExactly(new TransportMessageSent(expectedTransportMessage, _peerUp));
            }
        }
        public void should_release_task_when_completion_message_is_sent()
        {
            using (MessageId.PauseIdGeneration())
            {
                var command = new FakeCommand(123);
                SetupPeersHandlingMessage <FakeCommand>(_peerUp);
                _bus.Start();

                var task             = _bus.Send(command);
                var commandCompleted = new MessageExecutionCompleted(MessageId.NextId(), 1);
                _transport.RaiseMessageReceived(commandCompleted.ToTransportMessage());

                var receivedAck = task.Wait(10);

                receivedAck.ShouldBeTrue();
                task.Result.ErrorCode.ShouldEqual(1);
            }
        }
Exemplo n.º 6
0
        public void handlers_reply_with_an_int()
        {
            using (MessageId.PauseIdGeneration())
            {
                const int commandReply = 456;
                var       command      = new FakeCommand(123);
                SetupDispatch(command, _ => _bus.Reply(commandReply));

                var transportMessageReceived = command.ToTransportMessage(_peerUp);
                var expectedTransportMessage = new MessageExecutionCompleted(transportMessageReceived.Id, commandReply, null).ToTransportMessage(_self);

                _transport.RaiseMessageReceived(transportMessageReceived);

                var sentMessage = _transport.Messages.Single();
                expectedTransportMessage.ShouldHaveSamePropertiesAs(sentMessage.TransportMessage);
                var destination = sentMessage.Targets.Single();
                destination.ShouldHaveSamePropertiesAs(_peerUp);
            }
        }
Exemplo n.º 7
0
        public void handlers_reply_with_an_object()
        {
            using (MessageId.PauseIdGeneration())
            {
                var command                  = new FakeCommand(123);
                var commandResult            = new FakeCommandResult("CommandResult", 45);
                var transportMessageReceived = command.ToTransportMessage(_peerUp);
                SetupDispatch(command, _ => _bus.Reply(commandResult));

                var expectedExecutionCompleted = MessageExecutionCompleted.Success(transportMessageReceived.Id, commandResult, _messageSerializer);
                var expectedTransportMessage   = expectedExecutionCompleted.ToTransportMessage(_self);

                _transport.RaiseMessageReceived(transportMessageReceived);

                var sentMessage = _transport.Messages.Single();
                expectedTransportMessage.ShouldHaveSamePropertiesAs(sentMessage.TransportMessage);
                var destination = sentMessage.Targets.Single();
                destination.ShouldHaveSamePropertiesAs(_peerUp);
            }
        }
Exemplo n.º 8
0
            public void should_not_continue_execution_after_awaiting_a_send_in_the_MessageReceived_thread()
            {
                using (MessageId.PauseIdGeneration())
                {
                    var command = new FakeCommand(456);
                    SetupPeersHandlingMessage <FakeCommand>(_peerUp);
                    _bus.Start();

                    var task               = _bus.Send(command);
                    var commandCompleted   = new MessageExecutionCompleted(MessageId.NextId(), 0, null);
                    int backgroundThreadId = 0;

                    BackgroundThread.Start(() =>
                    {
                        backgroundThreadId = Thread.CurrentThread.ManagedThreadId;
                        _transport.RaiseMessageReceived(commandCompleted.ToTransportMessage());
                    });

                    var getThreadIdTask = GetThreadIdAfterAwaitingCommandResult(task);

                    getThreadIdTask.Result.ShouldNotEqual(backgroundThreadId);
                }
            }