public async Task EvaluateExam_ShouldReturnRedirectToAction_GivenInvalidUser()
        {
            // Arrange
            var courseService = CourseServiceMock.GetMock;

            courseService.Exists(true);

            var userManager = UserManagerMock.GetMock;

            userManager.GetUserId(null);

            var controller = new TrainersController(
                userManager.Object,
                certificateService: null,
                courseService.Object,
                examService: null,
                trainerService: null)
            {
                TempData = TempDataMock.GetMock
            };

            // Act
            var result = await controller.EvaluateExam(TestCourseId, It.IsAny <StudentCourseGradeFormModel>());

            // Assert
            controller.TempData.AssertErrorMsg(WebConstants.InvalidUserMsg);

            // Result
            this.AssertRedirectToTrainersControllerIndex(result);

            courseService.Verify();
            userManager.Verify();
        }
        public async Task EvaluateExam_ShouldReturnRedirectToActionWithCorrectRouteValues_GivenModelError()
        {
            // Arrange
            var courseService = CourseServiceMock.GetMock;

            courseService.Exists(true);

            var controller = new TrainersController(
                userManager: null,
                certificateService: null,
                courseService.Object,
                examService: null,
                trainerService: null)
            {
                TempData = TempDataMock.GetMock
            };

            controller.ModelState.AddModelError(string.Empty, "Error"); // model error

            // Act
            var result = await controller.EvaluateExam(TestCourseId, It.IsAny <StudentCourseGradeFormModel>());

            // Assert
            controller.TempData.AssertErrorMsg(WebConstants.GradeInvalidMsg);

            this.AssertRedirectToTrainersControllerStudents(result);
            this.AssertRouteWithId(result);

            courseService.Verify();
        }
        public async Task EvaluateExam_ShouldReturnRedirectToActionWithCorrectRouteValuesAndCertificateSuccessMsg_GivenCertificatetSuccess()
        {
            // Arrange
            var testModel = this.GetStudentInCourseWithGrade();

            var courseService = CourseServiceMock.GetMock;

            courseService
            .Exists(true)
            .IsUserEnrolledInCourseAsync(true);

            var userManager = UserManagerMock.GetMock;

            userManager.GetUserId(TestUserId);

            var trainerService = TrainerServiceMock.GetMock;

            trainerService
            .IsTrainerForCourseAsync(true)
            .CourseHasEndedAsync(true);

            var examService = ExamServiceMock.GetMock;

            examService.EvaluateAsync(true);

            var certificateService = CertificateServiceMock.GetMock;

            certificateService
            .IsGradeEligibleForCertificate(true)
            .CreateAsync(true);

            var controller = new TrainersController(
                userManager.Object,
                certificateService.Object,
                courseService.Object,
                examService.Object,
                trainerService.Object)
            {
                TempData = TempDataMock.GetMock
            };

            // Act
            var result = await controller.EvaluateExam(TestCourseId, testModel);

            // Assert
            controller.TempData.AssertSuccessMsg(
                WebConstants.ExamAssessedMsg
                + Environment.NewLine
                + WebConstants.CertificateIssuedMsg);

            this.AssertRedirectToTrainersControllerStudents(result);
            this.AssertRouteWithId(result);

            certificateService.Verify();
            courseService.Verify();
            examService.Verify();
            trainerService.Verify();
            userManager.Verify();
        }
        public async Task EvaluateExam_ShouldReturnRedirectToActionWithCorrectRouteValues_GivenAssessmentError()
        {
            // Arrange
            var testModel = this.GetStudentInCourseWithGrade();

            var courseService = CourseServiceMock.GetMock;

            courseService
            .Exists(true)
            .IsUserEnrolledInCourseAsync(true);

            var userManager = UserManagerMock.GetMock;

            userManager.GetUserId(TestUserId);

            var trainerService = TrainerServiceMock.GetMock;

            trainerService
            .IsTrainerForCourseAsync(true)
            .CourseHasEndedAsync(true);

            var examService = ExamServiceMock.GetMock;

            examService.EvaluateAsync(false);

            var controller = new TrainersController(
                userManager.Object,
                certificateService: null,
                courseService.Object,
                examService.Object,
                trainerService.Object)
            {
                TempData = TempDataMock.GetMock
            };

            // Act
            var result = await controller.EvaluateExam(TestCourseId, testModel);

            // Assert
            controller.TempData.AssertErrorMsg(WebConstants.ExamAssessmentErrorMsg);

            this.AssertRedirectToTrainersControllerStudents(result);
            this.AssertRouteWithId(result);

            courseService.Verify();
            examService.Verify();
            trainerService.Verify();
            userManager.Verify();
        }
        public async Task EvaluateExam_ShouldReturnRedirectToAction_BeforeCourseEndDate()
        {
            // Arrange
            var courseService = CourseServiceMock.GetMock;

            courseService.Exists(true);

            var userManager = UserManagerMock.GetMock;

            userManager.GetUserId(TestUserId);

            var trainerService = TrainerServiceMock.GetMock;

            trainerService
            .IsTrainerForCourseAsync(true)
            .CourseHasEndedAsync(false);

            var controller = new TrainersController(
                userManager.Object,
                certificateService: null,
                courseService.Object,
                examService: null,
                trainerService.Object)
            {
                TempData = TempDataMock.GetMock
            };

            // Act
            var result = await controller.EvaluateExam(TestCourseId, It.IsAny <StudentCourseGradeFormModel>());

            // Assert
            controller.TempData.AssertErrorMsg(WebConstants.CourseHasNotEndedMsg);

            this.AssertRedirectToTrainersControllerStudents(result);

            courseService.Verify();
            trainerService.Verify();
            userManager.Verify();
        }