public void Request_Returns_InstanceProvided() { // Arrange HttpStatusCode statusCode = CreateStatusCode(); using (HttpRequestMessage expectedRequest = CreateRequest()) { StatusCodeResult result = new StatusCodeResult(statusCode, expectedRequest); // Act HttpRequestMessage request = result.Request; // Assert Assert.Same(expectedRequest, request); } }
public void StatusCode_Returns_ValueProvided() { // Arrange HttpStatusCode expectedStatusCode = CreateStatusCode(); using (HttpRequestMessage request = CreateRequest()) { StatusCodeResult result = new StatusCodeResult(expectedStatusCode, request); // Act HttpStatusCode statusCode = result.StatusCode; // Assert Assert.Equal(expectedStatusCode, statusCode); } }
public void ExecuteAsync_Returns_CorrectResponse() { // Arrange HttpStatusCode expectedStatusCode = CreateStatusCode(); using (HttpRequestMessage expectedRequest = CreateRequest()) { IHttpActionResult result = new StatusCodeResult(expectedStatusCode, expectedRequest); // Act Task<HttpResponseMessage> task = result.ExecuteAsync(CancellationToken.None); // Assert Assert.NotNull(task); task.WaitUntilCompleted(); using (HttpResponseMessage response = task.Result) { Assert.NotNull(response); Assert.Equal(expectedStatusCode, response.StatusCode); Assert.Same(expectedRequest, response.RequestMessage); } } }
public void Request_ForApiController_Throws_WhenControllerRequestIsNull() { // Arrange HttpStatusCode statusCode = CreateStatusCode(); ApiController controller = CreateController(); Assert.Null(controller.Request); StatusCodeResult result = new StatusCodeResult(statusCode, controller); // Act & Assert InvalidOperationException exception = Assert.Throws<InvalidOperationException>(() => { HttpRequestMessage ignore = result.Request; }, "ApiController.Request must not be null."); }
public void Request_ForApiController_EvaluatesOnce() { // Arrange HttpStatusCode statusCode = CreateStatusCode(); ApiController controller = CreateController(); StatusCodeResult result = new StatusCodeResult(statusCode, controller); using (HttpRequestMessage expectedRequest = CreateRequest()) { controller.Request = expectedRequest; HttpRequestMessage ignore = result.Request; using (HttpRequestMessage otherRequest = CreateRequest()) { controller.Request = otherRequest; // Act HttpRequestMessage request = result.Request; // Assert Assert.Same(expectedRequest, request); } } }