public async Task AddRatingToBook_WithAddingRate_ShoulIncreaseRatingVotes() { //Arrange var db = this.SetDb(); await this.SeedBook(db); var repo = new Repository <Book>(db); var service = new BookService(repo, this.Mapper, null); //Act await service.AddRatingToBook(2, 5); await service.AddRatingToBook(2, 3); var expectedRatingVotes = 2; var actualRatingVotes = repo.All().SingleOrDefault(p => p.Id == 2).RatingVotes; //Assert Assert.Equal(expectedRatingVotes, actualRatingVotes); }
public async Task AddRatingToBook_WithInValidRate_ShoulThrow() { //Arrange var db = this.SetDb(); await this.SeedBook(db); var repo = new Repository <Book>(db); var service = new BookService(repo, this.Mapper, null); //Act //Assert await Assert.ThrowsAsync <InvalidOperationException>(async() => await service.AddRatingToBook(2, 6)); }
public async Task AddRatingToBook_WithValidData_ShouldAddRating() { //Arrange var db = this.SetDb(); await this.SeedBook(db); var repo = new Repository <Book>(db); var service = new BookService(repo, this.Mapper, null); //Act await service.AddRatingToBook(2, 5); var expectedRate = 5; var actualRate = repo.All().SingleOrDefault(p => p.Id == 2).Rating; //Assert Assert.Equal(expectedRate, actualRate); }