public async Task <ActionResult <FolderContentsDto> > GetFolderInfoAsync(int?folderId = null) { FolderContentsDto folderInfo = null; try { folderInfo = await _folderService.ReadContentsAsync(folderId); } catch (Exception ex) { if (folderId != null) { _logger.LogCritical(ex, $"Error getting content for folder id={folderId}."); } else { _logger.LogCritical(ex, $"Error getting content for root folder."); } return(StatusCode(StatusCodes.Status500InternalServerError)); } if (folderInfo == null) { return(NotFound()); } return(Ok(await Task.FromResult(folderInfo))); }
public FolderController BuildController() { _mockFolderService .Setup(inst => inst.ReadContentsAsync(It.IsAny <int?>())) .ReturnsAsync((int?id) => { FolderContentsDto item = null; if (id == null) { item = _testData .Where(folder => folder.Folder == null) .SingleOrDefault(); } else { item = _testData .Where(folder => folder.Folder != null && folder.Folder.Id == id) .SingleOrDefault(); } return(item); }); _mockFolderService .Setup(inst => inst.CreateItemAsync(It.IsAny <FolderDto>())) .ReturnsAsync((FolderDto folder) => { folder.Id = _nextId++; return(folder); }); return(new FolderController(_mockFolderService.Object, _mockLogger.Object)); }