Exemple #1
0
        public MockFileSystem(IDictionary <string, MockFileData> files, string currentDirectory = "")
        {
            if (string.IsNullOrEmpty(currentDirectory))
            {
                currentDirectory = XFS.Path(DEFAULT_CURRENT_DIRECTORY);
            }

            pathVerifier = new PathVerifier(this);

            this.files = new Dictionary <string, MockFileData>(StringComparer.OrdinalIgnoreCase);

            Path              = new MockPath(this);
            File              = new MockFile(this);
            Directory         = new MockDirectory(this, File, currentDirectory);
            FileInfo          = new MockFileInfoFactory(this);
            FileStream        = new MockFileStreamFactory(this);
            DirectoryInfo     = new MockDirectoryInfoFactory(this);
            DriveInfo         = new MockDriveInfoFactory(this);
            FileSystemWatcher = new MockFileSystemWatcherFactory();

            if (files != null)
            {
                foreach (var entry in files)
                {
                    AddFile(entry.Key, entry.Value);
                }
            }

            if (!FileExists(currentDirectory))
            {
                AddDirectory(currentDirectory);
            }
        }
        public MockFileSystem(IDictionary <string, MockFileData> files, string currentDirectory = "")
        {
            if (string.IsNullOrEmpty(currentDirectory))
            {
                currentDirectory = IO.Path.GetTempPath();
            }

            pathVerifier = new PathVerifier(this);

            this.files           = new Dictionary <string, MockFileData>(StringComparer.OrdinalIgnoreCase);
            pathField            = new MockPath(this);
            file                 = new MockFile(this);
            directory            = new MockDirectory(this, file, currentDirectory);
            fileInfoFactory      = new MockFileInfoFactory(this);
            directoryInfoFactory = new MockDirectoryInfoFactory(this);
            driveInfoFactory     = new MockDriveInfoFactory(this);

            if (files != null)
            {
                foreach (var entry in files)
                {
                    AddFile(entry.Key, entry.Value);
                }
            }
        }
        public MockFileSystem(IDictionary <string, MockFileData> files, string currentDirectory = "")
        {
            if (string.IsNullOrEmpty(currentDirectory))
            {
                currentDirectory = XFS.Path(DEFAULT_CURRENT_DIRECTORY);
            }
            else if (!System.IO.Path.IsPathRooted(currentDirectory))
            {
                throw new ArgumentException("Current directory needs to be rooted.", nameof(currentDirectory));
            }

            var defaultTempDirectory = XFS.Path(TEMP_DIRECTORY);

            StringOperations = new StringOperations(XFS.IsUnixPlatform());
            pathVerifier     = new PathVerifier(this);
            this.files       = new Dictionary <string, MockFileData>(StringOperations.Comparer);

            Path              = new MockPath(this, defaultTempDirectory);
            File              = new MockFile(this);
            Directory         = new MockDirectory(this, currentDirectory);
            FileInfo          = new MockFileInfoFactory(this);
            FileStream        = new MockFileStreamFactory(this);
            DirectoryInfo     = new MockDirectoryInfoFactory(this);
            DriveInfo         = new MockDriveInfoFactory(this);
            FileSystemWatcher = new MockFileSystemWatcherFactory();

            if (files != null)
            {
                foreach (var entry in files)
                {
                    AddFile(entry.Key, entry.Value);
                }
            }

            if (!FileExists(currentDirectory))
            {
                AddDirectory(currentDirectory);
            }

            if (!FileExists(defaultTempDirectory))
            {
                AddDirectory(defaultTempDirectory);
            }
        }
        public MockFileSystem(IDictionary<string, MockFileData> files, string currentDirectory = "")
        {
            if (string.IsNullOrEmpty(currentDirectory))
                currentDirectory = IO.Path.GetTempPath();

            pathVerifier = new PathVerifier(this);

            this.files = new Dictionary<string, MockFileData>(StringComparer.OrdinalIgnoreCase);
            pathField = new MockPath(this);
            file = new MockFile(this);
            directory = new MockDirectory(this, file, currentDirectory);
            fileInfoFactory = new MockFileInfoFactory(this);
            directoryInfoFactory = new MockDirectoryInfoFactory(this);
            driveInfoFactory = new MockDriveInfoFactory(this);

            if (files != null)
            {
                foreach (var entry in files)
                {
                    AddFile(entry.Key, entry.Value);
                }
            }
        }