public void when_add_null_as_broker_it_should_fail() { var configuration = ConfigurationTests.CreateMessageRouterConfiguration(); Action sut = () => configuration.AddBroker(configuration: null); sut.Should().ThrowExactly <ArgumentNullException>(); }
public void when_initialize_it_should_initialize_driver() { var configuration = ConfigurationTests.CreateBrokerEgressConfiguration(); var driverMock = new Mock <IBrokerEgressDriver>(); driverMock .Setup( driver => driver.Initialize( It.IsAny <IEnumerable <IEgressApi> >(), 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 BrokerEgress( configuration, serviceProviderMock.Object); sut.Initialize(); driverMock.Verify(); }
public void when_validating_and_driver_configuration_contains_errors_it_should_fail() { var sut = ConfigurationTests.CreateBrokerEgressConfiguration(); const string expectedError = "broken driver configuration"; ((TestBrokerEgressDriverConfiguration)sut.DriverConfiguration).ErrorToReport = expectedError; sut.Validate().Should().HaveCount(expected: 1).And.Contain(expectedError, "driver configuration errors should be reported"); }
public void when_constructed_with_invalid_configuration_it_should_fail() { var egressConfiguration = ConfigurationTests.CreateBrokerEgressConfiguration().With(configuration => configuration.Driver = null); var serviceProvider = Mock.Of <IDiContainerAdapter>(); Action sut = () => new BrokerEgress( egressConfiguration, serviceProvider); sut.Should().ThrowExactly <ArgumentNullException>().Where(exception => exception.ParamName.Equals("configuration.Driver")); }
public void when_start_consume_messages_on_uninitialized_ingress_it_should_fail() { var configuration = ConfigurationTests.CreateBrokerIngressConfiguration(); var ingress = new BrokerIngress( Mock.Of <IMessageBroker>(), configuration, Mock.Of <IDiContainerAdapter>()); Action sut = () => ingress.StartConsumeMessages(new[] { "queue name" }); sut.Should().ThrowExactly <PoezdOperationException>().Which.Message.Should().Contain("not initialized"); }
public void when_some_required_property_not_set_it_should_be_not_validated() { ConfigurationTests.CreateEgressApiConfiguration().With(configuration => configuration.Id = null) .Validate().Should().HaveCount(expected: 1); ConfigurationTests.CreateEgressApiConfiguration().With(configuration => configuration.PipeFitterType = null) .Validate().Should().HaveCount(expected: 1); ConfigurationTests.CreateEgressApiConfiguration().With(configuration => configuration.MessageTypesRegistryType = null) .Validate().Should().HaveCount(expected: 1); ConfigurationTests.CreateIngressApiConfiguration().With(configuration => configuration.MessageKeyType = null) .Validate().Should().HaveCount(expected: 1); ConfigurationTests.CreateIngressApiConfiguration().With(configuration => configuration.MessagePayloadType = null) .Validate().Should().HaveCount(expected: 1); }
public void when_some_required_property_not_set_it_should_be_not_validated() { ConfigurationTests.CreateBrokerEgressConfiguration().With(configuration => configuration.Driver = null) .Validate().Should().HaveCount(expected: 1); ConfigurationTests.CreateBrokerEgressConfiguration().With(configuration => configuration.DriverConfiguration = null) .Validate().Should().HaveCount(expected: 1); ConfigurationTests.CreateBrokerEgressConfiguration().With(configuration => configuration.EnterPipeFitterType = null) .Validate().Should().HaveCount(expected: 1); ConfigurationTests.CreateBrokerEgressConfiguration().With(configuration => configuration.ExitPipeFitterType = null) .Validate().Should().HaveCount(expected: 1); ConfigurationTests.CreateBrokerEgressConfiguration(shouldAddApis: false) .Validate().Should().HaveCount(expected: 1); }
public void when_some_required_property_not_set_it_should_be_not_validated() { ConfigurationTests.CreateMessageBrokerConfiguration().With(configuration => configuration.Id = null) .Validate().Should().HaveCount(expected: 1); Action sutIngress = () => ConfigurationTests.CreateMessageBrokerConfiguration().Ingress = null; sutIngress.Should().ThrowExactly <ArgumentNullException>().Where(exception => exception.ParamName.Equals("value")); Action sutEgress = () => ConfigurationTests.CreateMessageBrokerConfiguration().Egress = null; sutEgress.Should().ThrowExactly <ArgumentNullException>().Where(exception => exception.ParamName.Equals("value")); }
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"); }
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"); }
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); }
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"); }
public void when_constructed_with_invalid_pipe_fitters_in_configuration_it_should_fail() { var configuration = ConfigurationTests.CreateBrokerEgressConfiguration(); configuration.EnterPipeFitterType = typeof(IPipeFitter); configuration.ExitPipeFitterType = typeof(IPipeFitter); var serviceProviderMock = new Mock <IDiContainerAdapter>(); serviceProviderMock.Setup(adapter => adapter.GetService(It.IsAny <Type>())).Throws <InvalidOperationException>(); Action sut = () => new BrokerEgress( configuration, serviceProviderMock.Object); configuration.EnterPipeFitterType = typeof(object); sut.Should().ThrowExactly <PoezdConfigurationException>().Where(exception => exception.Message.Contains(typeof(object).FullName)); configuration.ExitPipeFitterType = typeof(IPipeFitter); configuration.ExitPipeFitterType = typeof(object); sut.Should().ThrowExactly <PoezdConfigurationException>().Where(exception => exception.Message.Contains(typeof(object).FullName)); }
public void when_constructed_it_should_initialize_properties() { var configuration = ConfigurationTests.CreateBrokerEgressConfiguration(); configuration.EnterPipeFitterType = typeof(EmptyPipeFitter); configuration.ExitPipeFitterType = typeof(EmptyPipeFitter); var serviceProviderMock = new Mock <IDiContainerAdapter>(); serviceProviderMock.Setup(adapter => adapter.GetService(typeof(EmptyPipeFitter))).Returns(() => new EmptyPipeFitter()); var sut = new BrokerEgress( configuration, serviceProviderMock.Object); sut.Configuration.Should().BeSameAs(configuration); sut.Configuration.Driver.Should().BeSameAs(configuration.Driver); sut.EnterPipeFitter.Should().BeOfType <EmptyPipeFitter>(); sut.ExitPipeFitter.Should().BeOfType <EmptyPipeFitter>(); sut.Apis.Should().HaveCount(expected: 1); }
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"); }
public void when_publish_it_should_publish_to_driver() { var configuration = ConfigurationTests.CreateBrokerEgressConfiguration(); var driverMock = new Mock <IBrokerEgressDriver>(); driverMock .Setup(driver => driver.Publish(It.IsAny <MessagePublishingContext>(), It.IsAny <CancellationToken>())) .Verifiable(); configuration.Driver = driverMock.Object; var serviceProviderMock = new Mock <IDiContainerAdapter>(); serviceProviderMock.Setup(adapter => adapter.GetService(typeof(EmptyPipeFitter))).Returns(() => new EmptyPipeFitter()); var sut = new BrokerEgress( configuration, serviceProviderMock.Object); sut.Publish(new MessagePublishingContext(), CancellationToken.None); driverMock.Verify(); }
public void when_all_required_properties_set_it_should_be_validated() { var sut = ConfigurationTests.CreateBrokerIngressConfiguration(); sut.Validate().Should().NotBeNull().And.Subject.Should().BeEmpty("there is no errors in the configuration"); }