public void MessageHandlerResolverReturnsMessageHandlerInstanceForCustomSubscriptionFilterMessageProperties()
        {
            var subscriptionFilter = new SubscriptionFilter
            {
                MessageProperties = new Dictionary <string, string>
                {
                    { "MessageType", "AL" }
                }
            };

            subscriptionFilter.Build(new(), typeof(AircraftLanded));

            var services = new ServiceCollection();
            var sut      = new MessageHandlerResolver(services);

            sut.SubcribeToMessage <AircraftLanded, AircraftLandedHandler>(subscriptionFilter);
            sut.Initialize();
            var handler = sut.Resolve("AL");

            Assert.NotNull(handler);
            Assert.IsType <AircraftLandedHandler>(handler);

            var messageContext = new MessageContext <AircraftLanded>(new BinaryData("Hello world!"), new object(),
                                                                     new Mock <IMessageBus>().Object);

            typeof(AircraftLandedHandler).GetMethod("HandleAsync").Invoke(handler, new object[] { messageContext });
        }
Exemple #2
0
        public void Initialize()
        {
            _messageHandlers.Clear();

            var resolvedHandlers = MessageHandlerResolver.Resolve();

            AddHandlers(resolvedHandlers);
        }
        public void MessageHandlerResolverReturnsMessageHandlerInstanceForGivenMessageType()
        {
            var services = new ServiceCollection();
            var sut      = new MessageHandlerResolver(services);

            sut.SubcribeToMessage <AircraftTakenOff, AircraftTakenOffHandler>(BuildSubscriptionFilter <AircraftTakenOff>());
            sut.SubcribeToMessage <AircraftLanded, AircraftLandedHandler>(BuildSubscriptionFilter <AircraftLanded>());
            sut.Initialize();
            var handler = sut.Resolve(nameof(AircraftLanded));

            Assert.NotNull(handler);
            Assert.IsType <AircraftLandedHandler>(handler);

            var messageContext = new MessageContext <AircraftLanded>(new BinaryData("Hello world!"), new object(),
                                                                     new Mock <IMessageBus>().Object);

            typeof(AircraftLandedHandler).GetMethod("HandleAsync").Invoke(handler, new object[] { messageContext });
        }
        public void MessageHandlerResolverThrowsIfCannotFindMessageHandler()
        {
            var sut = new MessageHandlerResolver(new ServiceCollection());

            Assert.Throws <MessageHandlerNotFoundException>(() => sut.Resolve("UnknownMessage"));
        }