public void Index_UserWithoutGoals_ViewResult() { // Arrange int expectedGoalsOfUserCount = 0; int userId = 100; var mockGoalAggegateService = new Mock <IGoalsService>(); var mockCategoriesService = new Mock <ICategoriesService>(); mockGoalAggegateService.Setup(g => g.GetGoalsByUser(userId)).Returns(GetTestGoalsByUserID(userId)); var controller = new GoalsController(mockCategoriesService.Object, mockGoalAggegateService.Object); var user = IdentityTestHelper.CreateIdentityUser("*****@*****.**", "1"); controller.ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = user } }; // Act var result = controller.Index(); // Assert var viewResult = Assert.IsAssignableFrom <ViewResult>(result); var model = Assert.IsAssignableFrom <IEnumerable <Goal> >(viewResult.ViewData.Model); Assert.Equal(expectedGoalsOfUserCount, model.Count()); }
public async Task GetGoal() { _iGoalServiceMock.Setup(x => x.GetGoals()).Returns(Task.FromResult( new List <Goal>() { new Goal() { Id = 1, Name = "First Goal" }, new Goal() { Id = 2, Name = "Second Goal" }, new Goal() { Id = 3, Name = "Third Goal" } })); GoalsController goalController = new GoalsController(_iGoalServiceMock.Object, _iLoggerMock.Object, _iOptionsMock.Object); var actionResult = await goalController.Index(); var viewResult = Assert.IsType <ViewResult>(actionResult); var model = Assert.IsAssignableFrom <IndexViewModel>(viewResult.ViewData.Model); Assert.Equal("First Goal", model.Goals[0].Name); }