Esempio n. 1
0
        public void when_initialize_it_should_initialize_driver()
        {
            var configuration = ConfigurationTests.CreateBrokerIngressConfiguration();
            var driverMock    = new Mock <IBrokerIngressDriver>();

            driverMock
            .Setup(
                driver => driver.Initialize(
                    It.IsAny <IBrokerIngress>(),
                    It.IsAny <IEnumerable <IIngressApi> >(),
                    It.IsAny <IDiContainerAdapter>()))
            .Verifiable();
            configuration.Driver = driverMock.Object;

            var serviceProviderMock = new Mock <IDiContainerAdapter>();

            serviceProviderMock.Setup(adapter => adapter.GetService(typeof(EmptyPipeFitter))).Returns(() => new EmptyPipeFitter());

            var sut = new BrokerIngress(
                Mock.Of <IMessageBroker>(),
                configuration,
                serviceProviderMock.Object);

            sut.Initialize();

            driverMock.Verify();
        }
Esempio n. 2
0
        public void when_get_api_by_queue_name_it_should_return_api_handling_messages_from_this_queue_name()
        {
            var(configuration, serviceProvider) =
                ConfigurationTests.CreateBrokerIngressConfigurationWithTwoApisHandlingMessageFromDifferentQueues();
            var ingress = new BrokerIngress(
                Mock.Of <IMessageBroker>(),
                configuration,
                serviceProvider);

            ingress.Initialize();

            ingress.GetApiByQueueName("queue1").Id.Should().Be("api1", "api1 configured to handle messages from queue1");
            ingress.GetApiByQueueName("queue2").Id.Should().Be("api2", "api2 configured to handle messages from queue2");
        }
Esempio n. 3
0
        public void when_start_consume_messages_without_queue_names_it_should_fail()
        {
            var configuration = ConfigurationTests.CreateBrokerIngressConfiguration();
            var ingress       = new BrokerIngress(
                Mock.Of <IMessageBroker>(),
                configuration,
                Mock.Of <IDiContainerAdapter>());

            ingress.Initialize();

            Action sut = () => ingress.StartConsumeMessages(queueNamePatterns: null);

            sut.Should().ThrowExactly <ArgumentNullException>().Which.ParamName.Should().Be("queueNamePatterns");
        }
Esempio n. 4
0
        public void when_get_api_by_queue_name_and_a_few_apis_handle_messages_from_same_queue_it_should_fail()
        {
            var(configuration, serviceProvider) = ConfigurationTests.CreateBrokerIngressConfigurationWithTwoApisHandlingMessageFromAnyQueue();
            var ingress = new BrokerIngress(
                Mock.Of <IMessageBroker>(),
                configuration,
                serviceProvider);

            ingress.Initialize();

            const string queueName = "queue-name";
            Action       sut       = () => ingress.GetApiByQueueName(queueName);

            sut.Should().ThrowExactly <PoezdOperationException>().Which.Message.Should().Contain("belongs to a few APIs");
            sut.Should().ThrowExactly <PoezdOperationException>().Which.Message.Should().Contain(queueName);
        }
Esempio n. 5
0
        public void when_initialized_twice_it_should_fail()
        {
            var configuration       = ConfigurationTests.CreateBrokerIngressConfiguration();
            var serviceProviderMock = new Mock <IDiContainerAdapter>();

            serviceProviderMock.Setup(adapter => adapter.GetService(typeof(EmptyPipeFitter))).Returns(() => new EmptyPipeFitter());

            var ingress = new BrokerIngress(
                Mock.Of <IMessageBroker>(),
                configuration,
                serviceProviderMock.Object);

            Action sut = () => ingress.Initialize();

            sut.Should().NotThrow();
            sut.Should().ThrowExactly <PoezdOperationException>().Which.Message.Should().Contain(
                "already initialized",
                "it should not be possible to initialize ingress more than once");
        }
Esempio n. 6
0
        public void when_start_consume_messages_it_should_start_consume_messages_from_underlying_driver()
        {
            var driverMock = new Mock <IBrokerIngressDriver>();
            var driverStartConsumeMessagesCalled = false;

            driverMock.Setup(driver => driver.StartConsumeMessages(It.IsAny <IEnumerable <string> >(), CancellationToken.None))
            .Callback(() => driverStartConsumeMessagesCalled = true)
            .Returns(Task.CompletedTask);

            var configuration = ConfigurationTests.CreateBrokerIngressConfiguration()
                                .With(ingressConfiguration => ingressConfiguration.Driver = driverMock.Object);
            var ingress = new BrokerIngress(
                Mock.Of <IMessageBroker>(),
                configuration,
                Mock.Of <IDiContainerAdapter>());

            ingress.Initialize();

            ingress.StartConsumeMessages(new[] { "queue name" });

            driverStartConsumeMessagesCalled.Should().BeTrue("broker ingress should start message consumption on driver");
        }