public async Task AddComment(DTOComment dtoComment) { var comment = AutoMapper.Mapper.Map <DTOComment, Comment>(dtoComment); if (dtoComment.UserInfoId > 0 && dtoComment.CommentBody.Length > 0) { await _uow.Comments.Insert(comment); } else { throw new ArgumentException("Wrong data"); } }
public void GetAndUpdateCommentTest() { string oldComment = "comentario que ya estaba"; string newComment = "nuevo comentario cambiado"; UserProfileDetails userProfileDetails = new UserProfileDetails("first name", "last name", "*****@*****.**", "es", "ES"); long userId = userService.RegisterUser("user1", "password", userProfileDetails); long commentId = sportEventService.AddComment("user1", 1, oldComment, null); DTOComment comment = sportEventService.getComment(commentId); Assert.IsTrue(oldComment.Equals(comment.comment_description)); sportEventService.UpdateComment(commentId, newComment); comment = sportEventService.getComment(commentId); Assert.IsTrue(newComment.Equals(comment.comment_description)); }
public void UpdateTagsTest() { UserProfileDetails userProfileDetails = new UserProfileDetails("first name", "last name", "*****@*****.**", "es", "ES"); long userId = userService.RegisterUser("user1", "password", userProfileDetails); long newCommentId = sportEventService.AddComment("user1", 1, "description", null); DTOComment expectedComment = new DTOComment(newCommentId, "user1", 1, "description", DateTime.Now.Date, null); List <DTOComment> obtainedComments = sportEventService.FindComments(1, 0, 1); int numberOfComments = obtainedComments.Count(); bool commentExist = commentDao.Exists(newCommentId); Assert.IsTrue(commentExist); Assert.AreEqual(1, numberOfComments); foreach (var comment in obtainedComments) { Assert.AreEqual(expectedComment.commentId, comment.commentId, "Comment found does not correspond with the original one."); Assert.AreEqual(expectedComment.comment_description, comment.comment_description, "Comment found does not correspond with the original one."); Assert.AreEqual(expectedComment.eventId, comment.eventId, "Comment found does not correspond with the original one."); Assert.AreEqual(expectedComment.loginName, comment.loginName, "Comment found does not correspond with the original one."); } //Prueba de actualizacion de tags List <String> tagsPrueba = new List <string>(); tagsPrueba.Add("tag1"); tagsPrueba.Add("tag2"); sportEventService.UpdateTagComment("user1", newCommentId, tagsPrueba); List <DTOComment> listOfCommentsFromEvent = sportEventService.FindComments(1, 0, 1); DTOComment obtainedComment = listOfCommentsFromEvent.First(); List <string> obtainedTagsFromComment = obtainedComment.tags; foreach (var tag in tagsPrueba) { Assert.IsTrue(obtainedTagsFromComment.Contains(tag)); } }
public async Task <IHttpActionResult> AddComment([FromUri] int refId) { var httpRequest = HttpContext.Current.Request; string comment = httpRequest.Params["Coment"]; DTORefractory refractory = await _uow.RefractoryService.GetRefractoryByRefId(refId); if (refractory == null) { return(NotFound()); } var userId = this.User.Identity.GetUserId(); if (userId == null) { return(this.Unauthorized()); } if (comment.Length < 1) { ModelState.AddModelError("Body", "Please write comment."); } if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } DTOUser user = await _uow.UserInfoService.GetUserById(User.Identity.GetUserId <int>()); DTOComment dtoComment = new DTOComment { DateCreation = DateTime.Now, RefractoryId = refId, UserInfoId = user.Id, CommentBody = comment }; await _uow.CommentService.AddComment(dtoComment); return(Content(HttpStatusCode.Created, "Comment added.")); }
public void AddCommentAndFindCommentsTest() { UserProfileDetails userProfileDetails = new UserProfileDetails("first name", "last name", "*****@*****.**", "es", "ES"); long userId = userService.RegisterUser("user1", "password", userProfileDetails); long newCommentId = sportEventService.AddComment("user1", 1, "description", null); DTOComment expectedComment = new DTOComment(newCommentId, "user1", 1, "description", DateTime.Now.Date, null); List <DTOComment> obtainedComments = sportEventService.FindComments(1, 0, 1); int numberOfComments = obtainedComments.Count(); bool commentExist = commentDao.Exists(newCommentId); Assert.IsTrue(commentExist); Assert.AreEqual(1, numberOfComments); foreach (var comment in obtainedComments) { Assert.AreEqual(expectedComment.commentId, comment.commentId, "Comment found does not correspond with the original one."); Assert.AreEqual(expectedComment.comment_description, comment.comment_description, "Comment found does not correspond with the original one."); Assert.AreEqual(expectedComment.eventId, comment.eventId, "Comment found does not correspond with the original one."); Assert.AreEqual(expectedComment.loginName, comment.loginName, "Comment found does not correspond with the original one."); } }