Esempio n. 1
0
        public static MockDependencyResolver CreateFor <T>(T service)
        {
            var resolver = new MockDependencyResolver();

            resolver.Register(service);
            return(resolver);
        }
        public WhenProcessingMessages()
        {
            var handler      = new MockPoisonMessageHandler();
            var mockResolver = MockDependencyResolver
                               .CreateFor <IPoisonMessageHandler>(handler);

            DependencyResolverFactory.Register(mockResolver);
            handler.Clear();
        }
        public void WhenResolvingUnknownMessageTypes_ShouldReturnDefaultHandler()
        {
            var dependencies = MockDependencyResolver
                               .Create()
                               .Register <IPoisonMessageHandler>(null);

            var resolver = new MessageHandlerResolver(new[] { typeof(TestMessageHandler) }, dependencies);
            var headers  = new Dictionary <string, string> {
                { EventDataPropertyKeys.MessageType, UnknownMessageType }
            };
            var handler = resolver.GetHandler(headers, "test-message-0");

            Assert.IsType <UnknownTypeMessageHandler>(handler);
        }
        public void WhenResolving_ShouldUseTypeFromMessageHeaders()
        {
            var dependencies = MockDependencyResolver
                               .Create()
                               .Register <IPoisonMessageHandler>(null);

            var resolver = new MessageHandlerResolver(new[] { typeof(TestMessageHandler) }, dependencies);
            var headers  = new Dictionary <string, string>
            {
                { EventDataPropertyKeys.MessageType, RegisteredMessageType },
                { EventDataPropertyKeys.MessageTypeVersion, "1" }
            };
            var handler = resolver.GetHandler(headers, "test-message-0");

            Assert.NotNull(handler);
            Assert.IsType <TestMessageHandler>(handler);
            Assert.Equal("TestMessageHandler", handler.Name);
        }