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>()); }
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>()); }
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>()); }
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); }
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); }
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)); }
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>()); }
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); }
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); }
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)); }