Exemple #1
0
        public void AddFile(string path, MockFileData mockFile)
        {
            var fixedPath = FixPath(path);

            throwExceptionWhenReadonly(path, fixedPath);

            var directoryPath = Path.GetDirectoryName(fixedPath);

            lock (files)
            {
                if (!directory.Exists(directoryPath))
                {
                    directory.CreateDirectory(directoryPath);
                }

                files[fixedPath] = mockFile;
            }
        }
        public MockFileSystem(IDictionary<string, MockFileData> files)
        {
            file = new MockFile(this);
            directory = new MockDirectory(this, file);
            fileInfoFactory = new MockFileInfoFactory(this);
            path = new MockPath();
            directoryInfoFactory = new MockDirectoryInfoFactory(this);

            //For each mock file add a file to the files dictionary
            //Also add a file entry for all directories leading up to this file
            this.files = new Dictionary<string, MockFileData>(StringComparer.InvariantCultureIgnoreCase);
            foreach (var entry in files)
            {
                var directoryPath = Path.GetDirectoryName(entry.Key);
                if (!directory.Exists(directoryPath))
                    directory.CreateDirectory(directoryPath);

                if (!file.Exists(entry.Key))
                    this.files.Add(entry.Key, entry.Value);
            }
        }
Exemple #3
0
        public void AddFile(string path, MockFileData mockFile)
        {
            var fixedPath = FixPath(path);

            if (FileExists(fixedPath) && (files[fixedPath].Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
            {
                throw new UnauthorizedAccessException(string.Format("Access to the path '{0}' is denied.", path));
            }

            var directoryPath = Path.GetDirectoryName(fixedPath);

            lock (files)
            {
                if (!directory.Exists(directoryPath))
                {
                    directory.CreateDirectory(directoryPath);
                }

                files[fixedPath] = mockFile;
            }
        }