Пример #1
0
        public void AddMessageHandler <T>(Func <IHandlerAsync <T> > futureHandler) where T : Message
        {
            Subscribers.Add(new Subscriber(typeof(T)));

            var handlerFunc = _messageHandlerWrapper.WrapMessageHandler(futureHandler);

            _handlerMap.Add(typeof(T), handlerFunc);
        }
Пример #2
0
        public void HandlerIsNotReturnedForNonMatchingType()
        {
            var map = new HandlerMap();
            map.Add(typeof(GenericMessage), m => Task.FromResult(true));

            var handlers = map.Get(typeof(AnotherGenericMessage));

            Assert.That(handlers, Is.Null);
        }
Пример #3
0
        public void MultipleHandlersForATypeAreSupported()
        {
            Func<Message, Task<bool>> fn1 = m => Task.FromResult(true);
            Func<Message, Task<bool>> fn2 = m => Task.FromResult(true);

            var map = new HandlerMap();
            map.Add(typeof(GenericMessage), fn1);
            map.Add(typeof(GenericMessage), fn2);

            var handlers1 = map.Get(typeof(GenericMessage));

            Assert.That(handlers1, Is.Not.Null);
            Assert.That(handlers1.Count, Is.EqualTo(2));
            Assert.That(handlers1[0], Is.EqualTo(fn1));
            Assert.That(handlers1[1], Is.EqualTo(fn2));

            var handlers2 = map.Get(typeof(AnotherGenericMessage));
            Assert.That(handlers2, Is.Null);
        }
Пример #4
0
        public void HandlerIsReturnedForMatchingType()
        {
            var map = new HandlerMap();
            map.Add(typeof(GenericMessage), m => Task.FromResult(true) );

            var handlers = map.Get(typeof(GenericMessage));

            Assert.That(handlers, Is.Not.Null);
            Assert.That(handlers.Count, Is.EqualTo(1));
        }
Пример #5
0
        public void CorrectHandlerIsReturnedForType()
        {
            Func<Message, Task<bool>> fn1 = m => Task.FromResult(true);
            Func<Message, Task<bool>> fn2 = m => Task.FromResult(true);

            var map = new HandlerMap();
            map.Add(typeof(GenericMessage), fn1);
            map.Add(typeof(AnotherGenericMessage), fn2);

            var handlers1 = map.Get(typeof(GenericMessage));

            Assert.That(handlers1, Is.Not.Null);
            Assert.That(handlers1.Count, Is.EqualTo(1));
            Assert.That(handlers1[0], Is.EqualTo(fn1));

            var handlers2 = map.Get(typeof(AnotherGenericMessage));

            Assert.That(handlers2, Is.Not.Null);
            Assert.That(handlers2.Count, Is.EqualTo(1));
            Assert.That(handlers2[0], Is.EqualTo(fn2));
        }
Пример #6
0
        public void AddMessageHandler <T>(Func <IHandlerAsync <T> > futureHandler) where T : Message
        {
            if (_handlerMap.ContainsKey(typeof(T)))
            {
                throw new NotSupportedException(
                          $"The handler for '{typeof(T)}' messages on this queue has already been registered.");
            }

            Subscribers.Add(new Subscriber(typeof(T)));

            var handlerFunc = _messageHandlerWrapper.WrapMessageHandler(futureHandler);

            _handlerMap.Add(typeof(T), handlerFunc);
        }