public async Task ReturnCorrectViewModel_WhenCalled() { // Arrange Mock <ILeagueService> leagueServiceMock = new Mock <ILeagueService>(); Mock <IPDFService> pDFServiceMock = new Mock <IPDFService>(); IMemoryCache memoryCacheMock = new MemoryCache(new MemoryCacheOptions()); string validSortOrder = string.Empty; string validFilter = string.Empty; int validPageNumber = 1; int validPageSize = 10; IPagedList <League> leagues = new PagedList <League>(new List <League>().AsQueryable(), validPageNumber, validPageSize); leagueServiceMock.Setup(mock => mock.FilterLeaguesAsync(validSortOrder, validFilter, validPageNumber, validPageSize)) .Returns(Task.FromResult(leagues)); LeagueController SUT = new LeagueController( leagueServiceMock.Object, pDFServiceMock.Object, memoryCacheMock); // Act var result = await SUT.Index() as ViewResult; // Assert Assert.IsInstanceOfType(result.Model, typeof(LeagueIndexViewModel)); }
public async Task Test_Index_Returns_Leagues() { var result = await controller.Index(); var model = ((ViewResult)result).Model as List <League>; Assert.AreEqual(3, model.Count); }
public void Index_ReturnsLeagueViewModel() { //Arrange //Act var result = _leagueController.Index(); //Assert Assert.NotNull(result); var viewResult = Assert.IsAssignableFrom <ViewResult>(result); var viewModel = Assert.IsAssignableFrom <LeagueViewModel>(viewResult.ViewData.Model); }
public void LeagueController_Index_NoLeagues() { //Arrange var mockLeagueService = new MockLeagueService().MockGetAll(new List <League>()); var controller = new LeagueController(mockLeagueService.Object); //Act var result = controller.Index(); //Assert Assert.IsAssignableFrom <ViewResult>(result); mockLeagueService.VerifyGetAll(Times.Once()); }
public void LeagueController_Index_LeaguesExist() { //Arrange var mockLeagues = new List <League>() { new League() { ID = 1, FoundingDate = new DateTime(1933, 5, 3) } }; var mockLeagueService = new MockLeagueService().MockGetAll(mockLeagues); var controller = new LeagueController(mockLeagueService.Object); //Act var result = controller.Index(); //Assert Assert.IsAssignableFrom <ViewResult>(result); mockLeagueService.VerifyGetAll(Times.Once()); }