public async Task OnMessageReceived_MultipleMessages_CorrectlyRoutedToEndpoint(IIntegrationMessage message, string[] expectedEndpointNames)
        {
            _routingConfiguration.Add <IIntegrationMessage>(new TestEndpoint("allMessages"), null);
            _routingConfiguration.Add <IIntegrationEvent>(new TestEndpoint("allEvents"), null);
            _routingConfiguration.Add <TestEventOne>(new TestEndpoint("eventOne"), null);
            _routingConfiguration.Add <TestEventTwo>(new TestEndpoint("eventTwo"), null);

            await _connectorRouter.OnMessageReceived(message);

            await _outboundQueue.Commit();

            var queued = await _outboundQueue.Dequeue(100);

            foreach (var expectedEndpointName in expectedEndpointNames)
            {
                queued.Count(x => x.Message.Endpoint.Name == expectedEndpointName).Should().Be(1);
            }

            var notExpectedEndpointNames = _routingConfiguration
                                           .Routes.Select(r => r.DestinationEndpoint.Name)
                                           .Where(r => !expectedEndpointNames.Contains(r));

            foreach (var notExpectedEndpointName in notExpectedEndpointNames)
            {
                queued.Count(x => x.Message.Endpoint.Name == notExpectedEndpointName).Should().Be(0);
            }
        }
        public async Task DequeueTest(int count, int expected)
        {
            for (var i = 0; i < 5; i++)
            {
                await _queue.Enqueue(_sampleOutboundMessage);
            }

            await _queue.Commit();

            var result = await _queue.Dequeue(count);

            result.Count().Should().Be(expected);
        }
        public async Task OnMessageReceived_SingleMessage_Queued()
        {
            var outboundMessage = new OutboundMessage <TestEventOne>(
                new TestEventOne {
                Content = "Test"
            },
                new[]
            {
                new MessageHeader("header1", "value1"),
                new MessageHeader("header2", "value2")
            },
                TestEndpoint.GetDefault());

            outboundMessage.RawContent = new JsonMessageSerializer().Serialize(outboundMessage.Content, outboundMessage.Headers);

            await _connector.RelayMessage(outboundMessage);

            await _queue.Commit();

            (await _queue.GetLength()).Should().Be(1);
            var queued = (await _queue.Dequeue(1)).First();

            queued.Endpoint.Should().Be(outboundMessage.Endpoint);
            queued.Headers.Count().Should().Be(3);
            queued.Content.Should().BeEquivalentTo(new JsonMessageSerializer().Serialize(outboundMessage.Content, outboundMessage.Headers));
        }
        public async Task OnMessageReceived_SingleMessage_Queued()
        {
            var outboundMessage = new OutboundMessage <TestEventOne>()
            {
                Message = new TestEventOne {
                    Content = "Test"
                },
                Headers =
                {
                    { "header1", "value1" },
                    { "header2", "value2" }
                },
                Endpoint = TestEndpoint.Default
            };

            await _connector.RelayMessage(outboundMessage);

            await _queue.Commit();

            _queue.Length.Should().Be(1);
            var queued = (await _queue.Dequeue(1)).First();

            queued.Message.Endpoint.Should().Be(outboundMessage.Endpoint);
            queued.Message.Headers.Count.Should().Be(2);
            ((IIntegrationMessage)queued.Message.Message).Id.Should().Be(outboundMessage.Message.Id);
        }
        public async Task Handle_OutboundMessage_CorrectlyRelayed()
        {
            var outboundMessage = new OutboundMessage <TestEventOne>(
                new TestEventOne(),
                new MessageHeader[0],
                new OutboundRoutingConfiguration.OutboundRoute(
                    typeof(TestEventOne),
                    TestEndpoint.GetDefault(),
                    typeof(OutboundConnector)));

            await _behavior.Handle(new[] { outboundMessage, outboundMessage, outboundMessage }, Task.FromResult);

            await _outboundQueue.Commit();

            var queued = await _outboundQueue.Dequeue(10);

            queued.Count().Should().Be(0);
            _broker.ProducedMessages.Count.Should().Be(3);
        }