Exemple #1
0
        /// <summary>
        /// Creates the configuration object.
        /// </summary>
        internal InitializableEndpoint Build()
        {
            if (scannedTypes == null)
            {
                var directoryToScan = AppDomain.CurrentDomain.BaseDirectory;
                if (HttpRuntime.AppDomainAppId != null)
                {
                    directoryToScan = HttpRuntime.BinDirectory;
                }

                scannedTypes = GetAllowedTypes(directoryToScan);
            }
            else
            {
                scannedTypes = scannedTypes.Union(GetAllowedCoreTypes()).ToList();
            }

            Settings.SetDefault("TypesToScan", scannedTypes);
            ActivateAndInvoke <INeedInitialization>(scannedTypes, t => t.Customize(this));

            UseTransportExtensions.EnsureTransportConfigured(this);
            var container = customBuilder ?? new AutofacObjectBuilder();

            var conventions = conventionsBuilder.Conventions;

            Settings.SetDefault <Conventions>(conventions);
            var messageMetadataRegistry = new MessageMetadataRegistry(conventions);

            messageMetadataRegistry.RegisterMessageTypesFoundIn(Settings.GetAvailableTypes());

            Settings.SetDefault <MessageMetadataRegistry>(messageMetadataRegistry);

            return(new InitializableEndpoint(Settings, container, registrations, Pipeline, pipelineCollection));
        }
        static SendConnector InitializeBehavior(FakeRouter router = null)
        {
            var metadataRegistry = new MessageMetadataRegistry(new Conventions().IsMessageType);

            metadataRegistry.RegisterMessageTypesFoundIn(new List <Type>
            {
                typeof(MyMessage),
                typeof(MessageWithoutRouting)
            });

            return(new SendConnector(router ?? new FakeRouter()));
        }
            public void Should_match_types_from_a_different_assembly(string typeName)
            {
                var defaultMessageRegistry = new MessageMetadataRegistry(new Conventions().IsMessageType);

                defaultMessageRegistry.RegisterMessageTypesFoundIn(new List <Type> {
                    typeof(MyEvent)
                });

                var messageMetadata = defaultMessageRegistry.GetMessageMetadata(typeName);

                Assert.AreEqual(typeof(MyEvent), messageMetadata.MessageHierarchy.ToList()[0]);
            }
            public void Should_return_metadata_for_a_mapped_type()
            {
                var defaultMessageRegistry = new MessageMetadataRegistry(type => type == typeof(int));

                defaultMessageRegistry.RegisterMessageTypesFoundIn(new List <Type> {
                    typeof(int)
                });

                var messageMetadata = defaultMessageRegistry.GetMessageMetadata(typeof(int));

                Assert.AreEqual(typeof(int), messageMetadata.MessageType);
                Assert.AreEqual(1, messageMetadata.MessageHierarchy.Count());
            }
            public void Should_return_metadata_for_a_mapped_type()
            {
                var conventions = new Conventions();
                conventions.IsMessageTypeAction = type => type == typeof(int);

                var defaultMessageRegistry = new MessageMetadataRegistry(conventions);
                defaultMessageRegistry.RegisterMessageTypesFoundIn(new List<Type> { typeof(int) });

                var messageMetadata = defaultMessageRegistry.GetMessageMetadata(typeof(int));

                Assert.AreEqual(typeof(int), messageMetadata.MessageType);
                Assert.AreEqual(1, messageMetadata.MessageHierarchy.Count());
            }
Exemple #6
0
        static UnicastSendRouterConnector InitializeBehavior(
            string sharedQueue           = null,
            string instanceSpecificQueue = null,
            FakeSendRouter router        = null)
        {
            var metadataRegistry = new MessageMetadataRegistry(new Conventions());

            metadataRegistry.RegisterMessageTypesFoundIn(new List <Type> {
                typeof(MyMessage), typeof(MessageWithoutRouting)
            });

            return(new UnicastSendRouterConnector(sharedQueue, instanceSpecificQueue, router ?? new FakeSendRouter(), new DistributionPolicy(), e => e.ToString()));
        }
            public void Should_return_the_correct_parent_hierarchy()
            {
                var defaultMessageRegistry = new MessageMetadataRegistry(new Conventions());

                defaultMessageRegistry.RegisterMessageTypesFoundIn(new List<Type> { typeof(MyEvent) });
                var messageMetadata = defaultMessageRegistry.GetMessageMetadata(typeof(MyEvent));

                Assert.AreEqual(5, messageMetadata.MessageHierarchy.Count());

                Assert.AreEqual(typeof(MyEvent), messageMetadata.MessageHierarchy.ToList()[0]);
                Assert.AreEqual(typeof(InterfaceParent1), messageMetadata.MessageHierarchy.ToList()[1]);
                Assert.AreEqual(typeof(ConcreteParent1), messageMetadata.MessageHierarchy.ToList()[2]);
                Assert.AreEqual(typeof(InterfaceParent1Base), messageMetadata.MessageHierarchy.ToList()[3]);
                Assert.AreEqual(typeof(ConcreteParentBase), messageMetadata.MessageHierarchy.ToList()[4]);

            }
Exemple #8
0
        static void ConfigureMessageTypes(Conventions conventions, SettingsHolder settings)
        {
            var messageMetadataRegistry = new MessageMetadataRegistry(conventions.IsMessageType);

            messageMetadataRegistry.RegisterMessageTypesFoundIn(settings.GetAvailableTypes());

            settings.Set(messageMetadataRegistry);

            var foundMessages = messageMetadataRegistry.GetAllMessages().ToList();

            settings.AddStartupDiagnosticsSection("Messages", new
            {
                CustomConventionUsed           = conventions.CustomMessageTypeConventionUsed,
                NumberOfMessagesFoundAtStartup = foundMessages.Count,
                Messages = foundMessages.Select(m => m.MessageType.FullName)
            });
        }
            public void Should_return_the_correct_parent_hierarchy()
            {
                var defaultMessageRegistry = new MessageMetadataRegistry(new Conventions().IsMessageType);

                defaultMessageRegistry.RegisterMessageTypesFoundIn(new List <Type> {
                    typeof(MyEvent)
                });
                var messageMetadata = defaultMessageRegistry.GetMessageMetadata(typeof(MyEvent));

                Assert.AreEqual(5, messageMetadata.MessageHierarchy.Count());

                Assert.AreEqual(typeof(MyEvent), messageMetadata.MessageHierarchy.ToList()[0]);
                Assert.AreEqual(typeof(InterfaceParent1), messageMetadata.MessageHierarchy.ToList()[1]);
                Assert.AreEqual(typeof(ConcreteParent1), messageMetadata.MessageHierarchy.ToList()[2]);
                Assert.AreEqual(typeof(InterfaceParent1Base), messageMetadata.MessageHierarchy.ToList()[3]);
                Assert.AreEqual(typeof(ConcreteParentBase), messageMetadata.MessageHierarchy.ToList()[4]);
            }
        public async Task Should_set_content_type_header()
        {
            var registry = new MessageMetadataRegistry(new Conventions());

            registry.RegisterMessageTypesFoundIn(new List<Type>
            {
                typeof(MyMessage)
            });

            var context = new TestableOutgoingLogicalMessageContext();
            context.Message = new OutgoingLogicalMessage(typeof(MyMessage), new MyMessage());

            var behavior = new SerializeMessageConnector(new FakeSerializer("myContentType"), registry);

            await behavior.Invoke(context, c => TaskEx.CompletedTask);

            Assert.AreEqual("myContentType", context.Headers[Headers.ContentType]);
        }
        public async Task Should_set_content_type_header()
        {
            var registry = new MessageMetadataRegistry(new Conventions().IsMessageType);

            registry.RegisterMessageTypesFoundIn(new List <Type>
            {
                typeof(MyMessage)
            });

            var context = new TestableOutgoingLogicalMessageContext();

            context.Message = new OutgoingLogicalMessage(typeof(MyMessage), new MyMessage());

            var behavior = new SerializeMessageConnector(new FakeSerializer("myContentType"), registry);

            await behavior.Invoke(context, c => Task.CompletedTask);

            Assert.AreEqual("myContentType", context.Headers[Headers.ContentType]);
        }
        static UnicastSendRouterConnector InitializeBehavior(
            string sharedQueue = null,
            string instanceSpecificQueue = null,
            FakeSendRouter router = null)
        {
            var metadataRegistry = new MessageMetadataRegistry(new Conventions());
            metadataRegistry.RegisterMessageTypesFoundIn(new List<Type> { typeof(MyMessage), typeof(MessageWithoutRouting) });

            return new UnicastSendRouterConnector(sharedQueue, instanceSpecificQueue, null, router ?? new FakeSendRouter(), new DistributionPolicy(), e => e.ToString());
        }