From d1e2ea2dff13938e0787e46e62065460bb514c47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Sun, 31 May 2026 15:41:59 +0200 Subject: [PATCH] test: kill DriveInfo expectation mutation survivors --- ...riveInfo.DoesNotComplyWithIsReady.Tests.cs | 36 ++++++++++++++++++ ...nfo.DoesNotHaveAvailableFreeSpace.Tests.cs | 36 ++++++++++++++++++ .../DriveInfo.DoesNotHaveDriveFormat.Tests.cs | 36 ++++++++++++++++++ .../DriveInfo.DoesNotHaveDriveType.Tests.cs | 37 +++++++++++++++++++ .../DriveInfo.DoesNotHaveName.Tests.cs | 36 ++++++++++++++++++ ...iveInfo.DoesNotHaveTotalFreeSpace.Tests.cs | 36 ++++++++++++++++++ .../DriveInfo.DoesNotHaveTotalSize.Tests.cs | 36 ++++++++++++++++++ .../DriveInfo.DoesNotHaveVolumeLabel.Tests.cs | 36 ++++++++++++++++++ .../DriveInfo.HasName.Tests.cs | 11 +++++- .../DriveInfo.HasVolumeLabel.Tests.cs | 7 +++- 10 files changed, 305 insertions(+), 2 deletions(-) create mode 100644 Tests/aweXpect.Testably.Tests/DriveInfo.DoesNotComplyWithIsReady.Tests.cs create mode 100644 Tests/aweXpect.Testably.Tests/DriveInfo.DoesNotHaveAvailableFreeSpace.Tests.cs create mode 100644 Tests/aweXpect.Testably.Tests/DriveInfo.DoesNotHaveDriveFormat.Tests.cs create mode 100644 Tests/aweXpect.Testably.Tests/DriveInfo.DoesNotHaveDriveType.Tests.cs create mode 100644 Tests/aweXpect.Testably.Tests/DriveInfo.DoesNotHaveName.Tests.cs create mode 100644 Tests/aweXpect.Testably.Tests/DriveInfo.DoesNotHaveTotalFreeSpace.Tests.cs create mode 100644 Tests/aweXpect.Testably.Tests/DriveInfo.DoesNotHaveTotalSize.Tests.cs create mode 100644 Tests/aweXpect.Testably.Tests/DriveInfo.DoesNotHaveVolumeLabel.Tests.cs diff --git a/Tests/aweXpect.Testably.Tests/DriveInfo.DoesNotComplyWithIsReady.Tests.cs b/Tests/aweXpect.Testably.Tests/DriveInfo.DoesNotComplyWithIsReady.Tests.cs new file mode 100644 index 0000000..5e316ae --- /dev/null +++ b/Tests/aweXpect.Testably.Tests/DriveInfo.DoesNotComplyWithIsReady.Tests.cs @@ -0,0 +1,36 @@ +#if NET8_0_OR_GREATER +using System.IO.Abstractions; +using Testably.Abstractions.Testing; + +namespace aweXpect.Testably.Tests; + +public sealed partial class DriveInfo +{ + public sealed class DoesNotComplyWithIsReady + { + public sealed class Tests + { + [Fact] + public async Task WhenDriveIsReady_ShouldFail() + { + MockFileSystem fileSystem = new(o => o.SimulatingOperatingSystem(SimulationMode.Windows)); + fileSystem.WithDrive("D:", d => d.SetIsReady(true)); + IDriveInfo driveInfo = fileSystem.DriveInfo.New("D:"); + + async Task Act() + { + await That(driveInfo).DoesNotComplyWith(d => d.IsReady()); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that driveInfo + is not ready, + but it was + """); + } + } + } +} + +#endif diff --git a/Tests/aweXpect.Testably.Tests/DriveInfo.DoesNotHaveAvailableFreeSpace.Tests.cs b/Tests/aweXpect.Testably.Tests/DriveInfo.DoesNotHaveAvailableFreeSpace.Tests.cs new file mode 100644 index 0000000..abf3355 --- /dev/null +++ b/Tests/aweXpect.Testably.Tests/DriveInfo.DoesNotHaveAvailableFreeSpace.Tests.cs @@ -0,0 +1,36 @@ +#if NET8_0_OR_GREATER +using System.IO.Abstractions; +using Testably.Abstractions.Testing; + +namespace aweXpect.Testably.Tests; + +public sealed partial class DriveInfo +{ + public sealed class DoesNotHaveAvailableFreeSpace + { + public sealed class Tests + { + [Fact] + public async Task WhenAvailableFreeSpaceMatches_ShouldFail() + { + MockFileSystem fileSystem = new(o => o.SimulatingOperatingSystem(SimulationMode.Windows)); + fileSystem.WithDrive("D:", d => d.SetTotalSize(2048)); + IDriveInfo driveInfo = fileSystem.DriveInfo.New("D:"); + + async Task Act() + { + await That(driveInfo).DoesNotComplyWith(d => d.HasAvailableFreeSpace(2048)); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that driveInfo + does not have available free space 2048, + but it did + """); + } + } + } +} + +#endif diff --git a/Tests/aweXpect.Testably.Tests/DriveInfo.DoesNotHaveDriveFormat.Tests.cs b/Tests/aweXpect.Testably.Tests/DriveInfo.DoesNotHaveDriveFormat.Tests.cs new file mode 100644 index 0000000..ba5fa83 --- /dev/null +++ b/Tests/aweXpect.Testably.Tests/DriveInfo.DoesNotHaveDriveFormat.Tests.cs @@ -0,0 +1,36 @@ +#if NET8_0_OR_GREATER +using System.IO.Abstractions; +using Testably.Abstractions.Testing; + +namespace aweXpect.Testably.Tests; + +public sealed partial class DriveInfo +{ + public sealed class DoesNotHaveDriveFormat + { + public sealed class Tests + { + [Fact] + public async Task WhenDriveFormatMatches_ShouldFail() + { + MockFileSystem fileSystem = new(o => o.SimulatingOperatingSystem(SimulationMode.Windows)); + fileSystem.WithDrive("D:", d => d.SetDriveFormat("NTFS")); + IDriveInfo driveInfo = fileSystem.DriveInfo.New("D:"); + + async Task Act() + { + await That(driveInfo).DoesNotComplyWith(d => d.HasDriveFormat("NTFS")); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that driveInfo + does not have drive format not equal to "NTFS", + but it did + """); + } + } + } +} + +#endif diff --git a/Tests/aweXpect.Testably.Tests/DriveInfo.DoesNotHaveDriveType.Tests.cs b/Tests/aweXpect.Testably.Tests/DriveInfo.DoesNotHaveDriveType.Tests.cs new file mode 100644 index 0000000..56c01b0 --- /dev/null +++ b/Tests/aweXpect.Testably.Tests/DriveInfo.DoesNotHaveDriveType.Tests.cs @@ -0,0 +1,37 @@ +#if NET8_0_OR_GREATER +using System.IO; +using System.IO.Abstractions; +using Testably.Abstractions.Testing; + +namespace aweXpect.Testably.Tests; + +public sealed partial class DriveInfo +{ + public sealed class DoesNotHaveDriveType + { + public sealed class Tests + { + [Fact] + public async Task WhenDriveTypeMatches_ShouldFail() + { + MockFileSystem fileSystem = new(o => o.SimulatingOperatingSystem(SimulationMode.Windows)); + fileSystem.WithDrive("D:", d => d.SetDriveType(DriveType.Fixed)); + IDriveInfo driveInfo = fileSystem.DriveInfo.New("D:"); + + async Task Act() + { + await That(driveInfo).DoesNotComplyWith(d => d.HasDriveType(DriveType.Fixed)); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that driveInfo + does not have drive type Fixed, + but it did + """); + } + } + } +} + +#endif diff --git a/Tests/aweXpect.Testably.Tests/DriveInfo.DoesNotHaveName.Tests.cs b/Tests/aweXpect.Testably.Tests/DriveInfo.DoesNotHaveName.Tests.cs new file mode 100644 index 0000000..c75b1d9 --- /dev/null +++ b/Tests/aweXpect.Testably.Tests/DriveInfo.DoesNotHaveName.Tests.cs @@ -0,0 +1,36 @@ +#if NET8_0_OR_GREATER +using System.IO.Abstractions; +using Testably.Abstractions.Testing; + +namespace aweXpect.Testably.Tests; + +public sealed partial class DriveInfo +{ + public sealed class DoesNotHaveName + { + public sealed class Tests + { + [Fact] + public async Task WhenNameMatches_ShouldFail() + { + MockFileSystem fileSystem = new(o => o.SimulatingOperatingSystem(SimulationMode.Windows)); + fileSystem.WithDrive("D:"); + IDriveInfo driveInfo = fileSystem.DriveInfo.New("D:"); + + async Task Act() + { + await That(driveInfo).DoesNotComplyWith(d => d.HasName(driveInfo.Name)); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that driveInfo + does not have name not equal to "D:\", + but it did + """); + } + } + } +} + +#endif diff --git a/Tests/aweXpect.Testably.Tests/DriveInfo.DoesNotHaveTotalFreeSpace.Tests.cs b/Tests/aweXpect.Testably.Tests/DriveInfo.DoesNotHaveTotalFreeSpace.Tests.cs new file mode 100644 index 0000000..bf23d1c --- /dev/null +++ b/Tests/aweXpect.Testably.Tests/DriveInfo.DoesNotHaveTotalFreeSpace.Tests.cs @@ -0,0 +1,36 @@ +#if NET8_0_OR_GREATER +using System.IO.Abstractions; +using Testably.Abstractions.Testing; + +namespace aweXpect.Testably.Tests; + +public sealed partial class DriveInfo +{ + public sealed class DoesNotHaveTotalFreeSpace + { + public sealed class Tests + { + [Fact] + public async Task WhenTotalFreeSpaceMatches_ShouldFail() + { + MockFileSystem fileSystem = new(o => o.SimulatingOperatingSystem(SimulationMode.Windows)); + fileSystem.WithDrive("D:", d => d.SetTotalSize(2048)); + IDriveInfo driveInfo = fileSystem.DriveInfo.New("D:"); + + async Task Act() + { + await That(driveInfo).DoesNotComplyWith(d => d.HasTotalFreeSpace(2048)); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that driveInfo + does not have total free space 2048, + but it did + """); + } + } + } +} + +#endif diff --git a/Tests/aweXpect.Testably.Tests/DriveInfo.DoesNotHaveTotalSize.Tests.cs b/Tests/aweXpect.Testably.Tests/DriveInfo.DoesNotHaveTotalSize.Tests.cs new file mode 100644 index 0000000..776803a --- /dev/null +++ b/Tests/aweXpect.Testably.Tests/DriveInfo.DoesNotHaveTotalSize.Tests.cs @@ -0,0 +1,36 @@ +#if NET8_0_OR_GREATER +using System.IO.Abstractions; +using Testably.Abstractions.Testing; + +namespace aweXpect.Testably.Tests; + +public sealed partial class DriveInfo +{ + public sealed class DoesNotHaveTotalSize + { + public sealed class Tests + { + [Fact] + public async Task WhenTotalSizeMatches_ShouldFail() + { + MockFileSystem fileSystem = new(o => o.SimulatingOperatingSystem(SimulationMode.Windows)); + fileSystem.WithDrive("D:", d => d.SetTotalSize(2048)); + IDriveInfo driveInfo = fileSystem.DriveInfo.New("D:"); + + async Task Act() + { + await That(driveInfo).DoesNotComplyWith(d => d.HasTotalSize(2048)); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that driveInfo + does not have total size 2048, + but it did + """); + } + } + } +} + +#endif diff --git a/Tests/aweXpect.Testably.Tests/DriveInfo.DoesNotHaveVolumeLabel.Tests.cs b/Tests/aweXpect.Testably.Tests/DriveInfo.DoesNotHaveVolumeLabel.Tests.cs new file mode 100644 index 0000000..7b53112 --- /dev/null +++ b/Tests/aweXpect.Testably.Tests/DriveInfo.DoesNotHaveVolumeLabel.Tests.cs @@ -0,0 +1,36 @@ +#if NET8_0_OR_GREATER +using System.IO.Abstractions; +using Testably.Abstractions.Testing; + +namespace aweXpect.Testably.Tests; + +public sealed partial class DriveInfo +{ + public sealed class DoesNotHaveVolumeLabel + { + public sealed class Tests + { + [Fact] + public async Task WhenVolumeLabelMatches_ShouldFail() + { + MockFileSystem fileSystem = new(o => o.SimulatingOperatingSystem(SimulationMode.Windows)); + IDriveInfo driveInfo = fileSystem.DriveInfo.New("C:"); + string actualLabel = driveInfo.VolumeLabel; + + async Task Act() + { + await That(driveInfo).DoesNotComplyWith(d => d.HasVolumeLabel(actualLabel)); + } + + await That(Act).ThrowsException() + .WithMessage($""" + Expected that driveInfo + does not have volume label not equal to "{actualLabel}", + but it did + """); + } + } + } +} + +#endif diff --git a/Tests/aweXpect.Testably.Tests/DriveInfo.HasName.Tests.cs b/Tests/aweXpect.Testably.Tests/DriveInfo.HasName.Tests.cs index 1582ef1..db1a2e8 100644 --- a/Tests/aweXpect.Testably.Tests/DriveInfo.HasName.Tests.cs +++ b/Tests/aweXpect.Testably.Tests/DriveInfo.HasName.Tests.cs @@ -37,7 +37,16 @@ async Task Act() await That(driveInfo).HasName("Z:\\"); } - await That(Act).ThrowsException(); + await That(Act).ThrowsException() + .WithMessage(""" + Expected that driveInfo + has name equal to "Z:\", + but it was "D:\" which differs at index 0: + ↓ (actual) + "D:\" + "Z:\" + ↑ (expected) + """); } [Fact] diff --git a/Tests/aweXpect.Testably.Tests/DriveInfo.HasVolumeLabel.Tests.cs b/Tests/aweXpect.Testably.Tests/DriveInfo.HasVolumeLabel.Tests.cs index 8c34bdc..248e2be 100644 --- a/Tests/aweXpect.Testably.Tests/DriveInfo.HasVolumeLabel.Tests.cs +++ b/Tests/aweXpect.Testably.Tests/DriveInfo.HasVolumeLabel.Tests.cs @@ -36,7 +36,12 @@ async Task Act() await That(driveInfo).HasVolumeLabel("definitely-not-the-label"); } - await That(Act).ThrowsException(); + await That(Act).ThrowsException() + .WithMessage(""" + Expected that driveInfo + has volume label equal to "definitely-not-the-label", + but it was * + """).AsWildcard(); } [Fact]