public void when_start_consume_messages_but_not_initialized_it_should_fail()
        {
            var    driver = new BrokerIngressKafkaDriver(MakeDriverConfiguration(), Mock.Of <IConsumerRegistry>());
            Action sut    = () => driver.StartConsumeMessages(new[] { "topic-1", "topic-2" }, CancellationToken.None);

            sut.Should().ThrowExactly <PoezdOperationException>().Where(exception => exception.Message.Contains("initialized"));
        }
        public void when_start_consume_messages_with_invalid_arguments_it_should_fail()
        {
            var driver = new BrokerIngressKafkaDriver(MakeDriverConfiguration(), Mock.Of <IConsumerRegistry>());

            driver.Initialize(
                Mock.Of <IBrokerIngress>(),
                new[] { MakeApi <int, byte[]>(), MakeApi <int, string>() },
                MakeServiceProviderMock().Object);
            Action sut = () => driver.StartConsumeMessages(queueNamePatterns: null, CancellationToken.None);

            sut.Should().ThrowExactly <ArgumentNullException>().Where(exception => exception.ParamName.Equals("queueNamePatterns"));
        }
        public async Task when_start_consume_messages_it_should_consume_messages()
        {
            var consumerRegistryMock = new Mock <IConsumerRegistry>();
            var apiConsumerMock      = new Mock <IApiConsumer <int, byte[]> >();
            var headers = new Headers {
                { "header1", new byte[0] }
            };

            apiConsumerMock
            .Setup(consumer => consumer.Start(It.IsAny <Func <ConsumeResult <int, byte[]>, Task> >(), It.IsAny <CancellationToken>()))
            .Callback(
                (Func <ConsumeResult <int, byte[]>, Task> onMessageReceivedFunc, CancellationToken cancellationToken) =>
            {
                onMessageReceivedFunc(
                    new ConsumeResult <int, byte[]>
                {
                    Topic   = "topic1",
                    Message = new Message <int, byte[]> {
                        Headers = headers, Key = 555, Timestamp = Timestamp.Default, Value = new byte[0]
                    }
                });
            })
            .Returns(() => Task.CompletedTask);
            consumerRegistryMock
            .Setup(registry => registry.Get <int, byte[]>(It.IsAny <IIngressApi>()))
            .Returns(() => apiConsumerMock.Object);

            var sut = new BrokerIngressKafkaDriver(MakeDriverConfiguration(), consumerRegistryMock.Object);

            var consumed    = 0;
            var ingressMock = new Mock <IBrokerIngress>();

            ingressMock
            .Setup(
                ingress => ingress.RouteIngressMessage(
                    It.IsAny <string>(),
                    It.IsAny <DateTimeOffset>(),
                    It.IsAny <int>(),
                    It.IsAny <byte[]>(),
                    It.IsAny <IReadOnlyDictionary <string, string> >()))
            .Callback(() => consumed++);
            sut.Initialize(
                ingressMock.Object,
                new[] { MakeApi <int, byte[]>() },
                MakeServiceProviderMock().Object);

            await sut.StartConsumeMessages(new[] { "topic1" }, CancellationToken.None);

            consumed.Should().Be(expected: 1, "a message should be consumed");
        }