Example #1
0
        public void SetUp()
        {
            LicenseManager.InitializeLicense();
            transportDefinition = new MsmqTransport();

            settings = new SettingsHolder();

            settings.SetDefault("EndpointName", "TestEndpoint");
            settings.SetDefault("Endpoint.SendOnly", false);
            settings.SetDefault("MasterNode.Address", MasterNodeAddress);
            pipelineModifications = new PipelineModifications();
            settings.Set <PipelineModifications>(pipelineModifications);

            ApplyPipelineModifications();

            Transport   = new FakeTransport();
            FuncBuilder = new FuncBuilder();

            FuncBuilder.Register <ReadOnlySettings>(() => settings);

            router = new StaticMessageRouter(KnownMessageTypes());
            var conventions = new Conventions();

            handlerRegistry         = new MessageHandlerRegistry(conventions);
            MessageMetadataRegistry = new MessageMetadataRegistry(false, conventions);
            MessageSerializer       = new XmlMessageSerializer(MessageMapper, conventions);

            messageSender       = MockRepository.GenerateStub <ISendMessages>();
            subscriptionStorage = new FakeSubscriptionStorage();
            configure           = new Configure(settings, FuncBuilder, new List <Action <IConfigureComponents> >(), new PipelineSettings(null))
            {
                localAddress = Address.Parse("TestEndpoint")
            };

            subscriptionManager = new SubscriptionManager
            {
                MessageSender       = messageSender,
                SubscriptionStorage = subscriptionStorage,
                Configure           = configure
            };

            pipelineFactory = new PipelineExecutor(settings, FuncBuilder);

            FuncBuilder.Register <IMessageSerializer>(() => MessageSerializer);
            FuncBuilder.Register <ISendMessages>(() => messageSender);

            FuncBuilder.Register <LogicalMessageFactory>(() => new LogicalMessageFactory(MessageMetadataRegistry, MessageMapper, pipelineFactory));

            FuncBuilder.Register <IManageSubscriptions>(() => subscriptionManager);
            FuncBuilder.Register <EstimatedTimeToSLABreachCalculator>(() => SLABreachCalculator);
            FuncBuilder.Register <MessageMetadataRegistry>(() => MessageMetadataRegistry);

            FuncBuilder.Register <IMessageHandlerRegistry>(() => handlerRegistry);
            FuncBuilder.Register <IMessageMapper>(() => MessageMapper);

            FuncBuilder.Register <DeserializeLogicalMessagesBehavior>(() => new DeserializeLogicalMessagesBehavior
            {
                MessageSerializer       = MessageSerializer,
                MessageMetadataRegistry = MessageMetadataRegistry,
            });

            FuncBuilder.Register <CreatePhysicalMessageBehavior>(() => new CreatePhysicalMessageBehavior());
            FuncBuilder.Register <PipelineExecutor>(() => pipelineFactory);
            FuncBuilder.Register <TransportDefinition>(() => transportDefinition);

            var messagePublisher = new StorageDrivenPublisher
            {
                MessageSender       = messageSender,
                SubscriptionStorage = subscriptionStorage
            };

            var deferrer = new TimeoutManagerDeferrer
            {
                MessageSender         = messageSender,
                TimeoutManagerAddress = MasterNodeAddress.SubScope("Timeouts"),
                Configure             = configure,
            };

            FuncBuilder.Register <IDeferMessages>(() => deferrer);
            FuncBuilder.Register <IPublishMessages>(() => messagePublisher);

            bus = new UnicastBus
            {
                Builder             = FuncBuilder,
                MessageSender       = messageSender,
                Transport           = Transport,
                MessageMapper       = MessageMapper,
                SubscriptionManager = subscriptionManager,
                MessageRouter       = router,
                Settings            = settings,
                Configure           = configure,
                HostInformation     = new HostInformation(Guid.NewGuid(), "HelloWorld")
            };

            FuncBuilder.Register <IMutateOutgoingTransportMessages>(() => new CausationMutator {
                Bus = bus
            });
            FuncBuilder.Register <IBus>(() => bus);
            FuncBuilder.Register <UnicastBus>(() => bus);
            FuncBuilder.Register <Conventions>(() => conventions);
            FuncBuilder.Register <Configure>(() => configure);
        }
        public void SetUp()
        {
            transportDefinition = new Msmq();
            HandlerInvocationCache.Clear();

            SettingsHolder.Reset();
            SettingsHolder.SetDefault("Endpoint.SendOnly", false);

            Transport   = new FakeTransport();
            FuncBuilder = new FuncBuilder();
            Configure.GetEndpointNameAction = () => "TestEndpoint";
            subscriptionPredicatesEvaluator = new SubscriptionPredicatesEvaluator();
            router                  = new StaticMessageRouter(KnownMessageTypes());
            handlerRegistry         = new MessageHandlerRegistry();
            MessageMetadataRegistry = new MessageMetadataRegistry
            {
                DefaultToNonPersistentMessages = false
            };


            MessageSerializer = new XmlMessageSerializer(MessageMapper);
            //ExtensionMethods.GetStaticOutgoingHeadersAction = () => MessageHeaderManager.staticHeaders;
            gatewayAddress = MasterNodeAddress.SubScope("gateway");

            messageSender       = MockRepository.GenerateStub <ISendMessages>();
            subscriptionStorage = new FakeSubscriptionStorage();
            subscriptionManager = new MessageDrivenSubscriptionManager
            {
                Builder             = FuncBuilder,
                MessageSender       = messageSender,
                SubscriptionStorage = subscriptionStorage
            };

            var pipelineBuilder = new PipelineBuilder(FuncBuilder);

            pipelineFactory = new PipelineExecutor(FuncBuilder, pipelineBuilder);

            FuncBuilder.Register <IMessageSerializer>(() => MessageSerializer);
            FuncBuilder.Register <ISendMessages>(() => messageSender);

            FuncBuilder.Register <MessageAuditer>(() => new MessageAuditer());

            FuncBuilder.Register <LogicalMessageFactory>(() => new LogicalMessageFactory());

            FuncBuilder.Register <IMutateIncomingMessages>(() => new FilteringMutator
            {
                SubscriptionPredicatesEvaluator = subscriptionPredicatesEvaluator
            });
            FuncBuilder.Register <IMutateIncomingTransportMessages>(() => subscriptionManager);
            FuncBuilder.Register <EstimatedTimeToSLABreachCalculator>(() => SLABreachCalculator);
            FuncBuilder.Register <MessageMetadataRegistry>(() => MessageMetadataRegistry);

            FuncBuilder.Register <IMessageHandlerRegistry>(() => handlerRegistry);
            FuncBuilder.Register <ExtractIncomingPrincipal>(() => new WindowsImpersonator());
            FuncBuilder.Register <IMessageMapper>(() => MessageMapper);

            FuncBuilder.Register <ExtractLogicalMessagesBehavior>(() => new ExtractLogicalMessagesBehavior
            {
                MessageSerializer       = MessageSerializer,
                MessageMetadataRegistry = MessageMetadataRegistry,
            });
            FuncBuilder.Register <ImpersonateSenderBehavior>(() => new ImpersonateSenderBehavior
            {
                ExtractIncomingPrincipal = MockRepository.GenerateStub <ExtractIncomingPrincipal>()
            });

            FuncBuilder.Register <CreatePhysicalMessageBehavior>(() => new CreatePhysicalMessageBehavior());
            FuncBuilder.Register <PipelineBuilder>(() => pipelineBuilder);
            FuncBuilder.Register <PipelineExecutor>(() => pipelineFactory);
            FuncBuilder.Register <TransportDefinition>(() => transportDefinition);


            var messagePublisher = new StorageDrivenPublisher
            {
                MessageSender       = messageSender,
                SubscriptionStorage = subscriptionStorage
            };

            var deferrer = new TimeoutManagerDeferrer
            {
                MessageSender         = messageSender,
                TimeoutManagerAddress = MasterNodeAddress.SubScope("Timeouts")
            };

            FuncBuilder.Register <IDeferMessages>(() => deferrer);
            FuncBuilder.Register <IPublishMessages>(() => messagePublisher);

            unicastBus = new UnicastBus
            {
                MasterNodeAddress               = MasterNodeAddress,
                Builder                         = FuncBuilder,
                MessageSender                   = messageSender,
                Transport                       = Transport,
                MessageMapper                   = MessageMapper,
                SubscriptionManager             = subscriptionManager,
                SubscriptionPredicatesEvaluator = subscriptionPredicatesEvaluator,
                MessageRouter                   = router
            };
            bus = unicastBus;

            FuncBuilder.Register <IMutateOutgoingTransportMessages>(() => new CausationMutator {
                Bus = bus
            });
            FuncBuilder.Register <IBus>(() => bus);
            FuncBuilder.Register <UnicastBus>(() => unicastBus);
            new HeaderBootstrapper
            {
                Builder = FuncBuilder
            }.SetupHeaderActions();
        }