public async Task FileController_ListFile_Sucess_ForNoDefaultPageNumber() { // setup var DEFAULT_PAGCE_NUMBER = 1; var paginatedFileInfo = new PaginatedFileInfo() { Files = Enumerable.Range(10, 0).Select(n => new StoredFileInfo()), PageNumber = DEFAULT_PAGCE_NUMBER, PageSize = 10, TotalRecords = 10 }; Mock <IFileStorage> mockStorage = new Mock <IFileStorage>(); mockStorage.Setup(s => s.ListAsync(0, 1, default)) .ReturnsAsync(paginatedFileInfo); Mock <ILogger <FileController> > mockLogger = new Mock <ILogger <FileController> >(); // act var controller = new FileController(mockStorage.Object, mockLogger.Object); var res = await controller.ListFiles(10, 0, default) as ObjectResult; // assert Assert.AreEqual((int)HttpStatusCode.OK, res.StatusCode); mockStorage.Verify(m => m.ListAsync(10, 1, default), Times.Once); }
public async Task FileController_ListFile_Sucess_ForNoDefaultPageSize() { // setup var DEFAULT_PAGE_SIZE = 10; var mockPaginatedFiles = new PaginatedFileInfo() { Files = Enumerable.Range(0, DEFAULT_PAGE_SIZE).Select(n => new StoredFileInfo()), PageNumber = 1, PageSize = DEFAULT_PAGE_SIZE, TotalRecords = DEFAULT_PAGE_SIZE }; Mock <IFileStorage> mockStorage = new Mock <IFileStorage>(); mockStorage.Setup(s => s.ListAsync(DEFAULT_PAGE_SIZE, 1, default)) .ReturnsAsync(mockPaginatedFiles); Mock <ILogger <FileController> > mockLogger = new Mock <ILogger <FileController> >(); // act var controller = new FileController(mockStorage.Object, mockLogger.Object); var res = await controller.ListFiles(0, 1, default) as ObjectResult; var paginatedFiles = res.Value as PaginatedFileInfo; // assert Assert.AreEqual((int)HttpStatusCode.OK, res.StatusCode); Assert.AreEqual(DEFAULT_PAGE_SIZE, paginatedFiles.TotalRecords); Assert.AreEqual(DEFAULT_PAGE_SIZE, paginatedFiles.Files.Count()); mockStorage.Verify(m => m.ListAsync(DEFAULT_PAGE_SIZE, 1, default), Times.Once); }