public void GetHandlersReturnHandlerForGivenMessageType()
        {
            IEnumerable <Type> MessageHandlerTypes()
            {
                return(new []
                {
                    typeof(HandlerA),
                    typeof(HandlerB),
                    typeof(NotAHandler)
                });
            }

            var sut = new MessageHandlerRegistry(MessageHandlerTypes);
            var sp  = A.Fake <IServiceProvider>();

            A.CallTo(() => sp.GetService(A <Type> .That.IsEqualTo(typeof(HandlerA)))).Returns(new HandlerA());
            var scope = A.Fake <IServiceScope>();

            A.CallTo(() => scope.ServiceProvider).Returns(sp);

            var handlers = sut.GetHandlers(typeof(MessageA), scope).ToList();

            Assert.NotEmpty(handlers);
            Assert.Single(handlers);
            Assert.Single(handlers, h => h is HandlerA);
        }
예제 #2
0
        public void GetHandlersDoesNotReturnHandlerForGivenMessageTypeIfHandlerIsntARealHandler()
        {
            IEnumerable <Type> MessageHandlerTypes()
            {
                return(new[]
                {
                    typeof(HandlerB),
                    typeof(NotAHandler)
                });
            }

            var sut = new MessageHandlerRegistry(MessageHandlerTypes);
            var sp  = A.Fake <IServiceProvider>();

            A.CallTo(() => sp.GetService(A <Type> .That.IsEqualTo(typeof(NotAHandler)))).Returns(new NotAHandler());

            var scope = A.Fake <IServiceScope>();

            A.CallTo(() => scope.ServiceProvider).Returns(sp);
            var scopeFactory = A.Fake <IServiceScopeFactory>();

            A.CallTo(() => scopeFactory.CreateScope()).Returns(scope);

            var handlers = sut.GetHandlers(scopeFactory, typeof(MessageA)).ToList();

            Assert.Empty(handlers);
        }