Skip to main content

aweXpect.Testably

aweXpect.Testably contains expectations for the file system and time system mocks from Testably.Abstractions. It is an extension for aweXpect.

Installation​

dotnet add package 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:

ExpectationNegatedSummary
HasFileDoesNotHaveFilecontains the file, optionally with its content and timestamps
HasDirectoryDoesNotHaveDirectorycontains the directory, optionally with its files and subdirectories
HasDriveDoesNotHaveDrivecontains the drive

Expectations for IFileInfo:

ExpectationNegatedSummary
ExistsDoesNotExistthe file exists
HasNamehas the expected name
HasExtensionhas the expected extension
HasLengthhas the expected length
HasContentHasContent().NotEqualTohas the expected string or binary content
IsReadOnlyIsNotReadOnlythe file is read-only
HasAttributeDoesNotHaveAttributehas the attribute flag
HasCreationTimehas the expected creation time, optionally within a tolerance
HasLastAccessTimehas the expected last access time, optionally within a tolerance
HasLastWriteTimehas the expected last write time, optionally within a tolerance
WhoseParentthe containing directory meets expectations (.NET 10 or later)

Expectations for IDirectoryInfo:

ExpectationNegatedSummary
ExistsDoesNotExistthe directory exists
HasNamehas the expected name
IsEmptyIsNotEmptycontains no files or subdirectories
HasFileDoesNotHaveFilecontains the file
HasDirectoryDoesNotHaveDirectorycontains the subdirectory
HasAttributeDoesNotHaveAttributehas the attribute flag
HasCreationTimehas the expected creation time, optionally within a tolerance
HasLastAccessTimehas the expected last access time, optionally within a tolerance
HasLastWriteTimehas the expected last write time, optionally within a tolerance
WhoseParentthe parent directory meets expectations (.NET 10 or later)

Expectations for IDriveInfo:

ExpectationNegatedSummary
IsReadyIsNotReadythe drive is ready
HasNamehas the expected name
HasVolumeLabelhas the expected volume label
HasDriveFormathas the expected drive format
HasDriveTypehas the expected drive type
HasTotalSizehas the expected total size
HasTotalFreeSpacehas the expected total free space
HasAvailableFreeSpacehas the expected available free space

Expectations for IFileVersionInfo:

ExpectationNegatedSummary
HasCompanyName, HasFileMajorPart, IsDebug, …IsNotDebug, …one expectation per property

Expectations for MockFileSystem:

ExpectationNegatedSummary
TriggeredNotificationDidNotTriggerNotificationthe file system raised a matching notification

Expectations for IFileSystemWatcher:

ExpectationNegatedSummary
TriggeredDidNotTriggerthe watcher raised a matching event

Expectations for ChangeDescription:

ExpectationNegatedSummary
HasChangeTypeDoesNotHaveChangeTypehas the change type flag
HasFileSystemTypeDoesNotHaveFileSystemTypehas the file system type flag
HasNotifyFiltersDoesNotHaveNotifyFiltershas the notify filters flag
HasNamehas the expected name
HasPathhas the expected path
HasOldNamehas the expected old name of a renamed file or directory
HasOldPathhas the expected old path of a renamed file or directory

Expectations for IFileSystemStatistics:

ExpectationNegatedSummary
Recorded.Never()a method was called or a property was accessed

Expectations for ITimerMock:

ExpectationNegatedSummary
Executed.Never()the timer callback was executed