public sealed class RunicTestFile An in-memory file that RunicTestFileDialogs hands out: the selection of an open dialog or the destination of a save dialog. It is never on disk.
Remarks
Leases follow the rules of the real ones: a commit replaces the content only when the file still holds what the application last saw, so RunicTestFile.Write or RunicTestFile.Delete during a test acts as another writer and makes the next commit report PlatformFailureCode.Conflict.
RunicTestFile.LocalPath is a fully qualified path that does not exist; read and write the file through its lease or through this object. The type is safe to use from any thread.
Constructors
RunicTestFile
public RunicTestFile(string name, ReadOnlySpan<byte> content) Creates a file with content, as an existing file the user selects.
Parameters
nameThe display name, a filename without a path.
contentThe file's bytes.
Exceptions
ArgumentExceptionnameis empty or contains a path separator.
Properties
CommittedWrites
public IReadOnlyList<ImmutableArray<byte>> CommittedWrites { get; } The bytes of each committed write, oldest first.
DisplayName
public string DisplayName { get; } The display name, without a path.
Exists
public bool Exists { get; } Whether the file exists: it was created with content or a commit or RunicTestFile.Write created it.
LocalPath
public string LocalPath { get; } A fully qualified path that the file's document leases report; nothing exists there.
WriteUnavailable
public PlatformUnavailableReason? WriteUnavailable { get; set; } Whether a lease of the file can begin a write: null, the default, lets it write; PlatformUnavailableReason.AtomicReplaceUnavailable acts as a read-only grant.
Remarks
ISaveFileLease.BeginWriteAsync then reports this reason.
Methods
Delete
public void Delete() Deletes the file as another application would.
EnqueueCommitResult
public void EnqueueCommitResult(FileCommitResult result) Scripts the outcome of the next commit that finds no conflict.
Parameters
resultNotCommittedleaves the file unchanged;CommitUnknownalso leaves it unchanged (useRunicTestFile.EnqueueCommitResultfor one that landed), and the lease then accepts both the previous and the staged bytes as its own, as a real lease does;Committedcommits as an unscripted commit would.
EnqueueCommitResult
public void EnqueueCommitResult(FileCommitResult result, bool applied) Scripts the outcome of the next commit that finds no conflict, and whether its write landed.
Parameters
resultThe reported outcome.
appliedWhether the staged bytes replace the content. A real lease reports
CommitUnknownexactly when the write may have landed, so both values are valid for it;CommittedrequirestrueandNotCommittedfalse.
Exceptions
ArgumentExceptionappliedcontradictsresult.
FromText
public static RunicTestFile FromText(string name, string text) Creates a file whose content is text in UTF-8, without a byte order mark.
Parameters
nameThe display name, a filename without a path.
textThe file's text.
Returns
The file.
Missing
public static RunicTestFile Missing(string name) Creates a file that does not exist yet, such as a new save destination.
Parameters
nameThe display name, a filename without a path.
Returns
The absent file.
ReadAllBytes
public byte[] ReadAllBytes() A copy of the file's current bytes.
Returns
The bytes.
Exceptions
FileNotFoundExceptionThe file does not exist.
ReadAllText
public string ReadAllText() The file's current content as UTF-8 text.
Returns
The text.
Exceptions
FileNotFoundExceptionThe file does not exist.
Write
public void Write(ReadOnlySpan<byte> content) Replaces the content as another writer would, so the next commit of a lease reports a conflict.
Parameters
contentThe new bytes.
WriteText
public void WriteText(string text) Replaces the content with UTF-8 text as another writer would.
Parameters
textThe new text.