public async Task AddRatingToTutorial_WithAddingRate_ShoulIncreaseRatingVotes()
        {
            //Arrange
            var db = this.SetDb();

            await this.SeedTutorials(db);

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

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

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

            await service.AddRatingToTutorial(2, 3);

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

            //Assert
            Assert.Equal(expectedRatingVotes, actualRatingVotes);
        }
        public async Task AddRatingToTutorial_WithInValidRating_ShouldThrow()
        {
            //Arrange
            var db = this.SetDb();

            await this.SeedTutorials(db);

            var repo    = new Repository <Tutorial>(db);
            var service = new TutorialService(repo, this.Mapper, null);

            //Act

            //Assert
            await Assert.ThrowsAsync <InvalidOperationException>(async() => await service.AddRatingToTutorial(2, 6));
        }
        public async Task AddRatingToTutorial_WithNullTutorial_ShoulThrow()
        {
            //Arrange
            var db = this.SetDb();

            await this.SeedTutorials(db);

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

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

            //Act

            //Assert
            await Assert.ThrowsAsync <NullReferenceException>(async() => await service.AddRatingToTutorial(3, -5));
        }
        public async Task AddRatingToTutorial_WithValidData_ShouldAddRatingToTutorial()
        {
            //Arrange
            var db = this.SetDb();

            await this.SeedTutorials(db);

            var repo    = new Repository <Tutorial>(db);
            var service = new TutorialService(repo, this.Mapper, null);

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

            var expectedRate = 5;
            var actualRate   = repo.All().SingleOrDefault(p => p.Id == 2).Rating;

            //Assert
            Assert.Equal(expectedRate, actualRate);
        }