public sealed class RunicTestFileDialogs : IFileDialogs Scripted IFileDialogs for tests: each dialog takes the next queued response, hands out in-memory RunicTestFile leases that follow the real lease and commit rules, and records its options.
Remarks
Queue a response before the action that shows the dialog: RunicTestFileDialogs.EnqueueOpen for an open-file or open-document dialog, RunicTestFileDialogs.EnqueueSave for a save dialog, RunicTestFileDialogs.EnqueueOpenDirectory, or RunicTestFileDialogs.EnqueueDismissed, RunicTestFileDialogs.EnqueueUnavailable and RunicTestFileDialogs.EnqueueFailed for any dialog. A dialog shown with an empty queue is dismissed. A response that does not fit the dialog, such as a save destination for an open dialog, throws InvalidOperationException from the dialog call, so a test sees the wrong dialog at once.
The dialogs check their options as the real providers do. When the test window closes, the dialogs report PlatformUnavailableReason.OwnerClosed and release every lease they handed out. The type is safe to use from any thread.
Properties
Calls
public IReadOnlyList<RunicFileDialogCall> Calls { get; } The dialogs shown so far, oldest first.
Pending
public int Pending { get; } The number of responses still queued.
Methods
EnqueueDismissed
public void EnqueueDismissed() Queues a dismissal: the next dialog of any kind reports Dismissed.
EnqueueFailed
public void EnqueueFailed(PlatformFailureCode code) Queues a failure for the next dialog of any kind.
Parameters
codeThe failure it reports.
EnqueueOpen
public RunicTestFile EnqueueOpen(RunicTestFile file) Queues the selection of an existing file for the next open-file, open-files or open-document dialog.
Parameters
fileThe selected file.
Returns
The file, to check later.
EnqueueOpen
public RunicTestFile EnqueueOpen(RunicTestFile file, FileDialogFilter? selectedFilter) Queues the selection of an existing file with the filter the dialog reports as active.
Parameters
fileThe selected file.
selectedFilterThe filter the dialog reports as active, one of the options' filters, or
null.
Returns
The file, to check later.
EnqueueOpen
public RunicTestFile EnqueueOpen(string name, ReadOnlySpan<byte> content) Queues the selection of a file with content for the next open dialog.
Parameters
nameThe file's display name.
contentIts bytes.
Returns
The file, to check later.
EnqueueOpen
public RunicTestFile EnqueueOpen(string name, string text) Queues the selection of a file with UTF-8 text for the next open dialog.
Parameters
nameThe file's display name.
textIts text.
Returns
The file, to check later.
EnqueueOpenDirectory
public void EnqueueOpenDirectory(params string[] paths) Queues the selection of directories for the next directory dialog.
Parameters
pathsFully qualified paths, one for an open-directory dialog; nothing checks that they exist.
EnqueueOpenFiles
public void EnqueueOpenFiles(params RunicTestFile[] files) Queues the selection of several files for the next open-files dialog.
Parameters
filesThe selected files, in the order the dialog returns them; at least one.
EnqueueSave
public RunicTestFile EnqueueSave(string name) Queues a new save destination for the next save-file or save-document dialog.
Parameters
nameThe name the user chose.
Returns
The destination, which does not exist until the first committed write.
EnqueueSave
public RunicTestFile EnqueueSave(RunicTestFile file) Queues a save destination, such as an existing file the user replaces, for the next save dialog.
Parameters
fileThe destination.
Returns
The destination.
EnqueueSave
public RunicTestFile EnqueueSave(RunicTestFile file, FileDialogFilter? selectedFilter) Queues a save destination with the filter the dialog reports as active.
Parameters
fileThe destination.
selectedFilterThe filter the dialog reports as active, or
null.
Returns
The destination.
EnqueueUnavailable
public void EnqueueUnavailable(PlatformUnavailableReason reason) Queues unavailability for the next dialog of any kind.
Parameters
reasonThe reason it reports.
OpenDirectoriesAsync
public ValueTask<PickerResult<IDirectoryLeaseList>> OpenDirectoriesAsync(OpenDirectoryOptions options, CancellationToken cancellationToken = default) Selects one or more directories and acquires access to each for C# filesystem operations.
Remarks
Each lease keeps its directory's access, as IFileDialogs.OpenDirectoryAsync does, until it, the list or the presentation is disposed. The default implementation returns Unavailable with PlatformUnavailableReason.BackendUnavailable; a provider that implements multiple directory selection overrides it and reports the platform.directories.openMultiple capability.
Documentation from IFileDialogs.OpenDirectoriesAsync.
OpenDirectoryAsync
public ValueTask<PickerResult<IDirectoryLease>> OpenDirectoryAsync(OpenDirectoryOptions options, CancellationToken cancellationToken = default) Selects directory access for C# filesystem operations. A provider without directory selection reports unavailable.
Remarks
The default implementation returns Unavailable with PlatformUnavailableReason.BackendUnavailable. A provider that implements directory selection overrides this method and also reports that support through its capability declaration, such as IPickerBackend.SupportsDirectorySelection in Runic.Platform.Runtime.
Documentation from IFileDialogs.OpenDirectoryAsync.
OpenDocumentAsync
public ValueTask<PickerResult<IDocumentFileLease>> OpenDocumentAsync(OpenFileOptions options, CancellationToken cancellationToken = default) Selects an existing document for reading and saving back to it.
Remarks
Unlike IFileDialogs.OpenFileAsync, which opens the file once for reading, the lease reads the document again on each IDocumentFileLease.OpenReadAsync and writes it through ISaveFileLease.BeginWriteAsync. Whether those writes can replace the file is reported by the platform.files.save capability; a read-only grant reports PlatformUnavailableReason.AtomicReplaceUnavailable per write. The default implementation returns Unavailable with PlatformUnavailableReason.BackendUnavailable; a provider that implements it overrides it and reports the platform.files.openDocument capability.
Documentation from IFileDialogs.OpenDocumentAsync.
OpenFileAsync
public ValueTask<PickerResult<IReadFileLease>> OpenFileAsync(OpenFileOptions options, CancellationToken cancellationToken = default) Selects and acquires a single-use read lease.
Documentation from IFileDialogs.OpenFileAsync.
OpenFilesAsync
public ValueTask<PickerResult<IReadFileLeaseList>> OpenFilesAsync(OpenFileOptions options, CancellationToken cancellationToken = default) Selects one or more files and acquires a single-use read lease for each.
Remarks
The selection is all or nothing: if any selected file cannot be opened, every acquired lease is released and the result is Failed. Each lease holds an open file until it or the list is disposed. The default implementation returns Unavailable with PlatformUnavailableReason.BackendUnavailable; a provider that implements multiple selection overrides it and reports the platform.files.openMultiple capability.
Documentation from IFileDialogs.OpenFilesAsync.
SaveDocumentAsync
public ValueTask<PickerResult<IDocumentFileLease>> SaveDocumentAsync(SaveFileOptions options, CancellationToken cancellationToken = default) Selects a save destination, as IFileDialogs.SaveFileAsync does, as a document the application can read back and save again, such as for Save As.
Exceptions
ArgumentExceptionThe suggested name is empty or a path.
Remarks
The document does not exist until the first committed write: until then IDocumentFileLease.OpenReadAsync reports PlatformFailureCode.NotFound. The default implementation returns Unavailable with PlatformUnavailableReason.BackendUnavailable; a provider that implements it overrides it and reports the platform.files.openDocument capability.
Documentation from IFileDialogs.SaveDocumentAsync.
SaveFileAsync
public ValueTask<PickerResult<ISaveFileLease>> SaveFileAsync(SaveFileOptions options, CancellationToken cancellationToken = default) Selects and acquires a save destination.
Documentation from IFileDialogs.SaveFileAsync.