예제 #1
0
 public void PostComment()
 {
     Comment comment = new Comment()
     {
         Author = "Scott",
         Email = "*****@*****.**",
         Text = "I love ASP.NET Web API!"
     };
     HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost");
     ICommentRepository repository = new InitialData();
     CommentsController controller = new CommentsController(repository) { Request = request };
     HttpResponseMessage<Comment> response = controller.PostComment(comment);
     Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
     Assert.IsNotNull(response.Headers.Location);
     Comment postedComment = response.Content.ReadAsync().Result;
     Assert.IsTrue(repository.TryGet(postedComment.ID, out postedComment));
 }
예제 #2
0
 public void PostComment()
 {
     Comment comment = new Comment()
     {
         Author = "Dan",
         Email = "*****@*****.**",
         Text = "I love ASP.NET Web API!"
     };
     HttpConfiguration config = new HttpConfiguration();
     WebApiConfig.Register(config);
     HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost");
     request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;
     ICommentRepository repository = new InitialData();
     CommentsController controller = new CommentsController(repository) { Request = request };
     HttpResponseMessage response = controller.PostComment(comment);
     Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
     Assert.IsNotNull(response.Headers.Location);
     Comment postedComment = response.Content.ReadAsAsync<Comment>().Result;
     Assert.IsTrue(repository.TryGet(postedComment.ID, out postedComment));
 }