Expectations for the file system and time system mocks from Testably.Abstractions for aweXpect.
using aweXpect.Chronology; // from the aweXpect.Chronology package
MockFileSystem fileSystem = new();
fileSystem.File.WriteAllText("let-it-be.txt", "let it be");
// verify that a file exists, together with its content
await Expect.That(fileSystem).HasFile("let-it-be.txt").WithContent("LET IT BE").IgnoringCase();
// verify the properties of the found file
await Expect.That(fileSystem).HasFile("let-it-be.txt").Which.HasLength(9);
// verify that a file does not exist
await Expect.That(fileSystem).DoesNotHaveFile("yesterday.txt");
// verify the notifications the file system raised
await Expect.That(fileSystem).TriggeredNotification(c => c.Name == "let-it-be.txt");
// verify the method calls the file system recorded
await Expect.That(fileSystem.Statistics).Recorded().File.WriteAllText().Once();
// verify how often the callback of a timer from a MockTimeSystem was executed
MockTimeSystem timeSystem = new();
ITimerMock timer = (ITimerMock)timeSystem.Timer.New(_ => { }, null, TimeSpan.Zero, 10.Milliseconds());
await Expect.That(timer).Executed().AtLeast(3.Times()).Within(5.Seconds());A failing expectation on the file system names the path it looked for. If the file was never written,
HasFile("yesterday.txt") would fail with:
Expected that fileSystem
has file "yesterday.txt",
but it did not exist
Expectations for IFileSystem:
| Expectation | Negated | Summary |
|---|---|---|
HasFile |
DoesNotHaveFile |
contains the file, optionally with its content and timestamps |
HasDirectory |
DoesNotHaveDirectory |
contains the directory, optionally with its files and subdirectories |
HasDrive |
DoesNotHaveDrive |
contains the drive |
Expectations for IFileInfo:
| Expectation | Negated | Summary |
|---|---|---|
Exists |
DoesNotExist |
the file exists |
HasName |
has the expected name | |
HasExtension |
has the expected extension | |
HasLength |
has the expected length | |
HasContent |
HasContent().NotEqualTo |
has the expected string or binary content |
IsReadOnly |
IsNotReadOnly |
the file is read-only |
HasAttribute |
DoesNotHaveAttribute |
has the attribute flag |
HasCreationTime |
has the expected creation time, optionally within a tolerance | |
HasLastAccessTime |
has the expected last access time, optionally within a tolerance | |
HasLastWriteTime |
has the expected last write time, optionally within a tolerance | |
WhoseParent |
the containing directory meets expectations (.NET 10 or later) |
Expectations for IDirectoryInfo:
| Expectation | Negated | Summary |
|---|---|---|
Exists |
DoesNotExist |
the directory exists |
HasName |
has the expected name | |
IsEmpty |
IsNotEmpty |
contains no files or subdirectories |
HasFile |
DoesNotHaveFile |
contains the file |
HasDirectory |
DoesNotHaveDirectory |
contains the subdirectory |
HasAttribute |
DoesNotHaveAttribute |
has the attribute flag |
HasCreationTime |
has the expected creation time, optionally within a tolerance | |
HasLastAccessTime |
has the expected last access time, optionally within a tolerance | |
HasLastWriteTime |
has the expected last write time, optionally within a tolerance | |
WhoseParent |
the parent directory meets expectations (.NET 10 or later) |
Expectations for IDriveInfo:
| Expectation | Negated | Summary |
|---|---|---|
IsReady |
IsNotReady |
the drive is ready |
HasName |
has the expected name | |
HasVolumeLabel |
has the expected volume label | |
HasDriveFormat |
has the expected drive format | |
HasDriveType |
has the expected drive type | |
HasTotalSize |
has the expected total size | |
HasTotalFreeSpace |
has the expected total free space | |
HasAvailableFreeSpace |
has the expected available free space |
Expectations for IFileVersionInfo:
| Expectation | Negated | Summary |
|---|---|---|
HasCompanyName, HasFileMajorPart, IsDebug, … |
IsNotDebug, … |
one expectation per property |
Expectations for MockFileSystem:
| Expectation | Negated | Summary |
|---|---|---|
TriggeredNotification |
DidNotTriggerNotification |
the file system raised a matching notification |
Expectations for IFileSystemWatcher:
| Expectation | Negated | Summary |
|---|---|---|
Triggered |
DidNotTrigger |
the watcher raised a matching event |
Expectations for ChangeDescription:
| Expectation | Negated | Summary |
|---|---|---|
HasChangeType |
DoesNotHaveChangeType |
has the change type flag |
HasFileSystemType |
DoesNotHaveFileSystemType |
has the file system type flag |
HasNotifyFilters |
DoesNotHaveNotifyFilters |
has the notify filters flag |
HasName |
has the expected name | |
HasPath |
has the expected path | |
HasOldName |
has the expected old name of a renamed file or directory | |
HasOldPath |
has the expected old path of a renamed file or directory |
Expectations for IFileSystemStatistics:
| Expectation | Negated | Summary |
|---|---|---|
Recorded |
.Never() |
a method was called or a property was accessed |
Expectations for ITimerMock:
| Expectation | Negated | Summary |
|---|---|---|
Executed |
.Never() |
the timer callback was executed |
The full documentation is available at docs.testably.org:
- File system: files, directories and drives of an
IFileSystem, and the expectations onIFileInfo,IDirectoryInfo,IDriveInfoandIFileVersionInfo - Notifications and recorded calls: file-system notifications, watcher events,
change descriptions and the calls recorded in
IFileSystemStatistics - Time system: the execution of
ITimerMocktimers