Example #1
0
        /// <inheritdoc />
        public IApiProducer Get(IEgressApi api)
        {
            if (api == null)
            {
                throw new ArgumentNullException(nameof(api));
            }

            if (!_producers.TryGetValue(api, out var producer))
            {
                throw new ArgumentException($"There is no registered producers for API with ID '{api.Id}'.", nameof(api));
            }

            return((IApiProducer)producer);
        }
Example #2
0
        /// <inheritdoc />
        public void Add(IEgressApi api, IApiProducer producer)
        {
            if (api == null)
            {
                throw new ArgumentNullException(nameof(api));
            }
            if (producer == null)
            {
                throw new ArgumentNullException(nameof(producer));
            }

            if (!_producers.TryAdd(api, producer))
            {
                throw new PoezdConfigurationException($"An egress API with ID '{api.Id}' and its producer already registered.");
            }
        }
Example #3
0
        public void when_initializing_with_invalid_arguments_it_should_fail()
        {
            var publishedMessages = new List <MessagePublishingContext>();
            var driver            = new BrokerEgressKafkaDriver(
                ConfigurationTests.CreateBrokerEgressKafkaDriverConfiguration(publishedMessages),
                new Mock <IProducerRegistry>().Object);

            var apis            = new IEgressApi[0];
            var serviceProvider = Mock.Of <IDiContainerAdapter>();

            Action sut = () => driver.Initialize(
                apis,
                serviceProvider);

            apis = null;
            sut.Should().ThrowExactly <ArgumentNullException>()
            .Which.ParamName.Should().Be("apis", "null is an invalid APIs");
            apis = new IEgressApi[0];

            serviceProvider = null;
            sut.Should().ThrowExactly <ArgumentNullException>()
            .Which.ParamName.Should().Be("serviceProvider", "null is an invalid service provider");
        }
            private static Pipeline <MessagePublishingContext> BuildEgressPipeline(IMessageBroker messageBroker, IEgressApi api)
            {
                try
                {
                    var pipeline = new Pipeline <MessagePublishingContext>();
                    messageBroker.Egress.EnterPipeFitter.AppendStepsInto(pipeline);
                    api.PipeFitter.AppendStepsInto(pipeline);
                    messageBroker.Egress.ExitPipeFitter.AppendStepsInto(pipeline);

                    return(pipeline);
                }
                catch (Exception exception)
                {
                    throw new PoezdOperationException(
                              "An error occurred during building an egress pipeline. Inspect the inner exceptions for more details.",
                              exception);
                }
            }