public static CommentModel ToModel(Comment commentEntity) { CommentModel commentModel = new CommentModel() { Author = commentEntity.Author.DisplayName, PostDate = commentEntity.PostDate, Text = commentEntity.Text }; return commentModel; }
public static Comment ToEntity(CommentModel commentModel, User author) { Comment commentEntity = new Comment() { Author = author, PostDate = DateTime.Now, Text = commentModel.Text }; return commentEntity; }
public void Comment_WhenInvalidComment_ShouldReturn400ErrorResponse() { // Add a post to test PostModel newPost = new PostModel() { Title = "Peshov post", Text = "Pesho posted a new post!!!" }; var createPostResponse = this.httpServer.Post("api/posts", newPost, this.sessionKeyHeader); var postedPost = createPostResponse.Content.ReadAsAsync<PostedPost>().Result; CommentModel testComment = new CommentModel(); var postID = postedPost.ID; var httpResponse = this.httpServer.Put("api/posts/" + postID + "/comment", testComment, this.sessionKeyHeader); Assert.AreEqual(HttpStatusCode.BadRequest, httpResponse.StatusCode); }
public void Comment_WhenPostNotExists_ShouldReturn404ErrorResponse() { CommentModel testComment = new CommentModel() { Text = "Test comment!" }; var httpResponse = this.httpServer.Put("api/posts/" + 11898712 + "/comment", testComment, this.sessionKeyHeader); Assert.AreEqual(HttpStatusCode.NotFound, httpResponse.StatusCode); }
public void Comment_WhenPostExists_ShouldReturn201CodeAndEmptyContent() { // Add a post to test PostModel newPost = new PostModel() { Title = "Peshov post", Text = "Pesho posted a new post!!!" }; var createPostResponse = this.httpServer.Post("api/posts", newPost, this.sessionKeyHeader); var postedPost = createPostResponse.Content.ReadAsAsync<PostedPost>().Result; CommentModel testComment = new CommentModel() { Text = "Test comment!" }; var postID = postedPost.ID; var httpResponse = this.httpServer.Put("api/posts/" + postID + "/comment", testComment, this.sessionKeyHeader); Assert.AreEqual(HttpStatusCode.OK, httpResponse.StatusCode); Assert.IsNull(httpResponse.Content); }