public void GetWeekTemplates_SuccessTest(DateTime todaysDate) { //Arrange List <Registry> weekRegistries = GetTestRegistries(); List <Mission> missions = GetTestMissions(); List <Task> tasks = GetTestTasks(); Mock <IRegistryRepository> registryRepoMock = new Mock <IRegistryRepository>(); registryRepoMock.SetupSequence(r => r.GetRegistriesByDate(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <int>())) .Returns(weekRegistries) .Returns(new List <Registry>()) .Returns(new List <Registry>()) .Returns(new List <Registry>()) .Returns(new List <Registry>()); Mock <IMissionRepository> missionRepoMock = new Mock <IMissionRepository>(); missionRepoMock.Setup(r => r.GetById(1)).Returns(missions[0]); missionRepoMock.Setup(r => r.GetById(2)).Returns(missions[1]); Mock <ITaskRepository> taskRepoMock = new Mock <ITaskRepository>(); taskRepoMock.Setup(r => r.GetById(1)).Returns(tasks[0]); taskRepoMock.Setup(r => r.GetById(2)).Returns(tasks[1]); Mock <IUnitOfWork> mockUOF = new Mock <IUnitOfWork>(); mockUOF.Setup(uow => uow.RegistryRepository).Returns(registryRepoMock.Object); mockUOF.Setup(uow => uow.MissionRepository).Returns(missionRepoMock.Object); mockUOF.Setup(uow => uow.TaskRepository).Returns(taskRepoMock.Object); var controller = new ReportingController(mockUOF.Object, httpContextAccessorMock); //Act var result = controller.GetWeekTemplates(todaysDate); //Assert Assert.IsType <ActionResult <List <WeekTemplateViewModel> > >(result); registryRepoMock.Verify(r => r.GetRegistriesByDate(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <int>()), Times.Exactly(5)); Assert.Single(result.Value); }
public void GetWeekTemplates_ThrowsInternalServerErrorException(DateTime todaysDate) { //Arrange Mock <IRegistryRepository> registryRepoMock = new Mock <IRegistryRepository>(); registryRepoMock.Setup(r => r.GetLatestRegistries(It.IsAny <int>(), It.IsAny <int>())).Throws <Exception>(); Mock <IUnitOfWork> mockUOF = new Mock <IUnitOfWork>(); mockUOF.Setup(uow => uow.RegistryRepository).Returns(registryRepoMock.Object); var controller = new ReportingController(mockUOF.Object, httpContextAccessorMock); //Act var result = controller.GetWeekTemplates(todaysDate); //Assert Assert.IsType <ActionResult <List <WeekTemplateViewModel> > >(result); Assert.Equal((int)HttpStatusCode.InternalServerError, (result.Result as ObjectResult).StatusCode); }