aweXpect.Testably
aweXpect.Testably contains expectations for the file system and time system mocks from Testably.Abstractions. It is an extension for aweXpect.
Installation
- .NET CLI
- PackageReference
- Central Package Management
dotnet add package aweXpect.Testably
<PackageReference Include="aweXpect.Testably" Version="3.0.0" />
Directory.Packages.props
<PackageVersion Include="aweXpect.Testably" Version="3.0.0" />
Project file
<PackageReference Include="aweXpect.Testably" />
It does not include aweXpect itself.
At a glance
using aweXpect.Chronology; // from the aweXpect.Chronology package
using static aweXpect.Expect;
MockFileSystem fileSystem = new();
fileSystem.File.WriteAllText("let-it-be.txt", "let it be");
// verify that a file exists, together with its content
await That(fileSystem).HasFile("let-it-be.txt").WithContent("LET IT BE").IgnoringCase();
// verify the properties of the found file
await That(fileSystem).HasFile("let-it-be.txt").Which.HasLength(9);
// verify that a file does not exist
await That(fileSystem).DoesNotHaveFile("yesterday.txt");
// verify the notifications the file system raised
await That(fileSystem).TriggeredNotification(c => c.Name == "let-it-be.txt");
// verify the method calls the file system recorded
await 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 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:
Failure message
Expected that fileSystem
has file "yesterday.txt",
but it did not exist
Overview
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 |