public void Post_Operation_Returns_CreatedStatusCode() { var httpConfiguration = new HttpConfiguration(); WebApiConfig.Register(httpConfiguration); var httpRouteData = new HttpRouteData(httpConfiguration.Routes["DefaultApi"], new HttpRouteValueDictionary { {"controller", "operations"} }); var controller = new OperationsController(_operationRepository.Object) { Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/operations/") { Properties = { {HttpPropertyKeys.HttpConfigurationKey, httpConfiguration}, {HttpPropertyKeys.HttpRouteDataKey, httpRouteData} } } }; Operation operation = new Operation { Author = new Author() { Name = "oleg" }, Cost = 240, Id = 1, TypeOperation = TypeOperation.Income, Description = "some bla bla" }; var response = controller.Post(operation).Result; StatusCodeResult result = response as StatusCodeResult; Assert.IsNotNull(result); Assert.AreEqual(HttpStatusCode.Created, result.StatusCode); }
public void Post_Operation_Returns_BadRequestStatusCode() { var httpConfiguration = new HttpConfiguration(); WebApiConfig.Register(httpConfiguration); var httpRouteData = new HttpRouteData(httpConfiguration.Routes["DefaultApi"], new HttpRouteValueDictionary { {"controller", "operations"} }); var controller = new OperationsController(_operationRepository.Object) { Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/operations/") { Properties = { {HttpPropertyKeys.HttpConfigurationKey, httpConfiguration}, {HttpPropertyKeys.HttpRouteDataKey, httpRouteData} } } }; Operation operation = new Operation(); controller.ModelState.AddModelError("", "mock error message"); var response = controller.Post(operation); Assert.IsInstanceOf<InvalidModelStateResult>(response.Result); }