public static BrokerEgressConfiguration With( this BrokerEgressConfiguration configuration, Action <BrokerEgressConfiguration> updater) { updater(configuration); return(configuration); }
public void when_add_null_as_api_it_should_fail() { var configuration = new BrokerEgressConfiguration(); Action sut = () => configuration.AddApi(configuration: null); sut.Should().ThrowExactly <ArgumentNullException>(); }
public void when_set_kafka_driver_without_configurator_it_should_fail() { var configuration = new BrokerEgressConfiguration(); var configurator = new BrokerEgressConfigurator(configuration); Action sut = () => configurator.WithKafkaDriver(configurator: null); sut.Should().ThrowExactly <ArgumentNullException>(); }
public void when_exit_pipe_fitter_set_it_should_be_set_in_configuration() { var configuration = new BrokerEgressConfiguration(); var sut = new BrokerEgressConfigurator(configuration); sut.WithExitPipeFitter <StabPipeFitter>().Should().BeSameAs(sut); configuration.ExitPipeFitterType.Should().Be <StabPipeFitter>(); }
public void when_same_api_added_second_time_it_should_fail() { var configuration = new BrokerEgressConfiguration(); var api = new EgressApiConfiguration(); Action sut = () => configuration.AddApi(api); sut.Should().NotThrow(); sut.Should().ThrowExactly <PoezdConfigurationException>(); }
public void when_api_added_it_should_be_added_into_configuration() { var configuration = new BrokerEgressConfiguration(); var sut = new BrokerEgressConfigurator(configuration); var expected = new StringCreator().Get(length: 10); sut.AddApi(api => api.WithId(expected)).Should().BeSameAs(sut); configuration.Apis.Should().HaveCount(expected: 1, "an API should be added") .And.Subject.Single().Id.Should().Be(expected, "it should be added API instance"); }
public void when_exit_pipe_fitter_set_more_than_once_it_should_fail() { var configuration = new BrokerEgressConfiguration(); var configurator = new BrokerEgressConfigurator(configuration); Action sut = () => configurator.WithExitPipeFitter <StabPipeFitter>(); sut.Should().NotThrow(); configuration.ExitPipeFitterType.Should().Be <StabPipeFitter>(); EnsureSecondCallOfConfigurationMethodFails(sut); }
/// <summary> /// Constructs a new instance of message broker egress. /// </summary> /// <param name="configuration"> /// The message broker egress configuration. /// </param> /// <param name="serviceProvider"> /// Service provider. /// </param> public BrokerEgress( [NotNull] BrokerEgressConfiguration configuration, [NotNull] IDiContainerAdapter serviceProvider) { Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); _serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)); Driver = configuration.Driver ?? throw new ArgumentNullException($"{nameof(configuration)}.{nameof(configuration.Driver)}"); Apis = configuration.Apis.Select(api => new EgressApi(api, serviceProvider)).Cast <IEgressApi>().ToList().AsReadOnly(); EnterPipeFitter = GetEnterPipeFitter(serviceProvider); ExitPipeFitter = GetExitPipeFitter(serviceProvider); }
public void when_set_driver_it_should_be_set_driver_and_driver_configuration() { var configuration = new BrokerEgressConfiguration(); var sut = (IBrokerEgressDriverConfigurator) new BrokerEgressConfigurator(configuration); var expectedDriver = Mock.Of <IBrokerEgressDriver>(); var expectedDriverConfiguration = Mock.Of <IMessageRouterConfigurationPart>(); sut.SetDriver(expectedDriver, expectedDriverConfiguration); configuration.Driver.Should().BeSameAs(expectedDriver); configuration.DriverConfiguration.Should().BeSameAs(expectedDriverConfiguration); }
public void when_set_driver_more_than_once_it_should_fail() { var configuration = new BrokerEgressConfiguration(); var configurator = (IBrokerEgressDriverConfigurator) new BrokerEgressConfigurator(configuration); var expectedDriver = Mock.Of <IBrokerEgressDriver>(); var expectedDriverConfiguration = Mock.Of <IMessageRouterConfigurationPart>(); Action sut = () => configurator.SetDriver(expectedDriver, expectedDriverConfiguration); sut.Should().NotThrow(); configuration.Driver.Should().BeSameAs(expectedDriver); configuration.DriverConfiguration.Should().BeSameAs(expectedDriverConfiguration); EnsureSecondCallOfConfigurationMethodFails(sut); }
public void when_broker_egress_configured_with_kafka_driver_it_should_configure_in_expected_way() { var configuration = new BrokerEgressConfiguration(); var configurator = new BrokerEgressConfigurator(configuration); configurator.WithKafkaDriver( driver => driver .WithProducerConfig(new ProducerConfig()) .WithDefaultProducerFactory() .WithHeaderValueCodec <IHeaderValueCodec>() .WithProducerFactory <IApiProducerFactory>() .WithSerializerFactory <ISerializerFactory>()); configuration.Driver.Should().BeOfType <BrokerEgressKafkaDriver>("what it can be else?"); }
public void when_constructed_with_invalid_arguments_it_should_fail() { var configuration = ConfigurationTests.CreateBrokerEgressConfiguration(); var serviceProvider = Mock.Of <IDiContainerAdapter>(); Action sut = () => new BrokerEgress( configuration, serviceProvider); configuration = null; sut.Should().ThrowExactly <ArgumentNullException>().Where(exception => exception.ParamName.Equals("configuration")); configuration = new BrokerEgressConfiguration(); serviceProvider = null; sut.Should().ThrowExactly <ArgumentNullException>().Where(exception => exception.ParamName.Equals("serviceProvider")); }
public static BrokerEgressConfiguration CreateBrokerEgressConfiguration(bool shouldAddApis = true) { var configuration = new BrokerEgressConfiguration { Driver = new TestBrokerEgressDriver(new TestDriverState()), DriverConfiguration = new TestBrokerEgressDriverConfiguration(), EnterPipeFitterType = typeof(object), ExitPipeFitterType = typeof(object) }; if (shouldAddApis) { configuration.AddApi(CreateEgressApiConfiguration()); } return(configuration); }
public void when_api_with_same_id_added_it_should_fail() { var configuration = new BrokerEgressConfiguration(); const string sameId = "same id"; var api1 = new EgressApiConfiguration { Id = sameId }; Action sut1 = () => configuration.AddApi(api1); sut1.Should().NotThrow(); var api2 = new EgressApiConfiguration { Id = sameId }; Action sut2 = () => configuration.AddApi(api2); sut2.Should().ThrowExactly <PoezdConfigurationException>(); }