Skip to main content

aweXpect.Testably

Nuget

aweXpect.Testably contains expectations for the file and time system from Testably.Abstractions.

Overview​

SubjectExpectationNegatedSummary
IFileSystemHasFileDoesNotHaveFilecontains the file, with its content and timestamps
HasDirectoryDoesNotHaveDirectorycontains the directory, with its files and subdirectories
HasDriveDoesNotHaveDrivecontains the drive
IFileInfoExistsDoesNotExistthe file exists
HasName, HasExtension, HasLength, HasContenthas the expected name, extension, length or content
IsReadOnlyIsNotReadOnlythe file is read-only
HasAttributeDoesNotHaveAttributehas the attribute flag
HasCreationTime, HasLastAccessTime, HasLastWriteTimehas the expected timestamp, optionally within a tolerance
IDirectoryInfoExistsDoesNotExistthe directory exists
IsEmptyIsNotEmptythe directory contains no files or subdirectories
HasFile, HasDirectoryDoesNotHaveFile, DoesNotHaveDirectorycontains the file or subdirectory
HasName, HasAttribute, Has…TimeDoesNotHaveAttributesame as for IFileInfo
IDriveInfoIsReadyIsNotReadythe drive is ready
HasName, HasDriveFormat, HasDriveType, Has…Size, …has the expected property value
IFileVersionInfoHas…, Is…IsNot…one expectation per property
MockFileSystemTriggeredNotificationDidNotTriggerNotificationraised a matching change notification
IFileSystemWatcherTriggeredDidNotTriggerraised a matching event
ChangeDescriptionHasChangeType, HasFileSystemType, HasNotifyFiltersDoesNotHave…has the expected change flags
HasName, HasPath, HasOldName, HasOldPathhas the expected (old) name or path
IFileSystemStatisticsRecorded()a method was called or a property was accessed
ITimerMockExecutedthe timer callback was executed

The samples use the TimeSpan helpers (e.g. 5.Seconds()) from aweXpect.Chronology.

File system​

You can verify that a file exists in an IFileSystem, together with its content, and continue with the found IFileInfo:

IFileSystem fileSystem = new MockFileSystem();
fileSystem.File.WriteAllText("let-it-be.txt", "let it be");

await Expect.That(fileSystem).HasFile("let-it-be.txt").WithContent("LET IT BE").IgnoringCase();
await Expect.That(fileSystem).HasFile("let-it-be.txt").Which.HasLength(9);
await Expect.That(fileSystem).DoesNotHaveFile("yesterday.txt");

For example, Expect.That(fileSystem).HasFile("yesterday.txt") fails with:

Failure message
Expected that fileSystem
has file "yesterday.txt",
but it did not exist

Directories, drives and file version infos are covered in File system.

Notifications and recorded calls​

You can verify the notifications a MockFileSystem raised and the calls it recorded:

MockFileSystem fileSystem = new();
fileSystem.File.WriteAllText("let-it-be.txt", "let it be");

await Expect.That(fileSystem).TriggeredNotification(c => c.Name == "let-it-be.txt");
await Expect.That(fileSystem.Statistics).Recorded().File.WriteAllText().Once();

Waiting for asynchronous notifications, watcher events and filtering recorded calls are covered in Notifications and recorded calls.

Time system​

You can 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, TimeSpan.FromMilliseconds(10));

await Expect.That(timer).Executed().AtLeast(3.Times()).Within(5.Seconds());

See Time system for the details.

Documentation​

The full documentation is available at docs.testably.org:

  • File system: files, directories and drives of an IFileSystem, and the expectations on IFileInfo, IDirectoryInfo, IDriveInfo and IFileVersionInfo
  • Notifications and recorded calls: file-system notifications, watcher events, change descriptions and the calls recorded in IFileSystemStatistics
  • Time system: the execution of ITimerMock timers