Example #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));
        }
Example #2
0
        public void UnmappedMessageType_ShouldThrowDetailedException()
        {
            MessageMapper.MapMessageTypesToHandlers(new [] { typeof(TestSubscriber.PatLiteTestHandler).Assembly });

            Assert.Throws <UnmappedMessageTypeException>(() =>
                                                         MessageMapper.GetHandlerForMessageType("Invalid.Type, AssemblyNameHere"));
        }