Ejemplo n.º 1
0
        public override Stream OpenFileStream(string path, FileMode fileMode, FileAccess fileAccess, FileShare shareMode, FileOptions options, bool flushesToDisk)
        {
            MockFile file = this.RootDirectory.FindFile(path);

            if (fileMode == FileMode.Create)
            {
                if (file != null)
                {
                    this.RootDirectory.RemoveFile(path);
                }

                return(this.CreateAndOpenFileStream(path));
            }

            if (fileMode == FileMode.OpenOrCreate)
            {
                if (file == null)
                {
                    return(this.CreateAndOpenFileStream(path));
                }
            }
            else
            {
                file.ShouldNotBeNull();
            }

            return(file.GetContentStream());
        }
Ejemplo n.º 2
0
        private Stream CreateAndOpenFileStream(string path)
        {
            MockFile file = this.RootDirectory.CreateFile(path);

            file.ShouldNotBeNull();

            return(this.OpenFileStream(path, FileMode.Open, (FileAccess)NativeMethods.FileAccess.FILE_GENERIC_READ, FileShare.Read, callFlushFileBuffers: false));
        }
Ejemplo n.º 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);
        }