From 3d752e7d014e98246bba6272196f3a724852da28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Fri, 8 Aug 2025 19:11:58 +0200 Subject: [PATCH] fix: compile errors in Examples.sln --- .../.idea/.idea.Examples/.idea/.gitignore | 13 +++++ .../.idea.Examples/.idea/indexLayout.xml | 8 +++ .../AccessControlListTests.cs | 33 +++++++----- .../DependencyInjectionTests.cs | 11 ++-- .../InitializationTests.cs | 44 +++++++--------- .../InterceptionTests.cs | 16 +++--- .../NotificationTests.cs | 17 +++--- Examples/Directory.Build.props | 3 +- .../DriveManagementTests.cs | 49 +++++++++-------- .../FileSystemWatcherTests.cs | 9 ++-- .../SafeFileHandleTests.cs | 28 +++++----- .../ThreadAwareTimeProviderTests.cs | 40 +++++++------- .../ZipFile.Tests/ZipFileHelperTests.cs | 52 +++++++++---------- 13 files changed, 172 insertions(+), 151 deletions(-) create mode 100644 Examples/.idea/.idea.Examples/.idea/.gitignore create mode 100644 Examples/.idea/.idea.Examples/.idea/indexLayout.xml diff --git a/Examples/.idea/.idea.Examples/.idea/.gitignore b/Examples/.idea/.idea.Examples/.idea/.gitignore new file mode 100644 index 000000000..3da0fb631 --- /dev/null +++ b/Examples/.idea/.idea.Examples/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/.idea.Examples.iml +/projectSettingsUpdater.xml +/contentModel.xml +/modules.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/Examples/.idea/.idea.Examples/.idea/indexLayout.xml b/Examples/.idea/.idea.Examples/.idea/indexLayout.xml new file mode 100644 index 000000000..7b08163ce --- /dev/null +++ b/Examples/.idea/.idea.Examples/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Examples/AccessControlLists/AccessControlLists.Tests/AccessControlListTests.cs b/Examples/AccessControlLists/AccessControlLists.Tests/AccessControlListTests.cs index 2f5fc5fcb..a53e700c7 100644 --- a/Examples/AccessControlLists/AccessControlLists.Tests/AccessControlListTests.cs +++ b/Examples/AccessControlLists/AccessControlLists.Tests/AccessControlListTests.cs @@ -1,7 +1,6 @@ -using AutoFixture.Xunit2; -using FluentAssertions; -using System; +using aweXpect; using System.IO; +using System.Threading.Tasks; using Testably.Abstractions.Testing; using Xunit; @@ -9,31 +8,37 @@ namespace Testably.Abstractions.Examples.AccessControlLists.Tests; public class AccessControlListTests { + #region Test Setup + + public MockFileSystem FileSystem { get; } + public AccessControlListTests() { FileSystem = new MockFileSystem(); } - public MockFileSystem FileSystem { get; } + #endregion [Theory] - [AutoData] - public void ReadAllText_DeniedPath_ShouldThrowIOException(string grantedPath, string deniedPath) + [InlineData("granted", "denied")] + public async Task ReadAllText_DeniedPath_ShouldThrowIOException(string grantedPath, + string deniedPath) { FileSystem.File.WriteAllText(grantedPath, "foo"); FileSystem.File.WriteAllText(deniedPath, "bar"); - FileSystem.WithAccessControlStrategy(new CustomAccessControlStrategy( - path => path.Contains(grantedPath))); + FileSystem.WithAccessControlStrategy( + new CustomAccessControlStrategy(path => path.Contains(grantedPath))); string result = FileSystem.File.ReadAllText(grantedPath); - result.Should().Be("foo"); + await Expect.That(result).IsEqualTo("foo"); - Exception? exception = Record.Exception(() => + void Act() { FileSystem.File.ReadAllText(deniedPath); - }); - exception.Should().BeOfType() - .Which.Message.Should() - .Be($"Access to the path '{FileSystem.Path.GetFullPath(deniedPath)}' is denied."); + } + + await Expect.That(Act).Throws() + .WithMessage( + $"Access to the path '{FileSystem.Path.GetFullPath(deniedPath)}' is denied."); } } diff --git a/Examples/Configuration/DependencyInjection.Tests/DependencyInjectionTests.cs b/Examples/Configuration/DependencyInjection.Tests/DependencyInjectionTests.cs index cf5d4d2d9..f750212f0 100644 --- a/Examples/Configuration/DependencyInjection.Tests/DependencyInjectionTests.cs +++ b/Examples/Configuration/DependencyInjection.Tests/DependencyInjectionTests.cs @@ -1,6 +1,7 @@ -using FluentAssertions; +using aweXpect; using Microsoft.Extensions.DependencyInjection; using System.IO.Abstractions; +using System.Threading.Tasks; using Xunit; namespace Testably.Abstractions.Examples.Configuration.DependencyInjection.Tests; @@ -8,7 +9,7 @@ namespace Testably.Abstractions.Examples.Configuration.DependencyInjection.Tests public class DependencyInjectionTests { [Fact] - public void + public async Task DependencyInjection_Microsoft_ShouldAllowRegistrationAndCreationOfInstances() { ServiceProvider services = new ServiceCollection() @@ -17,8 +18,8 @@ public void .AddSingleton() .BuildServiceProvider(); - services.GetService().Should().BeOfType(); - services.GetService().Should().BeOfType(); - services.GetService().Should().BeOfType(); + await Expect.That(services.GetService()).Is(); + await Expect.That(services.GetService()).Is(); + await Expect.That(services.GetService()).Is(); } } diff --git a/Examples/Configuration/FileSystemConfiguration.Tests/InitializationTests.cs b/Examples/Configuration/FileSystemConfiguration.Tests/InitializationTests.cs index c92ea21ec..6b11771fb 100644 --- a/Examples/Configuration/FileSystemConfiguration.Tests/InitializationTests.cs +++ b/Examples/Configuration/FileSystemConfiguration.Tests/InitializationTests.cs @@ -1,10 +1,8 @@ -using AutoFixture.Xunit2; -using FluentAssertions; -using System; +using aweXpect; using System.IO; using System.IO.Abstractions; -using System.Linq; using System.Runtime.InteropServices; +using System.Threading.Tasks; using Testably.Abstractions.RandomSystem; using Testably.Abstractions.Testing; using Xunit; @@ -18,8 +16,8 @@ public class InitializationTests /// - a randomly named directory /// [Theory] - [AutoData] - public void InitializeFileSystemInSpecifiedCurrentDirectory(string currentDirectory) + [InlineData("foo")] + public async Task InitializeFileSystemInSpecifiedCurrentDirectory(string currentDirectory) { MockFileSystem fileSystem = new(); string expectedDirectory = fileSystem.Path.GetFullPath(currentDirectory); @@ -27,9 +25,7 @@ public void InitializeFileSystemInSpecifiedCurrentDirectory(string currentDirect fileSystem.InitializeIn(currentDirectory) .WithASubdirectory(); - fileSystem.Directory.GetCurrentDirectory() - .Should() - .Be(expectedDirectory); + await Expect.That(fileSystem.Directory.GetCurrentDirectory()).IsEqualTo(expectedDirectory); } /// @@ -39,7 +35,7 @@ public void InitializeFileSystemInSpecifiedCurrentDirectory(string currentDirect /// - a file named "bar.txt" /// [Fact] - public void InitializeFileSystemInTheRootDirectory() + public async Task InitializeFileSystemInTheRootDirectory() { MockFileSystem fileSystem = new(); fileSystem.InitializeIn("base-directory") @@ -49,9 +45,9 @@ public void InitializeFileSystemInTheRootDirectory() .WithAFile()) .WithFile("bar.txt"); - fileSystem.File.Exists("bar.txt").Should().BeTrue(); - fileSystem.Directory.Exists("foo").Should().BeTrue(); - fileSystem.Directory.GetDirectories(".").Length.Should().Be(2); + await Expect.That(fileSystem.File.Exists("bar.txt")).IsTrue(); + await Expect.That(fileSystem.Directory.Exists("foo")).IsTrue(); + await Expect.That(fileSystem.Directory.GetDirectories(".")).HasCount(2); } /// @@ -60,20 +56,20 @@ public void InitializeFileSystemInTheRootDirectory() /// UNC servers (or additional drives under windows) can be added if required. /// [Fact] - public void InitializeFileSystemWithUncDrive() + public async Task InitializeFileSystemWithUncDrive() { MockFileSystem fileSystem = new(); - var initialDriveCount = fileSystem.DriveInfo.GetDrives().Length; + int initialDriveCount = fileSystem.DriveInfo.GetDrives().Length; fileSystem.WithUncDrive(@"//unc-server"); - fileSystem.DriveInfo.GetDrives().Should().HaveCount(initialDriveCount); + await Expect.That(fileSystem.DriveInfo.GetDrives()).HasCount(initialDriveCount); IDriveInfo drive = fileSystem.DriveInfo.New(@"//unc-server"); - drive.IsReady.Should().BeTrue(); + await Expect.That(drive.IsReady).IsTrue(); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - fileSystem.DriveInfo.GetDrives().Should().HaveCount(initialDriveCount); + await Expect.That(fileSystem.DriveInfo.GetDrives()).HasCount(initialDriveCount); } } @@ -84,7 +80,7 @@ public void InitializeFileSystemWithUncDrive() /// , when the limit is breached. /// [Fact] - public void LimitAvailableSpaceOnDrives() + public async Task LimitAvailableSpaceOnDrives() { MockFileSystem fileSystem = new(); IRandom random = fileSystem.RandomSystem.Random.Shared; @@ -96,16 +92,16 @@ public void LimitAvailableSpaceOnDrives() // Limit the main drive to 200 bytes fileSystem.WithDrive(drive => drive.SetTotalSize(200)); IDriveInfo mainDrive = fileSystem.GetDefaultDrive(); - mainDrive.AvailableFreeSpace.Should().Be(200); + await Expect.That(mainDrive.AvailableFreeSpace).IsEqualTo(200); fileSystem.File.WriteAllBytes("foo", firstFileContent); - mainDrive.AvailableFreeSpace.Should().Be(1); + await Expect.That(mainDrive.AvailableFreeSpace).IsEqualTo(1); - Exception? exception = Record.Exception(() => + void Act() { fileSystem.File.WriteAllBytes("bar", secondFileContent); - }); + } - exception.Should().BeOfType(); + await Expect.That(Act).Throws(); } } diff --git a/Examples/Configuration/FileSystemConfiguration.Tests/InterceptionTests.cs b/Examples/Configuration/FileSystemConfiguration.Tests/InterceptionTests.cs index b65216159..75bc11bb3 100644 --- a/Examples/Configuration/FileSystemConfiguration.Tests/InterceptionTests.cs +++ b/Examples/Configuration/FileSystemConfiguration.Tests/InterceptionTests.cs @@ -1,6 +1,6 @@ -using AutoFixture.Xunit2; -using FluentAssertions; +using aweXpect; using System; +using System.Threading.Tasks; using Testably.Abstractions.Testing; using Xunit; @@ -11,22 +11,22 @@ public class InterceptionTests /// /// Intercepting allows callbacks to be invoked before the change in the file system is performed. /// - [Theory] - [AutoData] - public void Intercept(Exception customException) + [Fact] + public async Task Intercept() { + Exception customException = new ApplicationException("bar"); MockFileSystem fileSystem = new(); fileSystem.Intercept.Creating(FileSystemTypes.File, _ => throw customException); fileSystem.Directory.CreateDirectory("foo"); - Exception exception = Record.Exception(() => + Exception? exception = Record.Exception(() => { fileSystem.File.Create("foo/bar.txt"); }); - exception.Should().Be(customException); - fileSystem.File.Exists("foo/bar.txt").Should().BeFalse(); + await Expect.That(exception).IsSameAs(customException); + await Expect.That(fileSystem.File.Exists("foo/bar.txt")).IsFalse(); } } diff --git a/Examples/Configuration/FileSystemConfiguration.Tests/NotificationTests.cs b/Examples/Configuration/FileSystemConfiguration.Tests/NotificationTests.cs index 0e92b54a1..854a116fd 100644 --- a/Examples/Configuration/FileSystemConfiguration.Tests/NotificationTests.cs +++ b/Examples/Configuration/FileSystemConfiguration.Tests/NotificationTests.cs @@ -1,5 +1,6 @@ -using FluentAssertions; +using aweXpect; using System.Threading; +using System.Threading.Tasks; using Testably.Abstractions.Testing; using Xunit; @@ -11,7 +12,7 @@ public class NotificationTests /// Notifications allow reacting to an event after it occurred. /// [Fact] - public void Notify_ManualWait() + public async Task Notify_ManualWait() { ManualResetEventSlim ms = new(); bool isNotified = false; @@ -26,16 +27,16 @@ public void Notify_ManualWait() fileSystem.Directory.CreateDirectory("foo"); fileSystem.File.Create("foo/bar.txt"); - ms.Wait(); - fileSystem.File.Exists("foo/bar.txt").Should().BeTrue(); - isNotified.Should().BeTrue(); + ms.Wait(TestContext.Current.CancellationToken); + await Expect.That(fileSystem.File.Exists("foo/bar.txt")).IsTrue(); + await Expect.That(isNotified).IsTrue(); } /// /// Notifications allow reacting to an event after it occurred. /// [Fact] - public void Notify_UseAwaitableCallback() + public async Task Notify_UseAwaitableCallback() { bool isNotified = false; MockFileSystem fileSystem = new(); @@ -53,7 +54,7 @@ public void Notify_UseAwaitableCallback() // If a timeout is provided, this will throw a TimeoutException if no event was triggered within 1000ms .Wait(timeout: 1000); - fileSystem.File.Exists("foo/bar.txt").Should().BeTrue(); - isNotified.Should().BeTrue(); + await Expect.That(fileSystem.File.Exists("foo/bar.txt")).IsTrue(); + await Expect.That(isNotified).IsTrue(); } } diff --git a/Examples/Directory.Build.props b/Examples/Directory.Build.props index 19aa5a8bb..8d876f36e 100644 --- a/Examples/Directory.Build.props +++ b/Examples/Directory.Build.props @@ -32,7 +32,8 @@ - + + diff --git a/Examples/DriveManagement/DriveManagement.Tests/DriveManagementTests.cs b/Examples/DriveManagement/DriveManagement.Tests/DriveManagementTests.cs index 220609896..3ded39576 100644 --- a/Examples/DriveManagement/DriveManagement.Tests/DriveManagementTests.cs +++ b/Examples/DriveManagement/DriveManagement.Tests/DriveManagementTests.cs @@ -1,7 +1,8 @@ -using FluentAssertions; +using aweXpect; using System; using System.IO; using System.IO.Abstractions; +using System.Threading.Tasks; using Testably.Abstractions.Testing; using Xunit; @@ -10,35 +11,32 @@ namespace Testably.Abstractions.Examples.DriveManagement.Tests; public class DriveManagementTests { [Fact] - public void DefineAdditionalDrive() + public async Task ChangeDefaultDrive() { MockFileSystem fileSystem = new MockFileSystem() - .WithDrive("T:\\"); + .InitializeIn("U:\\sub\\directory") + .FileSystem; - fileSystem.File.WriteAllText("T:\\foo.txt", "bar"); + fileSystem.File.WriteAllText("foo.txt", "bar"); - fileSystem.DriveInfo.GetDrives() - .Should().Contain(d => d.Name == "T:\\"); - fileSystem.File.Exists("T:\\foo.txt").Should().BeTrue(); + await Expect.That(fileSystem.DriveInfo.GetDrives()).Contains(d => d.Name == "U:\\"); + await Expect.That(fileSystem.File.Exists("U:\\sub\\directory\\foo.txt")).IsTrue(); } [Fact] - public void ChangeDefaultDrive() + public async Task DefineAdditionalDrive() { MockFileSystem fileSystem = new MockFileSystem() - .InitializeIn("U:\\sub\\directory") - .FileSystem; + .WithDrive("T:\\"); - fileSystem.File.WriteAllText("foo.txt", "bar"); + fileSystem.File.WriteAllText("T:\\foo.txt", "bar"); - fileSystem.DriveInfo.GetDrives() - .Should().Contain(d => d.Name == "U:\\"); - fileSystem.File.Exists("U:\\sub\\directory\\foo.txt") - .Should().BeTrue(); + await Expect.That(fileSystem.DriveInfo.GetDrives()).Contains(d => d.Name == "T:\\"); + await Expect.That(fileSystem.File.Exists("T:\\foo.txt")).IsTrue(); } [Fact] - public void LimitAvailableDriveSize() + public async Task LimitAvailableDriveSize() { MockFileSystem fileSystem = new MockFileSystem() .WithDrive("C:\\", d => d.SetTotalSize(100)); @@ -46,22 +44,23 @@ public void LimitAvailableDriveSize() byte[] largeFileContent = new byte[90]; Random.Shared.NextBytes(largeFileContent); - drive.AvailableFreeSpace.Should().Be(100); + await Expect.That(drive.AvailableFreeSpace).IsEqualTo(100); fileSystem.File.WriteAllText("foo.txt", "This is a text with 29 bytes."); - drive.AvailableFreeSpace.Should().Be(71); + await Expect.That(drive.AvailableFreeSpace).IsEqualTo(71); fileSystem.File.AppendAllText("foo.txt", "Another 17 bytes."); - drive.AvailableFreeSpace.Should().Be(54); + await Expect.That(drive.AvailableFreeSpace).IsEqualTo(54); - Exception? exception = Record.Exception(() => + void Act() { fileSystem.File.WriteAllBytes("bar.bin", largeFileContent); - }); - exception.Should().BeOfType(); + } + + await Expect.That(Act).Throws(); - drive.AvailableFreeSpace.Should().Be(54); + await Expect.That(drive.AvailableFreeSpace).IsEqualTo(54); fileSystem.File.Delete("foo.txt"); - drive.AvailableFreeSpace.Should().Be(100); + await Expect.That(drive.AvailableFreeSpace).IsEqualTo(100); fileSystem.File.WriteAllBytes("bar.bin", largeFileContent); - drive.AvailableFreeSpace.Should().Be(10); + await Expect.That(drive.AvailableFreeSpace).IsEqualTo(10); } } diff --git a/Examples/FileSystemWatcher/FileSystemWatcher.Tests/FileSystemWatcherTests.cs b/Examples/FileSystemWatcher/FileSystemWatcher.Tests/FileSystemWatcherTests.cs index db293a9cf..89a681634 100644 --- a/Examples/FileSystemWatcher/FileSystemWatcher.Tests/FileSystemWatcherTests.cs +++ b/Examples/FileSystemWatcher/FileSystemWatcher.Tests/FileSystemWatcherTests.cs @@ -1,7 +1,8 @@ -using FluentAssertions; +using aweXpect; using System.IO; using System.IO.Abstractions; using System.Threading; +using System.Threading.Tasks; using Testably.Abstractions.Testing; using Xunit; @@ -10,7 +11,7 @@ namespace Testably.Abstractions.Examples.FileSystemWatcher.Tests; public class FileSystemWatcherTests { [Fact] - public void EnableRaisingEvents_ShouldTriggerWhenFileSystemChanges() + public async Task EnableRaisingEvents_ShouldTriggerWhenFileSystemChanges() { MockFileSystem fileSystem = new(); fileSystem.Initialize().WithSubdirectory("foo"); @@ -28,8 +29,8 @@ public void EnableRaisingEvents_ShouldTriggerWhenFileSystemChanges() fileSystem.Directory.Delete("foo"); - ms.Wait(1000).Should().BeTrue(); + await Expect.That(ms.Wait(1000, TestContext.Current.CancellationToken)).IsTrue(); - result.Should().NotBeNull(); + await Expect.That(result).IsNotNull(); } } diff --git a/Examples/SafeFileHandle/SafeFileHandle.Tests/SafeFileHandleTests.cs b/Examples/SafeFileHandle/SafeFileHandle.Tests/SafeFileHandleTests.cs index 1ed57aea9..8d640d251 100644 --- a/Examples/SafeFileHandle/SafeFileHandle.Tests/SafeFileHandleTests.cs +++ b/Examples/SafeFileHandle/SafeFileHandle.Tests/SafeFileHandleTests.cs @@ -1,6 +1,6 @@ -using AutoFixture.Xunit2; -using FluentAssertions; +using aweXpect; using System; +using System.Threading.Tasks; using Testably.Abstractions.Testing; using Testably.Abstractions.Testing.FileSystem; using Xunit; @@ -9,12 +9,14 @@ namespace Testably.Abstractions.Examples.SafeFileHandle.Tests; public class SafeFileHandleTests { - [SkippableTheory] - [AutoData] - public void SynchronizeLastAccessTimeFromRealFileSystem_WhenUsingACustomSafeFileHandleStrategy( - DateTime lastAccessTime, string realFileSystemPath, string mockFileSystemPath) + [Theory] + [InlineData("real", "mock")] + public async Task + SynchronizeLastAccessTimeFromRealFileSystem_WhenUsingACustomSafeFileHandleStrategy( + string realFileSystemPath, string mockFileSystemPath) { - Skip.If(true, "Github actions don't support testing SafeFileHandle."); + DateTime lastAccessTime = DateTime.Now; + Skip.Test("Github actions don't support testing SafeFileHandle."); // Setup RealFileSystem realFileSystem = new(); @@ -31,19 +33,19 @@ public void SynchronizeLastAccessTimeFromRealFileSystem_WhenUsingACustomSafeFile Microsoft.Win32.SafeHandles.SafeFileHandle fileHandle = UnmanagedFileLoader.CreateSafeFileHandle(realFileSystemPath); // Ensure, that the mock file system last access time is currently different: - mockFileSystem.File.GetLastAccessTime(mockFileSystemPath) - .Should().NotBe(lastAccessTime); + await Expect.That(mockFileSystem.File.GetLastAccessTime(mockFileSystemPath)) + .IsNotEqualTo(lastAccessTime); // Add the mapping in the custom ISafeFileHandleStrategy: safeFileHandleStrategy.AddMapping(fileHandle, realFileSystemPath, new SafeFileHandleMock(mockFileSystemPath)); // Ensure, that access via the SafeFileHandle is possible - mockFileSystem.File.GetLastAccessTime(fileHandle) - .Should().Be(lastAccessTime); + await Expect.That(mockFileSystem.File.GetLastAccessTime(fileHandle)) + .IsEqualTo(lastAccessTime); // Ensure that the last access time was synchronized - mockFileSystem.File.GetLastAccessTime(mockFileSystemPath) - .Should().Be(lastAccessTime); + await Expect.That(mockFileSystem.File.GetLastAccessTime(mockFileSystemPath)) + .IsEqualTo(lastAccessTime); } } } diff --git a/Examples/ThreadAwareTimeProvider/ThreadAwareTimeProvider.Tests/ThreadAwareTimeProviderTests.cs b/Examples/ThreadAwareTimeProvider/ThreadAwareTimeProvider.Tests/ThreadAwareTimeProviderTests.cs index e806b7283..8e9bb5d20 100644 --- a/Examples/ThreadAwareTimeProvider/ThreadAwareTimeProvider.Tests/ThreadAwareTimeProviderTests.cs +++ b/Examples/ThreadAwareTimeProvider/ThreadAwareTimeProvider.Tests/ThreadAwareTimeProviderTests.cs @@ -1,4 +1,4 @@ -using FluentAssertions; +using aweXpect; using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -44,21 +44,20 @@ await Task.Run(async () => return l; }); } - }); + }, TestContext.Current.CancellationToken); } for (int i = 1; i <= parallelTasks; i++) { int delayPerTask = i * 1000; - delaysPerTask[i] - .Should() - .BeEquivalentTo( - Enumerable.Range(1, stepsPerTask).Select(x => x * delayPerTask)); + await Expect.That(delaysPerTask[i]) + .IsEqualTo(Enumerable.Range(1, stepsPerTask) + .Select(x => x * delayPerTask)); } } [Fact] - public void ParallelThreads_ShouldHaveDistinctTimes() + public async Task ParallelThreads_ShouldHaveDistinctTimes() { int parallelThreads = 10; int stepsPerThread = 20; @@ -95,14 +94,13 @@ public void ParallelThreads_ShouldHaveDistinctTimes() }).Start(); } - ms.Wait(1000).Should().BeTrue(); + await Expect.That(ms.Wait(1000, TestContext.Current.CancellationToken)).IsTrue(); for (int i = 1; i <= parallelThreads; i++) { int delayPerThread = i * 1000; - delaysPerThread[i] - .Should() - .BeEquivalentTo( - Enumerable.Range(1, stepsPerThread).Select(x => x * delayPerThread)); + await Expect.That(delaysPerThread[i]) + .IsEqualTo(Enumerable.Range(1, stepsPerThread) + .Select(x => x * delayPerThread)); } } @@ -115,7 +113,7 @@ public async Task SynchronizeClock_AdvanceBy_ShouldUseSynchronizedValueAsBase( ThreadAwareTimeProvider timeProvider = new(); MockTimeSystem timeSystem = new(timeProvider); DateTime start = timeSystem.DateTime.UtcNow; - await timeSystem.Task.Delay(1000); + await timeSystem.Task.Delay(1000, TestContext.Current.CancellationToken); ManualResetEventSlim ms = new(); await Task.Run(async () => @@ -127,13 +125,13 @@ await Task.Run(async () => } ms.Set(); - }); - ms.Wait(); + }, TestContext.Current.CancellationToken); + ms.Wait(TestContext.Current.CancellationToken); timeSystem.TimeProvider.AdvanceBy(TimeSpan.FromMilliseconds(1000)); int mainThreadAfterCompletedTaskDelay = (int)(timeSystem.DateTime.UtcNow - start).TotalMilliseconds; - mainThreadAfterCompletedTaskDelay.Should().Be(expectedDelay); + await Expect.That(mainThreadAfterCompletedTaskDelay).IsEqualTo(expectedDelay); } [Theory] @@ -145,7 +143,7 @@ public async Task SynchronizeClock_ShouldSetNowToValueOfCurrentAsyncContext( ThreadAwareTimeProvider timeProvider = new(); MockTimeSystem timeSystem = new(timeProvider); DateTime start = timeSystem.DateTime.UtcNow; - await timeSystem.Task.Delay(1000); + await timeSystem.Task.Delay(1000, TestContext.Current.CancellationToken); int parallelTaskDelay = 0; ManualResetEventSlim ms = new(); @@ -160,12 +158,12 @@ await Task.Run(async () => } ms.Set(); - }); - ms.Wait(); + }, TestContext.Current.CancellationToken); + ms.Wait(TestContext.Current.CancellationToken); int mainThreadAfterCompletedTaskDelay = (int)(timeSystem.DateTime.UtcNow - start).TotalMilliseconds; - parallelTaskDelay.Should().Be(2000); - mainThreadAfterCompletedTaskDelay.Should().Be(expectedDelay); + await Expect.That(parallelTaskDelay).IsEqualTo(2000); + await Expect.That(mainThreadAfterCompletedTaskDelay).IsEqualTo(expectedDelay); } } diff --git a/Examples/ZipFile/ZipFile.Tests/ZipFileHelperTests.cs b/Examples/ZipFile/ZipFile.Tests/ZipFileHelperTests.cs index 9f78e572e..e518ae290 100644 --- a/Examples/ZipFile/ZipFile.Tests/ZipFileHelperTests.cs +++ b/Examples/ZipFile/ZipFile.Tests/ZipFileHelperTests.cs @@ -1,8 +1,8 @@ -using AutoFixture.Xunit2; -using FluentAssertions; +using aweXpect; using System.IO; using System.IO.Abstractions; using System.IO.Compression; +using System.Threading.Tasks; using Testably.Abstractions.Testing; using Testably.Abstractions.Testing.Initializer; using Xunit; @@ -25,8 +25,8 @@ public ZipFileHelperTests() #endregion [Theory] - [AutoData] - public void CreateZipFromDirectory_ShouldIncludeAllFilesAndSubdirectories( + [InlineData("foo")] + public async Task CreateZipFromDirectory_ShouldIncludeAllFilesAndSubdirectories( string directory) { IFileSystemDirectoryInitializer initialized @@ -47,21 +47,20 @@ IFileSystemDirectoryInitializer initialized FileSystem.File.Exists("test.zip"); ZipArchive archive = new( FileSystem.File.OpenRead("test.zip")); - archive.Entries.Count.Should().Be(4); - archive.Entries.Should() - .Contain(e => e.FullName == initialized[1].Name); - archive.Entries.Should() - .Contain(e => e.FullName == initialized[2].Name); - archive.Entries.Should() - .Contain(e => e.FullName == initialized[3].Name + "/"); - archive.Entries.Should() - .Contain( - e => e.FullName == initialized[3].Name + "/" + initialized[4].Name); + await Expect.That(archive.Entries).HasCount(4); + await Expect.That(archive.Entries) + .Contains(e => e.FullName == initialized[1].Name); + await Expect.That(archive.Entries) + .Contains(e => e.FullName == initialized[2].Name); + await Expect.That(archive.Entries) + .Contains(e => e.FullName == initialized[3].Name + "/"); + await Expect.That(archive.Entries) + .Contains(e => e.FullName == initialized[3].Name + "/" + initialized[4].Name); } [Theory] - [AutoData] - public void ExtractZipToDirectory_ShouldExtractAllFilesAndDirectories( + [InlineData("foo")] + public async Task ExtractZipToDirectory_ShouldExtractAllFilesAndDirectories( string directory) { IFileSystemDirectoryInitializer initialized @@ -80,21 +79,18 @@ IFileSystemDirectoryInitializer initialized zipStream.CopyTo(fileStream); } - FileSystem.Directory - .GetFileSystemEntries(directory, "*", SearchOption.AllDirectories) - .Should() - .BeEmpty(); + await Expect.That(FileSystem.Directory + .GetFileSystemEntries(directory, "*", SearchOption.AllDirectories)) + .IsEmpty(); ZipFileHelper.ExtractZipToDirectory(FileSystem.File.OpenRead("test.zip"), directory); - FileSystem.Directory - .GetFileSystemEntries(directory, "*", SearchOption.AllDirectories) - .Should() - .HaveCount(4); - FileSystem - .File.ReadAllBytes(FileSystem.Path.Combine(directory, initialized[2].Name)) - .Should() - .BeEquivalentTo(FileSystem.File.ReadAllBytes(initialized[2].FullName)); + await Expect.That(FileSystem.Directory + .GetFileSystemEntries(directory, "*", SearchOption.AllDirectories)) + .HasCount(4); + await Expect.That(FileSystem + .File.ReadAllBytes(FileSystem.Path.Combine(directory, initialized[2].Name))) + .IsEqualTo(FileSystem.File.ReadAllBytes(initialized[2].FullName)); } }