示例#1
0
        public override FileProperties GetFileProperties(string path)
        {
            MockFile file = this.RootDirectory.FindFile(path);

            if (file != null)
            {
                return(file.FileProperties);
            }
            else
            {
                return(FileProperties.DefaultFile);
            }
        }
示例#2
0
        public void AddFile(MockFile file, string path)
        {
            string        parentPath      = path.Substring(0, path.LastIndexOf(Path.DirectorySeparatorChar));
            MockDirectory parentDirectory = this.FindDirectory(parentPath);

            if (parentDirectory == null)
            {
                throw new IOException();
            }

            MockFile existingFileAtPath = parentDirectory.FindFile(path);

            existingFileAtPath.ShouldBeNull();

            parentDirectory.Files.Add(file.FullName, file);
        }
示例#3
0
        public override void DeleteFile(string path)
        {
            if (this.DeleteFileThrowsException)
            {
                throw new IOException("Exception when deleting file");
            }

            MockFile file = this.RootDirectory.FindFile(path);

            if (file == null && !this.DeleteNonExistentFileThrowsException)
            {
                return;
            }

            file.ShouldNotBeNull();

            this.RootDirectory.RemoveFile(path);
        }
示例#4
0
        public MockFile CreateFile(string path, string contents, bool createDirectories = false)
        {
            string        parentPath      = path.Substring(0, path.LastIndexOf(Path.DirectorySeparatorChar));
            MockDirectory parentDirectory = this.FindDirectory(parentPath);

            if (createDirectories)
            {
                if (parentDirectory == null)
                {
                    parentDirectory = this.CreateDirectory(parentPath);
                }
            }
            else
            {
                parentDirectory.ShouldNotBeNull();
            }

            MockFile newFile = new MockFile(path, contents);

            parentDirectory.Files.Add(newFile.FullName, newFile);

            return(newFile);
        }
示例#5
0
        public override void WriteAllText(string path, string contents)
        {
            MockFile file = new MockFile(path, contents);

            this.RootDirectory.AddOrOverwriteFile(file, path);
        }