Skip to content

About

Expectations for the file and time system from Testably.Abstractions

Resources

Code of conduct

Contributing

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

168 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aweXpect.Testably

Nuget Build Quality Gate Status Coverage Mutation testing badge

Expectations for the file system and time system mocks from Testably.Abstractions for aweXpect.

Overview

Subject Expectation Negated Summary
IFileSystem HasFile DoesNotHaveFile contains the file, with its content and timestamps
HasDirectory DoesNotHaveDirectory contains the directory, with its files and subdirectories
HasDrive DoesNotHaveDrive contains the drive
IFileInfo Exists DoesNotExist the file exists
HasName, HasExtension, HasLength, HasContent has the expected name, extension, length or content
IsReadOnly IsNotReadOnly the file is read-only
HasAttribute DoesNotHaveAttribute has the attribute flag
HasCreationTime, HasLastAccessTime, HasLastWriteTime has the expected timestamp, optionally within a tolerance
IDirectoryInfo Exists DoesNotExist the directory exists
IsEmpty IsNotEmpty the directory contains no files or subdirectories
HasFile, HasDirectory DoesNotHaveFile, DoesNotHaveDirectory contains the file or subdirectory
HasName, HasAttribute, Has…Time DoesNotHaveAttribute same as for IFileInfo
IDriveInfo IsReady IsNotReady the drive is ready
HasName, HasDriveFormat, HasDriveType, Has…Size, … has the expected property value
IFileVersionInfo Has…, Is… IsNot… one expectation per property
MockFileSystem TriggeredNotification DidNotTriggerNotification raised a matching change notification
IFileSystemWatcher Triggered DidNotTrigger raised a matching event
ChangeDescription HasChangeType, HasFileSystemType, HasNotifyFilters DoesNotHave… has the expected change flags
HasName, HasPath, HasOldName, HasOldPath has the expected (old) name or path
IFileSystemStatistics Recorded() a method was called or a property was accessed
ITimerMock Executed the 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:

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

About

Expectations for the file and time system from Testably.Abstractions

Resources

Code of conduct

Contributing

Stars

1 star

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages