C# Класс System.IO.Abstractions.TestingHelpers.MockFile

Наследование: FileBase
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
AppendAllLines ( string path, IEnumerable contents ) : void
AppendAllLines ( string path, IEnumerable contents, Encoding encoding ) : void
AppendAllText ( string path, string contents ) : void
AppendAllText ( string path, string contents, Encoding encoding ) : void
AppendText ( string path ) : StreamWriter
Copy ( string sourceFileName, string destFileName ) : void
Copy ( string sourceFileName, string destFileName, bool overwrite ) : void
Create ( string path ) : Stream
Create ( string path, int bufferSize ) : Stream
Create ( string path, int bufferSize, FileOptions options ) : Stream
Create ( string path, int bufferSize, FileOptions options, FileSecurity fileSecurity ) : Stream
CreateText ( string path ) : StreamWriter
Decrypt ( string path ) : void
Delete ( string path ) : void
Encrypt ( string path ) : void
Exists ( string path ) : bool
GetAccessControl ( string path ) : FileSecurity
GetAccessControl ( string path, AccessControlSections includeSections ) : FileSecurity
GetAttributes ( string path ) : FileAttributes

Gets the FileAttributes of the file on the path.

GetCreationTime ( string path ) : DateTime
GetCreationTimeUtc ( string path ) : DateTime
GetLastAccessTime ( string path ) : DateTime
GetLastAccessTimeUtc ( string path ) : DateTime
GetLastWriteTime ( string path ) : DateTime
GetLastWriteTimeUtc ( string path ) : DateTime
MockFile ( IMockFileDataAccessor mockFileDataAccessor ) : System.Collections.Generic
Move ( string sourceFileName, string destFileName ) : void
Open ( string path, FileMode mode ) : Stream
Open ( string path, FileMode mode, FileAccess access ) : Stream
Open ( string path, FileMode mode, FileAccess access, FileShare share ) : Stream
OpenRead ( string path ) : Stream
OpenText ( string path ) : StreamReader
OpenWrite ( string path ) : Stream
ReadAllBytes ( string path ) : byte[]
ReadAllLines ( string path ) : string[]
ReadAllLines ( string path, Encoding encoding ) : string[]
ReadAllText ( string path ) : string
ReadAllText ( string path, Encoding encoding ) : string
ReadLines ( string path ) : IEnumerable
ReadLines ( string path, Encoding encoding ) : IEnumerable
Replace ( string sourceFileName, string destinationFileName, string destinationBackupFileName ) : void
Replace ( string sourceFileName, string destinationFileName, string destinationBackupFileName, bool ignoreMetadataErrors ) : void
SetAccessControl ( string path, FileSecurity fileSecurity ) : void
SetAttributes ( string path, FileAttributes fileAttributes ) : void
SetCreationTime ( string path, DateTime creationTime ) : void
SetCreationTimeUtc ( string path, DateTime creationTimeUtc ) : void
SetLastAccessTime ( string path, DateTime lastAccessTime ) : void
SetLastAccessTimeUtc ( string path, DateTime lastAccessTimeUtc ) : void
SetLastWriteTime ( string path, DateTime lastWriteTime ) : void
SetLastWriteTimeUtc ( string path, DateTime lastWriteTimeUtc ) : void
WriteAllBytes ( string path, byte bytes ) : void

Creates a new file, writes the specified byte array to the file, and then closes the file. If the target file already exists, it is overwritten.

Given a byte array and a file path, this method opens the specified file, writes the contents of the byte array to the file, and then closes the file.

WriteAllLines ( string path, IEnumerable contents ) : void

Creates a new file, writes a collection of strings to the file, and then closes the file.

If the target file already exists, it is overwritten.

You can use this method to create the contents for a collection class that takes an IEnumerable{T} in its constructor, such as a List{T}, HashSet{T}, or a SortedSet{T} class.

WriteAllLines ( string path, IEnumerable contents, Encoding encoding ) : void

Creates a new file by using the specified encoding, writes a collection of strings to the file, and then closes the file.

If the target file already exists, it is overwritten.

You can use this method to create a file that contains the following: The results of a LINQ to Objects query on the lines of a file, as obtained by using the ReadLines method. The contents of a collection that implements an IEnumerable{T} of strings.

WriteAllLines ( string path, string contents ) : void

Creates a new file, writes the specified string array to the file by using the specified encoding, and then closes the file.

If the target file already exists, it is overwritten.

The default behavior of the WriteAllLines method is to write out data using UTF-8 encoding without a byte order mark (BOM). If it is necessary to include a UTF-8 identifier, such as a byte order mark, at the beginning of a file, use the FileBase.WriteAllLines(string,string[],System.Text.Encoding) method overload with UTF8Encoding encoding.

Given a string array and a file path, this method opens the specified file, writes the string array to the file using the specified encoding, and then closes the file.

WriteAllLines ( string path, string contents, Encoding encoding ) : void

Creates a new file, writes the specified string array to the file by using the specified encoding, and then closes the file.

If the target file already exists, it is overwritten.

Given a string array and a file path, this method opens the specified file, writes the string array to the file using the specified encoding, and then closes the file.

WriteAllText ( string path, string contents ) : void

Creates a new file, writes the specified string to the file using the specified encoding, and then closes the file. If the target file already exists, it is overwritten.

This method uses UTF-8 encoding without a Byte-Order Mark (BOM), so using the M:Encoding.GetPreamble method will return an empty byte array. If it is necessary to include a UTF-8 identifier, such as a byte order mark, at the beginning of a file, use the FileBase.WriteAllText(string,string,System.Text.Encoding) method overload with UTF8Encoding encoding.

Given a string and a file path, this method opens the specified file, writes the string to the file, and then closes the file.

WriteAllText ( string path, string contents, Encoding encoding ) : void

Creates a new file, writes the specified string to the file using the specified encoding, and then closes the file. If the target file already exists, it is overwritten.

Given a string and a file path, this method opens the specified file, writes the string to the file using the specified encoding, and then closes the file. The file handle is guaranteed to be closed by this method, even if exceptions are raised.

Приватные методы

Метод Описание
GetTimeFromFile ( string path, DateTime>.Func existingFileFunction, Func nonExistingFileFunction ) : DateTime
ReadAllBytes ( byte contents, Encoding encoding ) : string
ReadAllTextInternal ( string path, Encoding encoding ) : string
VerifyDirectoryExists ( string path ) : void
VerifyValueIsNotNull ( object value, string parameterName ) : void

Описание методов

AppendAllLines() публичный Метод

public AppendAllLines ( string path, IEnumerable contents ) : void
path string
contents IEnumerable
Результат void

AppendAllLines() публичный Метод

public AppendAllLines ( string path, IEnumerable contents, Encoding encoding ) : void
path string
contents IEnumerable
encoding System.Text.Encoding
Результат void

AppendAllText() публичный Метод

public AppendAllText ( string path, string contents ) : void
path string
contents string
Результат void

AppendAllText() публичный Метод

public AppendAllText ( string path, string contents, Encoding encoding ) : void
path string
contents string
encoding System.Text.Encoding
Результат void

AppendText() публичный Метод

public AppendText ( string path ) : StreamWriter
path string
Результат StreamWriter

Copy() публичный Метод

public Copy ( string sourceFileName, string destFileName ) : void
sourceFileName string
destFileName string
Результат void

Copy() публичный Метод

public Copy ( string sourceFileName, string destFileName, bool overwrite ) : void
sourceFileName string
destFileName string
overwrite bool
Результат void

Create() публичный Метод

public Create ( string path ) : Stream
path string
Результат Stream

Create() публичный Метод

public Create ( string path, int bufferSize ) : Stream
path string
bufferSize int
Результат Stream

Create() публичный Метод

public Create ( string path, int bufferSize, FileOptions options ) : Stream
path string
bufferSize int
options FileOptions
Результат Stream

Create() публичный Метод

public Create ( string path, int bufferSize, FileOptions options, FileSecurity fileSecurity ) : Stream
path string
bufferSize int
options FileOptions
fileSecurity System.Security.AccessControl.FileSecurity
Результат Stream

CreateText() публичный Метод

public CreateText ( string path ) : StreamWriter
path string
Результат StreamWriter

Decrypt() публичный Метод

public Decrypt ( string path ) : void
path string
Результат void

Delete() публичный Метод

public Delete ( string path ) : void
path string
Результат void

Encrypt() публичный Метод

public Encrypt ( string path ) : void
path string
Результат void

Exists() публичный Метод

public Exists ( string path ) : bool
path string
Результат bool

GetAccessControl() публичный Метод

public GetAccessControl ( string path ) : FileSecurity
path string
Результат System.Security.AccessControl.FileSecurity

GetAccessControl() публичный Метод

public GetAccessControl ( string path, AccessControlSections includeSections ) : FileSecurity
path string
includeSections AccessControlSections
Результат System.Security.AccessControl.FileSecurity

GetAttributes() публичный Метод

Gets the FileAttributes of the file on the path.
is empty, contains only white spaces, or contains invalid characters. The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. is in an invalid format. represents a file and is invalid, such as being on an unmapped drive, or the file cannot be found. represents a directory and is invalid, such as being on an unmapped drive, or the directory cannot be found. This file is being used by another process. The caller does not have the required permission.
public GetAttributes ( string path ) : FileAttributes
path string The path to the file.
Результат FileAttributes

GetCreationTime() публичный Метод

public GetCreationTime ( string path ) : DateTime
path string
Результат DateTime

GetCreationTimeUtc() публичный Метод

public GetCreationTimeUtc ( string path ) : DateTime
path string
Результат DateTime

GetLastAccessTime() публичный Метод

public GetLastAccessTime ( string path ) : DateTime
path string
Результат DateTime

GetLastAccessTimeUtc() публичный Метод

public GetLastAccessTimeUtc ( string path ) : DateTime
path string
Результат DateTime

GetLastWriteTime() публичный Метод

public GetLastWriteTime ( string path ) : DateTime
path string
Результат DateTime

GetLastWriteTimeUtc() публичный Метод

public GetLastWriteTimeUtc ( string path ) : DateTime
path string
Результат DateTime

MockFile() публичный Метод

public MockFile ( IMockFileDataAccessor mockFileDataAccessor ) : System.Collections.Generic
mockFileDataAccessor IMockFileDataAccessor
Результат System.Collections.Generic

Move() публичный Метод

public Move ( string sourceFileName, string destFileName ) : void
sourceFileName string
destFileName string
Результат void

Open() публичный Метод

public Open ( string path, FileMode mode ) : Stream
path string
mode FileMode
Результат Stream

Open() публичный Метод

public Open ( string path, FileMode mode, FileAccess access ) : Stream
path string
mode FileMode
access FileAccess
Результат Stream

Open() публичный Метод

public Open ( string path, FileMode mode, FileAccess access, FileShare share ) : Stream
path string
mode FileMode
access FileAccess
share FileShare
Результат Stream

OpenRead() публичный Метод

public OpenRead ( string path ) : Stream
path string
Результат Stream

OpenText() публичный Метод

public OpenText ( string path ) : StreamReader
path string
Результат StreamReader

OpenWrite() публичный Метод

public OpenWrite ( string path ) : Stream
path string
Результат Stream

ReadAllBytes() публичный Метод

public ReadAllBytes ( string path ) : byte[]
path string
Результат byte[]

ReadAllLines() публичный Метод

public ReadAllLines ( string path ) : string[]
path string
Результат string[]

ReadAllLines() публичный Метод

public ReadAllLines ( string path, Encoding encoding ) : string[]
path string
encoding System.Text.Encoding
Результат string[]

ReadAllText() публичный Метод

public ReadAllText ( string path ) : string
path string
Результат string

ReadAllText() публичный Метод

public ReadAllText ( string path, Encoding encoding ) : string
path string
encoding System.Text.Encoding
Результат string

ReadLines() публичный Метод

public ReadLines ( string path ) : IEnumerable
path string
Результат IEnumerable

ReadLines() публичный Метод

public ReadLines ( string path, Encoding encoding ) : IEnumerable
path string
encoding System.Text.Encoding
Результат IEnumerable

Replace() публичный Метод

public Replace ( string sourceFileName, string destinationFileName, string destinationBackupFileName ) : void
sourceFileName string
destinationFileName string
destinationBackupFileName string
Результат void

Replace() публичный Метод

public Replace ( string sourceFileName, string destinationFileName, string destinationBackupFileName, bool ignoreMetadataErrors ) : void
sourceFileName string
destinationFileName string
destinationBackupFileName string
ignoreMetadataErrors bool
Результат void

SetAccessControl() публичный Метод

public SetAccessControl ( string path, FileSecurity fileSecurity ) : void
path string
fileSecurity System.Security.AccessControl.FileSecurity
Результат void

SetAttributes() публичный Метод

public SetAttributes ( string path, FileAttributes fileAttributes ) : void
path string
fileAttributes FileAttributes
Результат void

SetCreationTime() публичный Метод

public SetCreationTime ( string path, DateTime creationTime ) : void
path string
creationTime DateTime
Результат void

SetCreationTimeUtc() публичный Метод

public SetCreationTimeUtc ( string path, DateTime creationTimeUtc ) : void
path string
creationTimeUtc DateTime
Результат void

SetLastAccessTime() публичный Метод

public SetLastAccessTime ( string path, DateTime lastAccessTime ) : void
path string
lastAccessTime DateTime
Результат void

SetLastAccessTimeUtc() публичный Метод

public SetLastAccessTimeUtc ( string path, DateTime lastAccessTimeUtc ) : void
path string
lastAccessTimeUtc DateTime
Результат void

SetLastWriteTime() публичный Метод

public SetLastWriteTime ( string path, DateTime lastWriteTime ) : void
path string
lastWriteTime DateTime
Результат void

SetLastWriteTimeUtc() публичный Метод

public SetLastWriteTimeUtc ( string path, DateTime lastWriteTimeUtc ) : void
path string
lastWriteTimeUtc DateTime
Результат void

WriteAllBytes() публичный Метод

Creates a new file, writes the specified byte array to the file, and then closes the file. If the target file already exists, it is overwritten.
Given a byte array and a file path, this method opens the specified file, writes the contents of the byte array to the file, and then closes the file.
is a zero-length string, contains only white space, or contains one or more invalid characters as defined by . is or contents is empty. /// The specified path, file name, or both exceed the system-defined maximum length. /// For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. /// The specified path is invalid (for example, it is on an unmapped drive). An I/O error occurred while opening the file. /// path specified a file that is read-only. /// -or- /// This operation is not supported on the current platform. /// -or- /// path specified a directory. /// -or- /// The caller does not have the required permission. /// The file specified in was not found. is in an invalid format. The caller does not have the required permission.
public WriteAllBytes ( string path, byte bytes ) : void
path string The file to write to.
bytes byte The bytes to write to the file.
Результат void

WriteAllLines() публичный Метод

Creates a new file, writes a collection of strings to the file, and then closes the file.

If the target file already exists, it is overwritten.

You can use this method to create the contents for a collection class that takes an IEnumerable{T} in its constructor, such as a List{T}, HashSet{T}, or a SortedSet{T} class.

is a zero-length string, contains only white space, or contains one or more invalid characters as defined by . Either or is . The specified path is invalid (for example, it is on an unmapped drive). The file specified in was not found. An I/O error occurred while opening the file. /// The specified path, file name, or both exceed the system-defined maximum length. /// For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. /// is in an invalid format. The caller does not have the required permission. /// specified a file that is read-only. /// -or- /// This operation is not supported on the current platform. /// -or- /// specified a directory. /// -or- /// The caller does not have the required permission. ///
public WriteAllLines ( string path, IEnumerable contents ) : void
path string The file to write to.
contents IEnumerable The lines to write to the file.
Результат void

WriteAllLines() публичный Метод

Creates a new file by using the specified encoding, writes a collection of strings to the file, and then closes the file.

If the target file already exists, it is overwritten.

You can use this method to create a file that contains the following: The results of a LINQ to Objects query on the lines of a file, as obtained by using the ReadLines method. The contents of a collection that implements an IEnumerable{T} of strings.

is a zero-length string, contains only white space, or contains one or more invalid characters as defined by . Either , , or is . The specified path is invalid (for example, it is on an unmapped drive). The file specified in was not found. An I/O error occurred while opening the file. /// The specified path, file name, or both exceed the system-defined maximum length. /// For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. /// is in an invalid format. The caller does not have the required permission. /// specified a file that is read-only. /// -or- /// This operation is not supported on the current platform. /// -or- /// specified a directory. /// -or- /// The caller does not have the required permission. ///
public WriteAllLines ( string path, IEnumerable contents, Encoding encoding ) : void
path string The file to write to.
contents IEnumerable The lines to write to the file.
encoding System.Text.Encoding The character encoding to use.
Результат void

WriteAllLines() публичный Метод

Creates a new file, writes the specified string array to the file by using the specified encoding, and then closes the file.

If the target file already exists, it is overwritten.

The default behavior of the WriteAllLines method is to write out data using UTF-8 encoding without a byte order mark (BOM). If it is necessary to include a UTF-8 identifier, such as a byte order mark, at the beginning of a file, use the FileBase.WriteAllLines(string,string[],System.Text.Encoding) method overload with UTF8Encoding encoding.

Given a string array and a file path, this method opens the specified file, writes the string array to the file using the specified encoding, and then closes the file.

is a zero-length string, contains only white space, or contains one or more invalid characters as defined by . Either or is . /// The specified path, file name, or both exceed the system-defined maximum length. /// For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. /// The specified path is invalid (for example, it is on an unmapped drive). An I/O error occurred while opening the file. /// specified a file that is read-only. /// -or- /// This operation is not supported on the current platform. /// -or- /// specified a directory. /// -or- /// The caller does not have the required permission. /// The file specified in was not found. is in an invalid format. The caller does not have the required permission.
public WriteAllLines ( string path, string contents ) : void
path string The file to write to.
contents string The string array to write to the file.
Результат void

WriteAllLines() публичный Метод

Creates a new file, writes the specified string array to the file by using the specified encoding, and then closes the file.

If the target file already exists, it is overwritten.

Given a string array and a file path, this method opens the specified file, writes the string array to the file using the specified encoding, and then closes the file.

is a zero-length string, contains only white space, or contains one or more invalid characters as defined by . Either or is . /// The specified path, file name, or both exceed the system-defined maximum length. /// For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. /// The specified path is invalid (for example, it is on an unmapped drive). An I/O error occurred while opening the file. /// specified a file that is read-only. /// -or- /// This operation is not supported on the current platform. /// -or- /// specified a directory. /// -or- /// The caller does not have the required permission. /// The file specified in was not found. is in an invalid format. The caller does not have the required permission.
public WriteAllLines ( string path, string contents, Encoding encoding ) : void
path string The file to write to.
contents string The string array to write to the file.
encoding System.Text.Encoding An object that represents the character encoding applied to the string array.
Результат void

WriteAllText() публичный Метод

Creates a new file, writes the specified string to the file using the specified encoding, and then closes the file. If the target file already exists, it is overwritten.
This method uses UTF-8 encoding without a Byte-Order Mark (BOM), so using the M:Encoding.GetPreamble method will return an empty byte array. If it is necessary to include a UTF-8 identifier, such as a byte order mark, at the beginning of a file, use the FileBase.WriteAllText(string,string,System.Text.Encoding) method overload with UTF8Encoding encoding.

Given a string and a file path, this method opens the specified file, writes the string to the file, and then closes the file.

is a zero-length string, contains only white space, or contains one or more invalid characters as defined by . is or contents is empty. /// The specified path, file name, or both exceed the system-defined maximum length. /// For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. /// The specified path is invalid (for example, it is on an unmapped drive). An I/O error occurred while opening the file. /// path specified a file that is read-only. /// -or- /// This operation is not supported on the current platform. /// -or- /// path specified a directory. /// -or- /// The caller does not have the required permission. /// The file specified in was not found. is in an invalid format. The caller does not have the required permission.
public WriteAllText ( string path, string contents ) : void
path string The file to write to.
contents string The string to write to the file.
Результат void

WriteAllText() публичный Метод

Creates a new file, writes the specified string to the file using the specified encoding, and then closes the file. If the target file already exists, it is overwritten.
Given a string and a file path, this method opens the specified file, writes the string to the file using the specified encoding, and then closes the file. The file handle is guaranteed to be closed by this method, even if exceptions are raised.
is a zero-length string, contains only white space, or contains one or more invalid characters as defined by . is or contents is empty. /// The specified path, file name, or both exceed the system-defined maximum length. /// For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. /// The specified path is invalid (for example, it is on an unmapped drive). An I/O error occurred while opening the file. /// path specified a file that is read-only. /// -or- /// This operation is not supported on the current platform. /// -or- /// path specified a directory. /// -or- /// The caller does not have the required permission. /// The file specified in was not found. is in an invalid format. The caller does not have the required permission.
public WriteAllText ( string path, string contents, Encoding encoding ) : void
path string The file to write to.
contents string The string to write to the file.
encoding System.Text.Encoding The encoding to apply to the string.
Результат void