Esempio n. 1
0
        public void EmptyMapReturnsNullHandlers()
        {
            var map = new HandlerMap();

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

            Assert.That(handlers, Is.Null);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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));
        }
Esempio n. 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));
        }