Наследование: PathWrapper
        public MockFileSystem(IDictionary <string, MockFileData> files, string currentDirectory = "")
        {
            if (string.IsNullOrEmpty(currentDirectory))
            {
                currentDirectory = XFS.Path(DEFAULT_CURRENT_DIRECTORY);
            }

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

            Path              = new MockPath(this);
            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);
            }
        }
        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);

            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);
                }
            }
        }
        public void IsLegalAbsoluteOrRelative(string path, string paramName)
        {
            if (path == null)
            {
                throw new ArgumentNullException(paramName, Properties.Resources.VALUE_CANNOT_BE_NULL);
            }

            if (path == string.Empty)
            {
                throw new ArgumentException("Empty file name is not legal.", paramName);
            }

            if (path.Trim() == string.Empty)
            {
                throw new ArgumentException(Properties.Resources.THE_PATH_IS_NOT_OF_A_LEGAL_FORM, paramName);
            }

            if (ExtractFileName(path).IndexOfAny(_mockFileDataAccessor.Path.GetInvalidFileNameChars()) > -1)
            {
                throw new ArgumentException(Properties.Resources.ILLEGAL_CHARACTERS_IN_PATH_EXCEPTION);
            }

            string filePath = ExtractFilePath(path);

            if (MockPath.HasIllegalCharacters(filePath, false))
            {
                throw new ArgumentException(Properties.Resources.ILLEGAL_CHARACTERS_IN_PATH_EXCEPTION);
            }
        }
        public MockFile(IMockFileDataAccessor mockFileDataAccessor)
        {
            if (mockFileDataAccessor == null)
            {
                throw new ArgumentNullException("mockFileDataAccessor");
            }

            this.mockFileDataAccessor = mockFileDataAccessor;
            mockPath = new MockPath(mockFileDataAccessor);
        }
        public MockFile(IMockFileDataAccessor mockFileDataAccessor)
        {
            if (mockFileDataAccessor == null)
            {
                throw new ArgumentNullException("mockFileDataAccessor");
            }

            this.mockFileDataAccessor = mockFileDataAccessor;
            mockPath = new MockPath(mockFileDataAccessor);
        }
        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 override DirectoryInfoBase GetParent(string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            if (path.Length == 0)
            {
                throw new ArgumentException(Properties.Resources.PATH_CANNOT_BE_THE_EMPTY_STRING_OR_ALL_WHITESPACE, "path");
            }

            if (MockPath.HasIllegalCharacters(path, false))
            {
                throw new ArgumentException("Path contains invalid path characters.", "path");
            }

            var absolutePath = mockFileDataAccessor.Path.GetFullPath(path);
            var sepAsString  = mockFileDataAccessor.Path.DirectorySeparatorChar.ToString(CultureInfo.InvariantCulture);

            var lastIndex = 0;

            if (absolutePath != sepAsString)
            {
                var startIndex = absolutePath.EndsWith(sepAsString, StringComparison.OrdinalIgnoreCase) ? absolutePath.Length - 1 : absolutePath.Length;
                lastIndex = absolutePath.LastIndexOf(mockFileDataAccessor.Path.DirectorySeparatorChar, startIndex - 1);
                if (lastIndex < 0)
                {
                    return(null);
                }
            }

            var parentPath = absolutePath.Substring(0, lastIndex);

            if (string.IsNullOrEmpty(parentPath))
            {
                return(null);
            }

            var parent = new MockDirectoryInfo(mockFileDataAccessor, parentPath);

            return(parent);
        }
Пример #8
0
        public void IsLegalAbsoluteOrRelative(string path, string paramName)
        {
            if (path == null)
            {
                throw new ArgumentNullException(paramName, StringResources.Manager.GetString("VALUE_CANNOT_BE_NULL"));
            }

            if (path == string.Empty)
            {
                throw new ArgumentException("Empty file name is not legal.", paramName);
            }

            if (path.Trim() == string.Empty)
            {
                throw new ArgumentException(StringResources.Manager.GetString("THE_PATH_IS_NOT_OF_A_LEGAL_FORM"), paramName);
            }

            if (!MockUnixSupport.IsUnixPlatform())
            {
                if (!IsValidUseOfVolumeSeparatorChar(path))
                {
                    throw new NotSupportedException(StringResources.Manager.GetString("THE_PATH_IS_NOT_OF_A_LEGAL_FORM"));
                }
            }

            if (ExtractFileName(path).IndexOfAny(_mockFileDataAccessor.Path.GetInvalidFileNameChars()) > -1)
            {
                throw new ArgumentException(StringResources.Manager.GetString("ILLEGAL_CHARACTERS_IN_PATH_EXCEPTION"));
            }

            var filePath = ExtractFilePath(path);

            if (MockPath.HasIllegalCharacters(filePath, false))
            {
                throw new ArgumentException(StringResources.Manager.GetString("ILLEGAL_CHARACTERS_IN_PATH_EXCEPTION"));
            }
        }
Пример #9
0
 public MockFile(IMockFileDataAccessor mockFileDataAccessor) : base(mockFileDataAccessor?.FileSystem)
 {
     this.mockFileDataAccessor = mockFileDataAccessor ?? throw new ArgumentNullException(nameof(mockFileDataAccessor));
     mockPath = new MockPath(mockFileDataAccessor);
 }
Пример #10
0
 public MockFile(IMockFileDataAccessor mockFileDataAccessor)
 {
     this.mockFileDataAccessor = mockFileDataAccessor;
     mockPath = new MockPath(mockFileDataAccessor);
 }
Пример #11
0
 public MockFile(IMockFileDataAccessor mockFileDataAccessor)
 {
     this.mockFileDataAccessor = mockFileDataAccessor;
     mockPath = new MockPath(mockFileDataAccessor);
 }