public void Dispatch_WithCanceledCancellationToken_OperationCanceledExceptionIsSetOnTask() { var nancyContext = new NancyContext { Request = new Request("GET", "/Test", "HTTP") }; var nancyResponse = new Response { StatusCode = HttpStatusCode.OK }; var cancellationToken = new CancellationToken(true); var mockRequestHandler = Substitute.For <IMockProviderRequestHandler>(); var mockAdminRequestHandler = Substitute.For <IMockProviderAdminRequestHandler>(); mockRequestHandler.Handle(nancyContext).Returns(nancyResponse); IRequestDispatcher requestDispatcher = new MockProviderNancyRequestDispatcher(mockRequestHandler, mockAdminRequestHandler); var response = requestDispatcher.Dispatch(nancyContext, cancellationToken); Assert.Equal(typeof(OperationCanceledException), response.Exception.InnerExceptions.First().GetType()); }
public void Dispatch_WithNullNancyContext_ArgumentExceptionIsSetOnTask() { IRequestDispatcher requestDispatcher = new MockProviderNancyRequestDispatcher(null); var response = requestDispatcher.Dispatch(null, CancellationToken.None); Assert.Equal(typeof(ArgumentException), response.Exception.InnerExceptions.First().GetType()); }
public void Dispatch_WithNancyContext_CallsRequestHandlerWithContext() { var nancyContext = new NancyContext { Request = new Request("GET", "/Test", "HTTP") }; var mockRequestHandler = Substitute.For <IMockProviderNancyRequestHandler>(); mockRequestHandler.Handle(nancyContext).Returns(new Response()); IRequestDispatcher requestDispatcher = new MockProviderNancyRequestDispatcher(mockRequestHandler); requestDispatcher.Dispatch(nancyContext, CancellationToken.None); mockRequestHandler.Received(1).Handle(nancyContext); }
public void Dispatch_WithNancyContext_NoExceptionIsSetOnTask() { var nancyContext = new NancyContext { Request = new Request("GET", "/Test", "HTTP") }; var nancyResponse = new Response { StatusCode = HttpStatusCode.OK }; var mockRequestHandler = Substitute.For <IMockProviderNancyRequestHandler>(); mockRequestHandler.Handle(nancyContext).Returns(nancyResponse); IRequestDispatcher requestDispatcher = new MockProviderNancyRequestDispatcher(mockRequestHandler); var response = requestDispatcher.Dispatch(nancyContext, CancellationToken.None); Assert.Null(response.Exception); }
public void Dispatch_WithNancyContext_SetsContextResponse() { var nancyContext = new NancyContext { Request = new Request("GET", "/Test", "HTTP") }; var nancyResponse = new Response { StatusCode = HttpStatusCode.OK }; var mockRequestHandler = Substitute.For <IMockProviderNancyRequestHandler>(); mockRequestHandler.Handle(nancyContext).Returns(nancyResponse); IRequestDispatcher requestDispatcher = new MockProviderNancyRequestDispatcher(mockRequestHandler); requestDispatcher.Dispatch(nancyContext, CancellationToken.None); Assert.Equal(nancyResponse, nancyContext.Response); }