Exemplo n.º 1
0
        /// <summary>
        /// Creates relevant subscriptions.
        /// </summary>
        /// <param name="handlerAssemblies">Assemblies containing handles, defaults to <code>Assembly.GetCallingAssembly()</code></param>
        public async Task <bool> Initialise(Assembly[] handlerAssemblies, CustomMessageTypeMap[] customMethodMap = null)
        {
            if (handlerAssemblies == null || handlerAssemblies.Length == 0)
            {
                throw new ArgumentException("One or more assemblies required", nameof(handlerAssemblies));
            }

            MessageMapper.MapMessageTypesToHandlers(handlerAssemblies);

            var messagesTypes = ConfigureMessageTypes(customMethodMap);

            string handlerName = null;

            if (messagesTypes.Length == 0)
            {
                _log.LogWarning("Subscriber does not handle any message types");
            }
            else
            {
                var handler = MessageMapper.GetHandlerForMessageType(messagesTypes.First()).HandlerType;
                handlerName = handler.FullName;
            }

            _subscriptionBuilder.WithRuleVersionResolver(handlerAssemblies);
            return(await _subscriptionBuilder.Build(messagesTypes, handlerName).ConfigureAwait(false));
        }
Exemplo n.º 2
0
        public void UnmappedMessageType_ShouldThrowDetailedException()
        {
            MessageMapper.MapMessageTypesToHandlers(new [] { typeof(TestSubscriber.PatLiteTestHandler).Assembly });

            Assert.Throws <UnmappedMessageTypeException>(() =>
                                                         MessageMapper.GetHandlerForMessageType("Invalid.Type, AssemblyNameHere"));
        }
        public virtual MessageTypeMapping GetHandlerForMessageType(Message message)
        {
            var messageTypeString     = message.UserProperties["MessageType"].ToString();
            var handlerForMessageType = MessageMapper.GetHandlerForMessageType(messageTypeString);

            return(handlerForMessageType);
        }
        public async void Intiialise_Configures_CustomMessageTypes_In_MessageMapper()
        {
            var customMessageTypeMap =
                new CustomMessageTypeMap("TestType", typeof(FakeMessage), typeof(FakeHandler));

            var customMessageTypeMaps = new[] { customMessageTypeMap };
            var assemblies            = new[] { Assembly.GetCallingAssembly() };


            await _subscriber.Initialise(assemblies, customMessageTypeMaps);

            var actual = MessageMapper.GetHandlerForMessageType(customMessageTypeMap.MessageType);

            Assert.Equal(customMessageTypeMap.MappedMessageType, actual.MessageType);
            Assert.Equal(customMessageTypeMap.HandlerType, actual.HandlerType);
        }