Esempio n. 1
0
        public async Task AddRatingToCake_WithAddingRate_ShoulIncreaseRatingVotes()
        {
            //Arrange
            var db = this.SetDb();

            await this.SeedProducts(db);

            var repo = new Repository <Product>(db);

            var service = new CakeService(null, repo, this.Mapper);

            //Act
            await service.AddRatingToCake(2, 5);

            await service.AddRatingToCake(2, 3);

            var expectedRatingVotes = 2;
            var actualRatingVotes   = repo.All().SingleOrDefault(p => p.Id == 2).RatingVotes;

            //Assert
            Assert.Equal(expectedRatingVotes, actualRatingVotes);
        }
Esempio n. 2
0
        public async Task AddRatingToCake_WithInValidRate_ShoulThrow()
        {
            //Arrange
            var db = this.SetDb();

            await this.SeedProducts(db);

            var repo = new Repository <Product>(db);

            var service = new CakeService(null, repo, this.Mapper);

            //Act

            //Assert
            await Assert.ThrowsAsync <InvalidOperationException>(async() => await service.AddRatingToCake(2, 6));
        }
Esempio n. 3
0
        public async Task AddRatingToCake_WithValidData_ShoulChangeRatingVotesOfProduct()
        {
            //Arrange
            var db = this.SetDb();

            await this.SeedProducts(db);

            var repo = new Repository <Product>(db);

            var service = new CakeService(null, repo, this.Mapper);

            //Act
            await service.AddRatingToCake(2, 5);

            var expectedRatingVote = 1;
            var actualRatingVote   = repo.All().SingleOrDefault(p => p.Id == 2).RatingVotes;

            //Assert
            Assert.Equal(expectedRatingVote, actualRatingVote);
        }