Beispiel #1
0
        public async Task When_Implicit_Clearing_The_PostBox_On_The_Command_Processor_Async()
        {
            await _fakeOutboxSync.AddAsync(_message);

            await _fakeOutboxSync.AddAsync(_message2);

            _commandProcessor.ClearAsyncOutbox(1, 1);

            for (var i = 1; i <= 10; i++)
            {
                if (_fakeMessageProducer.SentMessages.Count == 1)
                {
                    break;
                }
                await Task.Delay(i * 100);
            }

            _commandProcessor.ClearAsyncOutbox(1, 1);

            //Try again and kick off another background thread
            for (var i = 1; i <= 10; i++)
            {
                if (_fakeMessageProducer.SentMessages.Count == 2)
                {
                    break;
                }
                await Task.Delay(i * 100);

                _commandProcessor.ClearAsyncOutbox(1, 1);
            }

            //_should_send_a_message_via_the_messaging_gateway
            _fakeMessageProducer.MessageWasSent.Should().BeTrue();

            var sentMessage = _fakeMessageProducer.SentMessages.FirstOrDefault(m => m.Id == _message.Id);

            sentMessage.Should().NotBeNull();
            sentMessage.Id.Should().Be(_message.Id);
            sentMessage.Header.Topic.Should().Be(_message.Header.Topic);
            sentMessage.Body.Value.Should().Be(_message.Body.Value);

            var sentMessage2 = _fakeMessageProducer.SentMessages.FirstOrDefault(m => m.Id == _message2.Id);

            sentMessage2.Should().NotBeNull();
            sentMessage2.Id.Should().Be(_message2.Id);
            sentMessage2.Header.Topic.Should().Be(_message2.Header.Topic);
            sentMessage2.Body.Value.Should().Be(_message2.Body.Value);
        }
        public async Task When_Clearing_The_PostBox_On_The_Command_Processor_Async()
        {
            await _fakeOutboxSync.AddAsync(_message);

            await _fakeOutboxSync.AddAsync(_message2);

            _commandProcessor.ClearAsyncOutbox(2, 1, true);

            await Task.Delay(1000);

            //_should_send_a_message_via_the_messaging_gateway
            _fakeMessageProducerWithPublishConfirmation.MessageWasSent.Should().BeTrue();

            var sentMessage = _fakeMessageProducerWithPublishConfirmation.SentMessages[0];

            sentMessage.Should().NotBeNull();
            sentMessage.Id.Should().Be(_message.Id);
            sentMessage.Header.Topic.Should().Be(_message.Header.Topic);
            sentMessage.Body.Value.Should().Be(_message.Body.Value);

            var sentMessage2 = _fakeMessageProducerWithPublishConfirmation.SentMessages[1];

            sentMessage2.Should().NotBeNull();
            sentMessage2.Id.Should().Be(_message2.Id);
            sentMessage2.Header.Topic.Should().Be(_message2.Header.Topic);
            sentMessage2.Body.Value.Should().Be(_message2.Body.Value);
        }