namespace CommanderApp; public class MockFileSystemService : IFileSystemService { public string MockRootPath { get; set; } = "/mock/root"; private readonly Dictionary> _mockDirectories = new(); public MockFileSystemService() { // Инициализируем mock данными SetupMockData(); } private void SetupMockData() { _mockDirectories["/mock/root"] = new List { new FileSystemItem { Name = "Documents", FullName = "/mock/root/Documents", IsDirectory = true }, new FileSystemItem { Name = "Pictures", FullName = "/mock/root/Pictures", IsDirectory = true }, new FileSystemItem { Name = "readme.txt", FullName = "/mock/root/readme.txt", IsDirectory = false }, new FileSystemItem { Name = "..", FullName = "/mock", IsDirectory = true } }; _mockDirectories["/mock/root/Documents"] = new List { new FileSystemItem { Name = "Project1", FullName = "/mock/root/Documents/Project1", IsDirectory = true }, new FileSystemItem { Name = "Project2", FullName = "/mock/root/Documents/Project2", IsDirectory = true }, new FileSystemItem { Name = "notes.txt", FullName = "/mock/root/Documents/notes.txt", IsDirectory = false }, new FileSystemItem { Name = "..", FullName = "/mock/root", IsDirectory = true } }; _mockDirectories["/mock/root/Pictures"] = new List { new FileSystemItem { Name = "vacation.jpg", FullName = "/mock/root/Pictures/vacation.jpg", IsDirectory = false }, new FileSystemItem { Name = "..", FullName = "/mock/root", IsDirectory = true } }; } public string GetRootPath() { return MockRootPath; } public IEnumerable GetDirectoryContents(string path) { if (_mockDirectories.ContainsKey(path)) { return _mockDirectories[path]; } // Если директории нет в mock данных, возвращаем пустой список с ".." var parent = GetParentPath(path); if (parent != null) { return new List { new FileSystemItem { Name = "..", FullName = parent, IsDirectory = true } }; } return Enumerable.Empty(); } // Метод для добавления mock данных в тестах public void AddMockDirectory(string path, List items) { _mockDirectories[path] = items; } private string GetParentPath(string path) { var separator = '/'; var lastSeparator = path.LastIndexOf(separator); if (lastSeparator > 0) { return path.Substring(0, lastSeparator); } return null; } }