public HttpResponseMessage PutCommentInappropriate(InappropriateCommentModel inappropriateModel) { CommentModel commentModel; try { if (InappropriateExists(inappropriateModel) == null) { commentModel = unitOfWork.CommentRepository.Get(a => a.Id == inappropriateModel.CommentId).Select(x => Mapper.Map <CommentModel>(x)).FirstOrDefault(); commentModel.Counter++; var inappropriate = Mapper.Map <InappropriateComment>(inappropriateModel); unitOfWork.InappropriateCommentRepository.Insert(inappropriate); var comment = Mapper.Map <Comment>(commentModel); unitOfWork.CommentRepository.Update(comment); unitOfWork.Save(); return(Create(inappropriate)); } else { return(Forbidden()); } } catch (ObjectNotFoundException) { return(NotFound("Not Found. There is no Comment")); } catch (Exception ex) { return(InternalServerError("Server Error: Can not set Inappropriate flag for this Comment.", ex)); } }
private InappropriateCommentModel InappropriateExists(InappropriateCommentModel inappModel) { try { return(unitOfWork.InappropriateCommentRepository.Get(r => r.UserId == inappModel.UserId && r.CommentId == inappModel.CommentId).Select(x => Mapper.Map <InappropriateCommentModel>(x)).First()); } catch { return(null); } }
public void PutCommentInappropriate_ShouldNotBeInserted() { int count = inappComments.Count; var inappModel = new InappropriateCommentModel { Id = Guid.NewGuid(), Description = "CommentDescription", CommentId = new Guid("cd6aa915-6044-4354-8958-befc3bdfe02e"), //comment2 UserId = new Guid("fa8849b6-c4b6-47d5-96a0-109b0500047a") //user1 }; var response = controllerC.PutCommentInappropriate(inappModel); Assert.AreEqual(HttpStatusCode.Forbidden, response.StatusCode); Assert.AreEqual(count, inappComments.Count); }
public void PutCommentInappropriate_ShouldBeInserted() { int count = inappComments.Count; var inappModel = new InappropriateCommentModel { Id = Guid.NewGuid(), Description = "CommentDescription", CommentId = new Guid("cd6aa915-6044-4354-8958-befc3bdfe02e"), //comment2 UserId = new Guid("39c3a066-78b2-43a3-a04b-28757864114e") //user2 }; var response = controllerC.PutCommentInappropriate(inappModel); Assert.AreEqual(HttpStatusCode.Created, response.StatusCode); Assert.AreEqual(count + 1, inappComments.Count); }