public async Task ThrowApplicationException_WhenSpellsIsNull() { // Arrange Mock <ISpellService> spellServiceMock = new Mock <ISpellService>(); 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 <Spell> spells = null; spellServiceMock.Setup(mock => mock.FilterSpellsAsync(validSortOrder, validFilter, validPageNumber, validPageSize)) .Returns(Task.FromResult(spells)); SpellController SUT = new SpellController( spellServiceMock.Object, pDFServiceMock.Object, memoryCacheMock.Object); // Act & Assert await Assert.ThrowsExceptionAsync <ApplicationException>(() => SUT.Download(validSortOrder, validFilter, validPageNumber, validPageSize)); }
public async Task CallFilterSpellsAsync_WhenCalled() { // Arrange Mock <ISpellService> spellServiceMock = new Mock <ISpellService>(); Mock <IPDFService> pDFServiceMock = new Mock <IPDFService>(); Mock <IMemoryCache> memoryCacheMock = new Mock <IMemoryCache>(); IList <string> validFileParameters = typeof(SpellDownloadViewModel).GetProperties().Select(p => p.Name.ToString()).ToList(); string validCollection = "spells"; string validSortOrder = string.Empty; string validFilter = string.Empty; int validPageNumber = 1; int validPageSize = 10; string validFileName = string.Empty; byte[] validFileBytes = new byte[0]; IPagedList <Spell> spells = new PagedList <Spell>( new List <Spell>().AsQueryable(), validPageNumber, validPageSize); IPagedList <SpellDownloadViewModel> spellDownloadViewModels = new PagedList <SpellDownloadViewModel>( new List <SpellDownloadViewModel>().AsQueryable(), validPageNumber, validPageSize); spellServiceMock.Setup(mock => mock.FilterSpellsAsync(validSortOrder, validFilter, validPageNumber, validPageSize)) .Returns(Task.FromResult(spells)); pDFServiceMock .Setup(mock => mock.CreatePDF(spellDownloadViewModels, validFileParameters, validCollection)) .Returns(validFileName); pDFServiceMock .Setup(mock => mock.GetFileBytesAsync(validFileName)) .Returns(Task.FromResult(validFileBytes)); pDFServiceMock .Setup(mock => mock.DeleteFile(validFileName)); SpellController SUT = new SpellController( spellServiceMock.Object, pDFServiceMock.Object, memoryCacheMock.Object); // Act await SUT.Download(validSortOrder, validFilter, validPageNumber, validPageSize); // Assert spellServiceMock.Verify(mock => mock.FilterSpellsAsync(validSortOrder, validFilter, validPageNumber, validPageSize), Times.Once); }