Exemplo n.º 1
0
        public void CanConfigureColoredConsoleLogging()
        {
            var adapter = new TestContainerAdapter();

            Configure.With(adapter)
            .Logging(l => l.ColoredConsole());

            RebusLoggerFactory.Current.ShouldBeTypeOf <ConsoleLoggerFactory>();
        }
Exemplo n.º 2
0
        public void CanConfigureSerilogLogging()
        {
            var adapter = new TestContainerAdapter();

            Configure.With(adapter)
            .Logging(l => l.Serilog());

            RebusLoggerFactory.Current.ShouldBeOfType <SerilogLoggerFactory>();
        }
Exemplo n.º 3
0
        public void CanConfigureAllTheMongoStuff()
        {
            var adapter = new TestContainerAdapter();

            Configure.With(adapter)
            .Sagas(s => s.StoreInMongoDb(MongoDbFixtureBase.ConnectionString)
                   .SetCollectionName <FirstSagaData>("string_sagas")
                   .SetCollectionName <SecondSagaData>("datetime_sagas"));
        }
Exemplo n.º 4
0
        public void CanConfigureTimeoutManager_External()
        {
            var adapter = new TestContainerAdapter();

            var configurer = Configure.With(adapter)
                             .Timeouts(t => t.UseExternalTimeoutManager());

            configurer.Backbone.StoreTimeouts.ShouldBe(null);
        }
Exemplo n.º 5
0
        public void CanConfigureLog4NetLogging()
        {
            var adapter = new TestContainerAdapter();

            Configure.With(adapter)
            .Logging(l => l.Log4Net());

            RebusLoggerFactory.Current.ShouldBeTypeOf <Log4NetLoggerFactory>();
        }
Exemplo n.º 6
0
        public void CanConfigureTimeoutManager_InternalWithAppConfig()
        {
            var adapter = new TestContainerAdapter();

            var configurer = Configure.With(adapter)
                             .Timeouts(t => t.StoreInSqlServer("someConnectionString", "timeouts"));

            configurer.Backbone.StoreTimeouts.ShouldBeTypeOf <SqlServerTimeoutStorage>();
        }
Exemplo n.º 7
0
        public void NotConfiguringLoggingStillRegistersTheHandlerActivator()
        {
            var adapter = new TestContainerAdapter();

            var configurer = Configure.With(adapter)
                             .Logging(l => l.None())
                             .Serialization(s => s.UseJsonSerializer());

            configurer.Backbone.ActivateHandlers.ShouldNotBe(null);
        }
Exemplo n.º 8
0
        public void CanConfigureEncryptedMsmqTransport()
        {
            var adapter = new TestContainerAdapter();

            Configure.With(adapter)
            .Transport(t => t.UseEncryptedMsmqAndGetConfigurationFromAppConfig());

            adapter.Resolve <ISendMessages>().ShouldBeTypeOf <RijndaelEncryptionTransportDecorator>();
            adapter.Resolve <IReceiveMessages>().ShouldBeTypeOf <RijndaelEncryptionTransportDecorator>();
        }
Exemplo n.º 9
0
        public void CanConfigureJsonSerialization()
        {
            var adapter = new TestContainerAdapter();

            Configure.With(adapter)
            .Serialization(s => s.UseJsonSerializer());

            var registration = adapter.Registrations.Single(r => r.Instance.GetType() == typeof(JsonMessageSerializer));
            var serializer   = (JsonMessageSerializer)registration.Instance;
        }
Exemplo n.º 10
0
        public void CanConfigureEvents()
        {
            var adapter      = new TestContainerAdapter();
            var raisedEvents = new List <string>();
            var unitOfWorkManagerInstanceThatCanBeRecognized = Mock <IUnitOfWorkManager>();

            var configurer = Configure.With(adapter)
                             .Events(e =>
            {
                e.BusStarted += delegate { raisedEvents.Add("bus started"); };

                e.BeforeTransportMessage += delegate { raisedEvents.Add("before transport message"); };
                e.BeforeMessage          += delegate { raisedEvents.Add("before message"); };
                e.AfterMessage           += delegate { raisedEvents.Add("after message"); };
                e.AfterTransportMessage  += delegate { raisedEvents.Add("after transport message"); };

                e.MessageSent   += delegate { raisedEvents.Add("message sent"); };
                e.PoisonMessage += delegate { raisedEvents.Add("poison message"); };

                e.UncorrelatedMessage += delegate { raisedEvents.Add("uncorrelated message"); };

                e.MessageContextEstablished += delegate { raisedEvents.Add("message context established"); };
                e.AddUnitOfWorkManager(unitOfWorkManagerInstanceThatCanBeRecognized);

                e.BusStopped += delegate { raisedEvents.Add("bus stopped"); };
            })
                             .Transport(t => t.UseMsmqAndGetInputQueueNameFromAppConfig());

            var bus    = (IBus)configurer.CreateBus();
            var events = (RebusEvents)bus.Advanced.Events;

            events.RaiseBusStarted(null);
            events.RaiseBeforeTransportMessage(null, null);
            events.RaiseBeforeMessage(null, null);
            events.RaiseAfterMessage(null, null, null);
            events.RaiseAfterTransportMessage(null, null, null);
            events.RaiseMessageSent(null, null, null);
            events.RaisePoisonMessage(null, null, null);
            events.RaiseUncorrelatedMessage(null, null, null);
            events.RaiseMessageContextEstablished(null, null);
            events.RaiseBusStopped(null);

            raisedEvents.ShouldContain("bus started");
            raisedEvents.ShouldContain("before transport message");
            raisedEvents.ShouldContain("before message");
            raisedEvents.ShouldContain("after message");
            raisedEvents.ShouldContain("after transport message");
            raisedEvents.ShouldContain("message sent");
            raisedEvents.ShouldContain("poison message");
            raisedEvents.ShouldContain("uncorrelated message");
            raisedEvents.ShouldContain("message context established");
            raisedEvents.ShouldContain("bus stopped");

            events.UnitOfWorkManagers.ShouldContain(unitOfWorkManagerInstanceThatCanBeRecognized);
        }
Exemplo n.º 11
0
        public void CanConfigureCustomSerialization()
        {
            var adapter = new TestContainerAdapter();

            var serializer = Mock <ISerializeMessages>();

            var configurer = Configure.With(adapter)
                             .Serialization(s => s.Use(serializer));

            configurer.Backbone.SerializeMessages.ShouldBe(serializer);
        }
Exemplo n.º 12
0
        public void CanConfigureDiscovery()
        {
            var adapter = new TestContainerAdapter();

            Configure.With(adapter)
            .DetermineEndpoints(d => d.FromRebusConfigurationSection())
            .Discovery(d =>
            {
                d.Handlers.LoadFrom(Assembly.GetExecutingAssembly());
            });
        }
Exemplo n.º 13
0
        public void CanConfigureJsonSerialization()
        {
            var adapter = new TestContainerAdapter();

            var configurer = Configure.With(adapter)
                             .Serialization(s => s.UseJsonSerializer()
                                            .AddNameResolver(t => null)
                                            .AddTypeResolver(d => null));

            configurer.Backbone.SerializeMessages.ShouldBeTypeOf <JsonMessageSerializer>();
        }
Exemplo n.º 14
0
        public void NotConfiguringLoggingStillRegistersTheHandlerActivator()
        {
            var adapter = new TestContainerAdapter();

            Configure.With(adapter)
            .Logging(l => l.None())
            .Serialization(s => s.UseJsonSerializer());

            adapter.Registrations
            .Count(r => r.ServiceTypes.Contains(typeof(IActivateHandlers)))
            .ShouldBe(1);
        }
Exemplo n.º 15
0
        public void WhenTransportIsConfiguredEverythingElseWillDefaultToSomething()
        {
            var adapter = new TestContainerAdapter();

            Configure.With(adapter)
            .Transport(t => t.UseMsmq("some_input_queue_name", "some_error_queue"))
            .DetermineEndpoints(d => d.FromNServiceBusConfiguration())
            .CreateBus();

            adapter.HasImplementationOf(typeof(IActivateHandlers)).ShouldBe(true);
            adapter.HasImplementationOf(typeof(IStoreSubscriptions)).ShouldBe(true);
            adapter.HasImplementationOf(typeof(IStoreSagaData)).ShouldBe(true);
            adapter.HasImplementationOf(typeof(IInspectHandlerPipeline)).ShouldBe(true);
            adapter.HasImplementationOf(typeof(ISerializeMessages)).ShouldBe(true);
        }
Exemplo n.º 16
0
        public void CanConfigureHandlerOrdering()
        {
            var adapter = new TestContainerAdapter();

            var configurer = Configure.With(adapter)
                             .SpecifyOrderOfHandlers(h => h.First <SomeType>().Then <AnotherType>());

            configurer.Backbone.InspectHandlerPipeline.ShouldBeTypeOf <RearrangeHandlersPipelineInspector>();

            var inspector = (RearrangeHandlersPipelineInspector)configurer.Backbone.InspectHandlerPipeline;
            var order     = inspector.GetOrder();

            order[0].ShouldBe(typeof(SomeType));
            order[1].ShouldBe(typeof(AnotherType));
        }
Exemplo n.º 17
0
        public void CanConfigureHandlerOrdering()
        {
            var adapter = new TestContainerAdapter();

            Configure.With(adapter)
            .SpecifyOrderOfHandlers(h => h.First <SomeType>().Then <AnotherType>());

            var registration = adapter.Registrations.Single(r => r.Instance.GetType() == typeof(RearrangeHandlersPipelineInspector));

            var inspector = (RearrangeHandlersPipelineInspector)registration.Instance;
            var order     = inspector.GetOrder();

            order[0].ShouldBe(typeof(SomeType));
            order[1].ShouldBe(typeof(AnotherType));
        }
Exemplo n.º 18
0
        public void WhenTransportIsConfiguredEverythingElseWillDefaultToSomething()
        {
            var adapter = new TestContainerAdapter();

            var configurer = Configure.With(adapter)
                             .Transport(t => t.UseMsmq("some_input_queue_name", "some_error_queue"));

            configurer.CreateBus();

            configurer.Backbone.ActivateHandlers.ShouldNotBe(null);
            configurer.Backbone.StoreSagaData.ShouldNotBe(null);
            configurer.Backbone.StoreSubscriptions.ShouldNotBe(null);
            configurer.Backbone.InspectHandlerPipeline.ShouldNotBe(null);
            configurer.Backbone.SerializeMessages.ShouldNotBe(null);
            configurer.Backbone.DetermineMessageOwnership.ShouldNotBe(null);
        }
Exemplo n.º 19
0
        public void CanConfigureMsmqTransport()
        {
            var adapter = new TestContainerAdapter();

            var configurer = Configure.With(adapter)
                             .Transport(t => t.UseMsmq("some_input_queue", "some_error_queue"));

            configurer.Backbone.SendMessages.ShouldBeTypeOf <MsmqMessageQueue>();
            configurer.Backbone.ReceiveMessages.ShouldBeTypeOf <MsmqMessageQueue>();

            configurer.Backbone.SendMessages.ShouldBeSameAs(configurer.Backbone.ReceiveMessages);

            var msmqMessageQueue = (MsmqMessageQueue)configurer.Backbone.SendMessages;

            msmqMessageQueue.InputQueue.ShouldBe("some_input_queue");
        }
Exemplo n.º 20
0
        public void CanConfigureMsmqTransportFromRebusConfigurationSection()
        {
            var adapter = new TestContainerAdapter();

            var configurer = Configure.With(adapter)
                             .Transport(t => t.UseMsmqAndGetInputQueueNameFromAppConfig());

            configurer.Backbone.SendMessages.ShouldBeTypeOf <MsmqMessageQueue>();
            configurer.Backbone.ReceiveMessages.ShouldBeTypeOf <MsmqMessageQueue>();

            configurer.Backbone.SendMessages.ShouldBeSameAs(configurer.Backbone.ReceiveMessages);

            var msmqMessageQueue = (MsmqMessageQueue)configurer.Backbone.SendMessages;

            msmqMessageQueue.InputQueue.ShouldBe("this.is.my.input.queue");
        }
Exemplo n.º 21
0
        public void CanConfigureMsmqTransportFromRebusConfigurationSection()
        {
            var adapter = new TestContainerAdapter();

            Configure.With(adapter)
            .Transport(t => t.UseMsmqAndGetInputQueueNameFromAppConfig());

            var registrations = adapter.Registrations
                                .Where(r => r.Instance.GetType() == typeof(MsmqMessageQueue))
                                .ToList();

            registrations.Count.ShouldBe(2);

            var msmqMessageQueue = (MsmqMessageQueue)registrations.First().Instance;

            msmqMessageQueue.InputQueue.ShouldBe("this.is.my.input.queue");
        }
Exemplo n.º 22
0
        public void CanConfigureMsmqTransport()
        {
            var adapter = new TestContainerAdapter();

            Configure.With(adapter)
            .Transport(t => t.UseMsmq("some_input_queue", "some_error_queue"));

            var registrations = adapter.Registrations
                                .Where(r => r.Instance.GetType() == typeof(MsmqMessageQueue))
                                .ToList();

            registrations.Count.ShouldBe(2);

            var msmqMessageQueue = (MsmqMessageQueue)registrations.First().Instance;

            msmqMessageQueue.InputQueue.ShouldBe("some_input_queue");
        }
Exemplo n.º 23
0
        public void CanConfigureEndpointMapperWithFilter()
        {
            var adapter = new TestContainerAdapter();

            var backboneWithoutFilter =
                (DetermineMessageOwnershipFromRebusConfigurationSection)
                Configure.With(adapter)
                .MessageOwnership(d => d.FromRebusConfigurationSection())
                .Backbone.DetermineMessageOwnership;

            var backboneWithFilter =
                (DetermineMessageOwnershipFromRebusConfigurationSection)
                Configure.With(adapter)
                .MessageOwnership(d => d.FromRebusConfigurationSectionWithFilter(f => f == typeof(SomeType)))
                .Backbone.DetermineMessageOwnership;

            Assert.DoesNotThrow(() => backboneWithoutFilter.GetEndpointFor(typeof(SomeType)));

            Assert.DoesNotThrow(() => backboneWithFilter.GetEndpointFor(typeof(SomeType)));
            Assert.Throws <InvalidOperationException>(() => backboneWithFilter.GetEndpointFor(typeof(AnotherType)));
        }
Exemplo n.º 24
0
        public void CanConfigureSqlServerPersistence()
        {
            var adapter = new TestContainerAdapter();

            const string connectionstring = "connectionString";

            Configure.With(adapter)
            .Sagas(s => s.StoreInSqlServer(connectionstring, "saga_table", "saga_index_table"))
            .Subscriptions(s => s.StoreInSqlServer(connectionstring, "subscriptions"));

            var sagaRegistration = adapter.Registrations.Single(r => r.Instance.GetType() == typeof(SqlServerSagaPersister));
            var subRegistration  = adapter.Registrations.Single(r => r.Instance.GetType() == typeof(SqlServerSubscriptionStorage));

            var sagaPersister = (SqlServerSagaPersister)sagaRegistration.Instance;

            sagaPersister.SagaTableName.ShouldBe("saga_table");
            sagaPersister.SagaIndexTableName.ShouldBe("saga_index_table");

            var subscriptionStorage = (SqlServerSubscriptionStorage)subRegistration.Instance;

            subscriptionStorage.SubscriptionsTableName.ShouldBe("subscriptions");
        }
Exemplo n.º 25
0
        public void CanConfigureEvents()
        {
            var adapter      = new TestContainerAdapter();
            var raisedEvents = new List <string>();

            var configurer = Configure.With(adapter)
                             .Events(e =>
            {
                e.BeforeTransportMessage += delegate { raisedEvents.Add("before transport message"); };
                e.BeforeMessage          += delegate { raisedEvents.Add("before message"); };
                e.AfterMessage           += delegate { raisedEvents.Add("after message"); };
                e.AfterTransportMessage  += delegate { raisedEvents.Add("after transport message"); };

                e.MessageSent   += delegate { raisedEvents.Add("message sent"); };
                e.PoisonMessage += delegate { raisedEvents.Add("poison message"); };

                e.UncorrelatedMessage += delegate { raisedEvents.Add("uncorrelated message"); };
            })
                             .Transport(t => t.UseMsmqAndGetInputQueueNameFromAppConfig());

            var bus    = (IAdvancedBus)configurer.CreateBus();
            var events = (RebusEvents)bus.Events;

            events.RaiseBeforeTransportMessage(null, null);
            events.RaiseBeforeMessage(null, null);
            events.RaiseAfterMessage(null, null, null);
            events.RaiseAfterTransportMessage(null, null, null);
            events.RaiseMessageSent(null, null, null);
            events.RaisePoisonMessage(null, null, null);
            events.RaiseUncorrelatedMessage(null, null);

            raisedEvents.ShouldContain("before transport message");
            raisedEvents.ShouldContain("before message");
            raisedEvents.ShouldContain("after message");
            raisedEvents.ShouldContain("after transport message");
            raisedEvents.ShouldContain("message sent");
            raisedEvents.ShouldContain("poison message");
            raisedEvents.ShouldContain("uncorrelated message");
        }
Exemplo n.º 26
0
        public void CanConfigureSqlServerPersistence()
        {
            var adapter = new TestContainerAdapter();

            const string connectionstring = "connectionString";

            var configurer = Configure.With(adapter)
                             .Sagas(s => s.StoreInSqlServer(connectionstring, "saga_table", "saga_index_table"))
                             .Subscriptions(s => s.StoreInSqlServer(connectionstring, "subscriptions"));

            configurer.Backbone.StoreSagaData.ShouldBeTypeOf <SqlServerSagaPersister>();
            configurer.Backbone.StoreSubscriptions.ShouldBeTypeOf <SqlServerSubscriptionStorage>();


            var sagaPersister = (SqlServerSagaPersister)configurer.Backbone.StoreSagaData;

            sagaPersister.SagaTableName.ShouldBe("saga_table");
            sagaPersister.SagaIndexTableName.ShouldBe("saga_index_table");

            var subscriptionStorage = (SqlServerSubscriptionStorage)configurer.Backbone.StoreSubscriptions;

            subscriptionStorage.SubscriptionsTableName.ShouldBe("subscriptions");
        }