public Review(model.Review item = null) : base(item) { if (item != null) { this.InjectFrom(item); Body = item.ReviewFieldValues.First(value => value.Name == "Review").Value; ItemName = item.ItemId; ReviewType = ReviewType.Review; } }
public void Can_save_review_comments() { var client = GetRepository(); var reviewId = Guid.NewGuid().ToString(); var customerId = Guid.NewGuid().ToString(); Review dbReviewreview = new Review() { ReviewId = reviewId, AuthorId = customerId, AuthorLocation = "Los Angeles", AuthorName = "NickName", ItemId = "someitem", ItemUrl = "url", OverallRating = 5, Title = "comment", IsVerifiedBuyer = true, Status = (int)ReviewStatus.Pending }; client.Add(dbReviewreview); client.UnitOfWork.Commit(); //RefreshClient RefreshRepository(ref client); var loadedReview = client.Reviews.Where(r => r.ReviewId == reviewId).SingleOrDefault(); //client.Attach(loadedReview); ReviewComment reviewComment = new ReviewComment(); reviewComment.AuthorId = customerId; reviewComment.AuthorLocation = "Los Angeles"; reviewComment.AuthorName = "Author"; reviewComment.Comment = "Comment"; reviewComment.ReviewCommentId = Guid.NewGuid().ToString(); reviewComment.Status = (int)ReviewStatus.Pending; loadedReview.ReviewComments.Add(reviewComment); //client.Update(loadedReview); client.UnitOfWork.Commit(); RefreshRepository(ref client); loadedReview = (from r in client.Reviews where r.ReviewId == reviewId select r).ExpandAll().SingleOrDefault(); // test delete from collection, object should be removed from db as well loadedReview.ReviewComments.Remove(loadedReview.ReviewComments[0]); client.UnitOfWork.Commit(); RefreshRepository(ref client); loadedReview = (from r in client.Reviews where r.ReviewId == reviewId select r).ExpandAll().SingleOrDefault(); Assert.True(loadedReview.ReviewComments.Count == 0); // test saving just a comment by itself var reviewComment2 = new ReviewComment(); reviewComment2.AuthorId = customerId; reviewComment2.AuthorLocation = "Los Angeles"; reviewComment2.AuthorName = "Author"; reviewComment2.ReviewId = reviewId; reviewComment2.Comment = "Comment"; reviewComment2.ReviewCommentId = Guid.NewGuid().ToString(); reviewComment2.Status = (int)ReviewStatus.Pending; client.Add(reviewComment2); client.UnitOfWork.Commit(); var comment2 = (from r in client.ReviewComments where r.ReviewId == reviewId && r.ReviewCommentId == reviewComment2.ReviewCommentId select r).SingleOrDefault(); Assert.True(comment2 != null); // now modify it reviewComment2.AuthorName = "Author2"; client.UnitOfWork.Commit(); comment2 = (from r in client.ReviewComments where r.ReviewId == reviewId && r.ReviewCommentId == reviewComment2.ReviewCommentId select r).SingleOrDefault(); Assert.True(comment2 != null); }