예제 #1
0
        public void Register_WithRequestHandlerType_WithUnregisteredHandler_ThrowsNotRegisteredException()
        {
            // Arrange
            var dispatcher = new DIRequestDispatcher(container);

            // Act
            TestDelegate register = () => dispatcher.Register <Request, Response, IRequestHandler <Request, Response> >();

            // Assert
            Assert.That(register, Throws.TypeOf <NotRegisteredException>());
        }
예제 #2
0
        public void Register_WithRequestHandlerDelegate_WithUnserializableRequestType_ThrowsUnserializableTypeException()
        {
            // Arrange
            var dispatcher = new DIRequestDispatcher(container);
            RequestHandlerDelegate <UnserializableRequest, Response> handler = request => response;

            // Act
            TestDelegate register = () => dispatcher.Register(handler);

            // Assert
            Assert.That(register, Throws.TypeOf <UnserializableTypeException>());
        }
예제 #3
0
        public void Register_WithRequestHandler_WithUnserializableResponseType_ThrowsUnserializableTypeException()
        {
            // Arrange
            var dispatcher = new DIRequestDispatcher(container);
            var handler    = new Mock <IRequestHandler <Request, UnserializableResponse> >().Object;

            // Act
            TestDelegate register = () => dispatcher.Register(handler);

            // Assert
            Assert.That(register, Throws.TypeOf <UnserializableTypeException>());
        }
예제 #4
0
        public void Handle_WithHandlerRegistered_CallsHandler()
        {
            // Arrange
            Response ret         = null;
            var      dispatcher  = new DIRequestDispatcher(container);
            var      requestTask = new RequestTask(receiver, request, r => ret = (Response)r, _ => { });

            dispatcher.Register(handler);

            // Act
            dispatcher.Handle(ref requestTask);

            // Assert
            mockHandler.Verify(m => m.Handle(It.IsIn(request)), Times.Once);
        }
예제 #5
0
        public void Register_WithRequestHandlerType_CallsContainerIsRegistered()
        {
            // Arrange
            var dispatcher = new DIRequestDispatcher(container);

            mockContainer
            .Setup(m => m.IsRegistered <IRequestHandler <Request, Response> >())
            .Returns(true);

            // Act
            dispatcher.Register <Request, Response, IRequestHandler <Request, Response> >();

            // Assert
            mockContainer.Verify(m => m.IsRegistered <IRequestHandler <Request, Response> >(), Times.Once);
        }
예제 #6
0
        public void Handle_WithHandlerClassRegistered_ReturnsResponse()
        {
            // Arrange
            Response ret         = null;
            var      dispatcher  = new DIRequestDispatcher(container);
            var      requestTask = new RequestTask(receiver, request, r => ret = (Response)r, _ => { });

            dispatcher.Register(handler);

            // Act
            dispatcher.Handle(ref requestTask);

            // Assert
            Assert.That(ret is Response, Is.True);
            Assert.That(ret, Is.SameAs(response));
        }
예제 #7
0
        public void Handle_WithBaseClassHandlerFunctionRegistered_ThrowsRequestHandlerNotFoundException()
        {
            // Arrange
            Exception ex          = null;
            var       request     = new SubRequest();
            var       dispatcher  = new DIRequestDispatcher(container);
            var       requestTask = new RequestTask(receiver, request, _ => { }, e => ex = e);

            dispatcher.Register <Request, Response>(r => response);

            // Act
            dispatcher.Handle(ref requestTask);

            // Assert
            Assert.That(ex, Is.TypeOf <RequestHandlerNotFoundException>());
        }
예제 #8
0
        public void Handle_WithHandlerFunctionRegistered_CallsHandler()
        {
            // Arrange
            Response ret         = null;
            var      handled     = false;
            var      dispatcher  = new DIRequestDispatcher(container);
            var      requestTask = new RequestTask(receiver, request, r => ret = (Response)r, _ => { });

            dispatcher.Register <Request, Response>(dt => { handled = true; return(response); });

            // Act
            dispatcher.Handle(ref requestTask);

            // Assert
            Assert.That(handled, Is.True);
        }
예제 #9
0
        public void Handle_WithResolvableHandlerClassRegistered_ResolvesFromContainer()
        {
            // Arrange
            Response ret         = null;
            var      dispatcher  = new DIRequestDispatcher(container);
            var      requestTask = new RequestTask(receiver, request, r => ret = (Response)r, _ => { });

            mockContainer.Setup(m => m.IsRegistered <IRequestHandler <Request, Response> >()).Returns(true);
            mockContainer.Setup(m => m.Resolve <IRequestHandler <Request, Response> >()).Returns(handler);
            dispatcher.Register <Request, Response, IRequestHandler <Request, Response> >();

            // Act
            dispatcher.Handle(ref requestTask);

            // Assert
            mockContainer.Verify(m => m.Resolve <IRequestHandler <Request, Response> >(), Times.Once);
        }
예제 #10
0
        public void Handle_WithResolvableHandlerClassRegistered_ReturnsResponse()
        {
            // Arrange
            Response ret         = null;
            var      dispatcher  = new DIRequestDispatcher(container);
            var      requestTask = new RequestTask(receiver, request, r => ret = (Response)r, _ => { });

            mockContainer.Setup(m => m.IsRegistered <IRequestHandler <Request, Response> >()).Returns(true);
            mockContainer.Setup(m => m.Resolve <IRequestHandler <Request, Response> >()).Returns(handler);
            dispatcher.Register <Request, Response, IRequestHandler <Request, Response> >();

            // Act
            dispatcher.Handle(ref requestTask);

            // Assert
            Assert.That(ret is Response, Is.True);
            Assert.That(ret, Is.SameAs(response));
        }