public async Task Courses_ShouldReturnRedirectToAction_GivenInvalidUser() { // Arrange var userManager = UserManagerMock.GetMock; userManager.GetUserId(null); var controller = new TrainersController( userManager.Object, certificateService: null, courseService: null, examService: null, trainerService: null) { TempData = TempDataMock.GetMock }; // Act var result = await controller.Courses(It.IsAny <string>(), It.IsAny <int>()); // Assert controller.TempData.AssertErrorMsg(WebConstants.InvalidUserMsg); this.AssertRedirectToCoursesControllerIndex(result); userManager.Verify(); }
[InlineData(int.MaxValue)] // invalid public async Task Courses_ShouldReturnViewResultWithCorrectModel_GivenValidUser(int page) { // Arrange var testPagination = Tests.GetPaginationViewModel(page, TestTotalItems, TestSearchTerm); var userManager = UserManagerMock.GetMock; userManager.GetUserId(TestUserId); var trainerService = TrainerServiceMock.GetMock; trainerService .TotalCoursesAsync(TestTotalItems) .CoursesAsync(Tests.GetCourseServiceModelCollection()) .CoursesToEvaluateAsync(Tests.GetCourseServiceModelCollection()); var controller = new TrainersController( userManager.Object, certificateService: null, courseService: null, examService: null, trainerService.Object); // Act var result = await controller.Courses(TestSearchTerm, page); // Assert var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsType <TrainerCoursePageListingViewModel>(viewResult.Model); this.AssertCoursePage(testPagination, model); Tests.AssertCourseServiceModelCollection(model.CoursesToEvaluate); userManager.Verify(); trainerService.Verify(); }