public async Task ThrowApplicationException_WhenTeamsIsNull() { // Arrange Mock <ITeamService> teamServiceMock = new Mock <ITeamService>(); Mock <IPDFService> pDFServiceMock = new Mock <IPDFService>(); Mock <IMemoryCache> memoryCacheMock = new Mock <IMemoryCache>(); string validSortOrder = string.Empty; string validFilter = string.Empty; int validPageNumber = 1; int validPageSize = 10; IPagedList <Team> teams = null; teamServiceMock.Setup(mock => mock.FilterTeamsAsync(validSortOrder, validFilter, validPageNumber, validPageSize)) .Returns(Task.FromResult(teams)); TeamController SUT = new TeamController( teamServiceMock.Object, pDFServiceMock.Object, memoryCacheMock.Object); // Act & Assert await Assert.ThrowsExceptionAsync <ApplicationException>(() => SUT.Download(validSortOrder, validFilter, validPageNumber, validPageSize)); }
public async Task CallFilterTeamsAsync_WhenCalled() { // Arrange Mock <ITeamService> teamServiceMock = new Mock <ITeamService>(); Mock <IPDFService> pDFServiceMock = new Mock <IPDFService>(); Mock <IMemoryCache> memoryCacheMock = new Mock <IMemoryCache>(); IList <string> validFileParameters = typeof(TeamDownloadViewModel).GetProperties().Select(p => p.Name.ToString()).ToList(); string validCollection = "teams"; string validSortOrder = string.Empty; string validFilter = string.Empty; int validPageNumber = 1; int validPageSize = 10; string validFileName = string.Empty; byte[] validFileBytes = new byte[0]; IPagedList <Team> teams = new PagedList <Team>( new List <Team>().AsQueryable(), validPageNumber, validPageSize); IPagedList <TeamDownloadViewModel> teamDownloadViewModels = new PagedList <TeamDownloadViewModel>( new List <TeamDownloadViewModel>().AsQueryable(), validPageNumber, validPageSize); teamServiceMock.Setup(mock => mock.FilterTeamsAsync(validSortOrder, validFilter, validPageNumber, validPageSize)) .Returns(Task.FromResult(teams)); pDFServiceMock .Setup(mock => mock.CreatePDF(teamDownloadViewModels, validFileParameters, validCollection)) .Returns(validFileName); pDFServiceMock .Setup(mock => mock.GetFileBytesAsync(validFileName)) .Returns(Task.FromResult(validFileBytes)); pDFServiceMock .Setup(mock => mock.DeleteFile(validFileName)); TeamController SUT = new TeamController( teamServiceMock.Object, pDFServiceMock.Object, memoryCacheMock.Object); // Act await SUT.Download(validSortOrder, validFilter, validPageNumber, validPageSize); // Assert teamServiceMock.Verify(mock => mock.FilterTeamsAsync(validSortOrder, validFilter, validPageNumber, validPageSize), Times.Once); }