public async Task CreateRatingChangesRatingsIfItAlreadyExists() { // Arrange var ratingList = this.GetRatings(); var reviewList = this.GetReviews(); var ratingMock = this.GetRatingMock(ratingList); var reviewMock = this.GetReviewMock(reviewList); var creatorId = "2"; var expectedRatingCount = ratingList.Count(); var reviewService = new ReviewsService(reviewMock.Object, ratingMock.Object, this.mediaRepo); var inputModel = new RatingInputModel() { MediaId = "3", Value = 5, }; // Act await reviewService.CreateRating(inputModel.MediaId, creatorId, inputModel.Value); var newValue = ratingMock.Object.All().Where(x => x.MediaId == inputModel.MediaId && x.CreatorId == creatorId).FirstOrDefault().Score; // Assert Assert.Equal(expectedRatingCount, ratingMock.Object.All().Count()); Assert.Equal(inputModel.Value, newValue); }
public async Task CreateRatingAddsNewIfItDoesNotExist() { // Arrange var ratingList = this.GetRatings(); var reviewList = this.GetReviews(); var ratingMock = this.GetRatingMock(ratingList); var reviewMock = this.GetReviewMock(reviewList); var expectedRatingCount = ratingList.Count() + 1; var reviewService = new ReviewsService(reviewMock.Object, ratingMock.Object, this.mediaRepo); var inputModel = new RatingInputModel() { MediaId = "4", Value = 5, }; // Act await reviewService.CreateRating(inputModel.MediaId, "2", inputModel.Value); // Assert Assert.Equal(expectedRatingCount, ratingMock.Object.All().Count()); Assert.Contains(ratingMock.Object.All(), x => x.MediaId == inputModel.MediaId && x.Score == inputModel.Value); }