public void ControlerShouldPutUpdateFirstArticle() { var _articlesController = new ArticlesController(articleService) { Configuration = new HttpConfiguration(), Request = new HttpRequestMessage { Method = HttpMethod.Put, RequestUri = new Uri("http://localhost/api/articles/1") } }; IHttpActionResult updateResult = _articlesController.PutArticle(1, new Article() { ID = 1, Title = "ASP.NET Web API feat. OData", URL = "http://t.co/fuIbNoc7Zh", Contents = @"OData is an open standard protocol.." }) as IHttpActionResult; Assert.That(updateResult, Is.TypeOf <StatusCodeResult>()); StatusCodeResult statusCodeResult = updateResult as StatusCodeResult; Assert.That(statusCodeResult.StatusCode, Is.EqualTo(HttpStatusCode.NoContent)); Assert.That(randomArticles.First().URL, Is.EqualTo("http://t.co/fuIbNoc7Zh")); }
public void ControlerShouldPutReturnBadRequestResult() { var articlesController = new ArticlesController(articleService) { Configuration = new HttpConfiguration(), Request = new HttpRequestMessage { Method = HttpMethod.Put, RequestUri = new Uri("http://localhost/api/articles/-1") } }; var badResult = articlesController.PutArticle(-1, new Article { Title = "Unknown Article" }); Assert.That(badResult, Is.TypeOf <BadRequestResult>()); }