Skip to content

Commit c554dc3

Browse files
vbreussCopilot
authored andcommitted
fix: compile errors in Examples.sln (#822)
This PR migrates test projects from FluentAssertions and AutoFixture to aweXpect for assertion testing across multiple example projects. The primary goal is to fix compile errors in Examples.sln by updating testing dependencies and assertion syntax. ### Key changes: - Replaced FluentAssertions and AutoFixture.Xunit2 with aweXpect assertion library - Updated package references in Directory.Build.props to include aweXpect packages - Converted synchronous test methods to async Task methods to support aweXpect's async assertions
1 parent bb825e1 commit c554dc3

File tree

13 files changed

+172
-151
lines changed

13 files changed

+172
-151
lines changed

Examples/.idea/.idea.Examples/.idea/.gitignore

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Examples/.idea/.idea.Examples/.idea/indexLayout.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,44 @@
1-
using AutoFixture.Xunit2;
2-
using FluentAssertions;
3-
using System;
1+
using aweXpect;
42
using System.IO;
3+
using System.Threading.Tasks;
54
using Testably.Abstractions.Testing;
65
using Xunit;
76

87
namespace Testably.Abstractions.Examples.AccessControlLists.Tests;
98

109
public class AccessControlListTests
1110
{
11+
#region Test Setup
12+
13+
public MockFileSystem FileSystem { get; }
14+
1215
public AccessControlListTests()
1316
{
1417
FileSystem = new MockFileSystem();
1518
}
1619

17-
public MockFileSystem FileSystem { get; }
20+
#endregion
1821

1922
[Theory]
20-
[AutoData]
21-
public void ReadAllText_DeniedPath_ShouldThrowIOException(string grantedPath, string deniedPath)
23+
[InlineData("granted", "denied")]
24+
public async Task ReadAllText_DeniedPath_ShouldThrowIOException(string grantedPath,
25+
string deniedPath)
2226
{
2327
FileSystem.File.WriteAllText(grantedPath, "foo");
2428
FileSystem.File.WriteAllText(deniedPath, "bar");
25-
FileSystem.WithAccessControlStrategy(new CustomAccessControlStrategy(
26-
path => path.Contains(grantedPath)));
29+
FileSystem.WithAccessControlStrategy(
30+
new CustomAccessControlStrategy(path => path.Contains(grantedPath)));
2731

2832
string result = FileSystem.File.ReadAllText(grantedPath);
29-
result.Should().Be("foo");
33+
await Expect.That(result).IsEqualTo("foo");
3034

31-
Exception? exception = Record.Exception(() =>
35+
void Act()
3236
{
3337
FileSystem.File.ReadAllText(deniedPath);
34-
});
35-
exception.Should().BeOfType<IOException>()
36-
.Which.Message.Should()
37-
.Be($"Access to the path '{FileSystem.Path.GetFullPath(deniedPath)}' is denied.");
38+
}
39+
40+
await Expect.That(Act).Throws<IOException>()
41+
.WithMessage(
42+
$"Access to the path '{FileSystem.Path.GetFullPath(deniedPath)}' is denied.");
3843
}
3944
}
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
using FluentAssertions;
1+
using aweXpect;
22
using Microsoft.Extensions.DependencyInjection;
33
using System.IO.Abstractions;
4+
using System.Threading.Tasks;
45
using Xunit;
56

67
namespace Testably.Abstractions.Examples.Configuration.DependencyInjection.Tests;
78

89
public class DependencyInjectionTests
910
{
1011
[Fact]
11-
public void
12+
public async Task
1213
DependencyInjection_Microsoft_ShouldAllowRegistrationAndCreationOfInstances()
1314
{
1415
ServiceProvider services = new ServiceCollection()
@@ -17,8 +18,8 @@ public void
1718
.AddSingleton<ITimeSystem, RealTimeSystem>()
1819
.BuildServiceProvider();
1920

20-
services.GetService<IFileSystem>().Should().BeOfType<RealFileSystem>();
21-
services.GetService<IRandomSystem>().Should().BeOfType<RealRandomSystem>();
22-
services.GetService<ITimeSystem>().Should().BeOfType<RealTimeSystem>();
21+
await Expect.That(services.GetService<IFileSystem>()).Is<RealFileSystem>();
22+
await Expect.That(services.GetService<IRandomSystem>()).Is<RealRandomSystem>();
23+
await Expect.That(services.GetService<ITimeSystem>()).Is<RealTimeSystem>();
2324
}
2425
}
Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
using AutoFixture.Xunit2;
2-
using FluentAssertions;
3-
using System;
1+
using aweXpect;
42
using System.IO;
53
using System.IO.Abstractions;
6-
using System.Linq;
74
using System.Runtime.InteropServices;
5+
using System.Threading.Tasks;
86
using Testably.Abstractions.RandomSystem;
97
using Testably.Abstractions.Testing;
108
using Xunit;
@@ -18,18 +16,16 @@ public class InitializationTests
1816
/// - a randomly named directory
1917
/// </summary>
2018
[Theory]
21-
[AutoData]
22-
public void InitializeFileSystemInSpecifiedCurrentDirectory(string currentDirectory)
19+
[InlineData("foo")]
20+
public async Task InitializeFileSystemInSpecifiedCurrentDirectory(string currentDirectory)
2321
{
2422
MockFileSystem fileSystem = new();
2523
string expectedDirectory = fileSystem.Path.GetFullPath(currentDirectory);
2624

2725
fileSystem.InitializeIn(currentDirectory)
2826
.WithASubdirectory();
2927

30-
fileSystem.Directory.GetCurrentDirectory()
31-
.Should()
32-
.Be(expectedDirectory);
28+
await Expect.That(fileSystem.Directory.GetCurrentDirectory()).IsEqualTo(expectedDirectory);
3329
}
3430

3531
/// <summary>
@@ -39,7 +35,7 @@ public void InitializeFileSystemInSpecifiedCurrentDirectory(string currentDirect
3935
/// - a file named "bar.txt"
4036
/// </summary>
4137
[Fact]
42-
public void InitializeFileSystemInTheRootDirectory()
38+
public async Task InitializeFileSystemInTheRootDirectory()
4339
{
4440
MockFileSystem fileSystem = new();
4541
fileSystem.InitializeIn("base-directory")
@@ -49,9 +45,9 @@ public void InitializeFileSystemInTheRootDirectory()
4945
.WithAFile())
5046
.WithFile("bar.txt");
5147

52-
fileSystem.File.Exists("bar.txt").Should().BeTrue();
53-
fileSystem.Directory.Exists("foo").Should().BeTrue();
54-
fileSystem.Directory.GetDirectories(".").Length.Should().Be(2);
48+
await Expect.That(fileSystem.File.Exists("bar.txt")).IsTrue();
49+
await Expect.That(fileSystem.Directory.Exists("foo")).IsTrue();
50+
await Expect.That(fileSystem.Directory.GetDirectories(".")).HasCount(2);
5551
}
5652

5753
/// <summary>
@@ -60,20 +56,20 @@ public void InitializeFileSystemInTheRootDirectory()
6056
/// UNC servers (or additional drives under windows) can be added if required.
6157
/// </summary>
6258
[Fact]
63-
public void InitializeFileSystemWithUncDrive()
59+
public async Task InitializeFileSystemWithUncDrive()
6460
{
6561
MockFileSystem fileSystem = new();
66-
var initialDriveCount = fileSystem.DriveInfo.GetDrives().Length;
62+
int initialDriveCount = fileSystem.DriveInfo.GetDrives().Length;
6763

6864
fileSystem.WithUncDrive(@"//unc-server");
6965

70-
fileSystem.DriveInfo.GetDrives().Should().HaveCount(initialDriveCount);
66+
await Expect.That(fileSystem.DriveInfo.GetDrives()).HasCount(initialDriveCount);
7167
IDriveInfo drive = fileSystem.DriveInfo.New(@"//unc-server");
72-
drive.IsReady.Should().BeTrue();
68+
await Expect.That(drive.IsReady).IsTrue();
7369

7470
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
7571
{
76-
fileSystem.DriveInfo.GetDrives().Should().HaveCount(initialDriveCount);
72+
await Expect.That(fileSystem.DriveInfo.GetDrives()).HasCount(initialDriveCount);
7773
}
7874
}
7975

@@ -84,7 +80,7 @@ public void InitializeFileSystemWithUncDrive()
8480
/// <see cref="IOException" />, when the limit is breached.
8581
/// </summary>
8682
[Fact]
87-
public void LimitAvailableSpaceOnDrives()
83+
public async Task LimitAvailableSpaceOnDrives()
8884
{
8985
MockFileSystem fileSystem = new();
9086
IRandom random = fileSystem.RandomSystem.Random.Shared;
@@ -96,16 +92,16 @@ public void LimitAvailableSpaceOnDrives()
9692
// Limit the main drive to 200 bytes
9793
fileSystem.WithDrive(drive => drive.SetTotalSize(200));
9894
IDriveInfo mainDrive = fileSystem.GetDefaultDrive();
99-
mainDrive.AvailableFreeSpace.Should().Be(200);
95+
await Expect.That(mainDrive.AvailableFreeSpace).IsEqualTo(200);
10096

10197
fileSystem.File.WriteAllBytes("foo", firstFileContent);
102-
mainDrive.AvailableFreeSpace.Should().Be(1);
98+
await Expect.That(mainDrive.AvailableFreeSpace).IsEqualTo(1);
10399

104-
Exception? exception = Record.Exception(() =>
100+
void Act()
105101
{
106102
fileSystem.File.WriteAllBytes("bar", secondFileContent);
107-
});
103+
}
108104

109-
exception.Should().BeOfType<IOException>();
105+
await Expect.That(Act).Throws<IOException>();
110106
}
111107
}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using AutoFixture.Xunit2;
2-
using FluentAssertions;
1+
using aweXpect;
32
using System;
3+
using System.Threading.Tasks;
44
using Testably.Abstractions.Testing;
55
using Xunit;
66

@@ -11,22 +11,22 @@ public class InterceptionTests
1111
/// <summary>
1212
/// Intercepting allows callbacks to be invoked before the change in the file system is performed.
1313
/// </summary>
14-
[Theory]
15-
[AutoData]
16-
public void Intercept(Exception customException)
14+
[Fact]
15+
public async Task Intercept()
1716
{
17+
Exception customException = new ApplicationException("bar");
1818
MockFileSystem fileSystem = new();
1919
fileSystem.Intercept.Creating(FileSystemTypes.File,
2020
_ => throw customException);
2121

2222
fileSystem.Directory.CreateDirectory("foo");
2323

24-
Exception exception = Record.Exception(() =>
24+
Exception? exception = Record.Exception(() =>
2525
{
2626
fileSystem.File.Create("foo/bar.txt");
2727
});
2828

29-
exception.Should().Be(customException);
30-
fileSystem.File.Exists("foo/bar.txt").Should().BeFalse();
29+
await Expect.That(exception).IsSameAs(customException);
30+
await Expect.That(fileSystem.File.Exists("foo/bar.txt")).IsFalse();
3131
}
3232
}

Examples/Configuration/FileSystemConfiguration.Tests/NotificationTests.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
using FluentAssertions;
1+
using aweXpect;
22
using System.Threading;
3+
using System.Threading.Tasks;
34
using Testably.Abstractions.Testing;
45
using Xunit;
56

@@ -11,7 +12,7 @@ public class NotificationTests
1112
/// Notifications allow reacting to an event after it occurred.
1213
/// </summary>
1314
[Fact]
14-
public void Notify_ManualWait()
15+
public async Task Notify_ManualWait()
1516
{
1617
ManualResetEventSlim ms = new();
1718
bool isNotified = false;
@@ -26,16 +27,16 @@ public void Notify_ManualWait()
2627
fileSystem.Directory.CreateDirectory("foo");
2728
fileSystem.File.Create("foo/bar.txt");
2829

29-
ms.Wait();
30-
fileSystem.File.Exists("foo/bar.txt").Should().BeTrue();
31-
isNotified.Should().BeTrue();
30+
ms.Wait(TestContext.Current.CancellationToken);
31+
await Expect.That(fileSystem.File.Exists("foo/bar.txt")).IsTrue();
32+
await Expect.That(isNotified).IsTrue();
3233
}
3334

3435
/// <summary>
3536
/// Notifications allow reacting to an event after it occurred.
3637
/// </summary>
3738
[Fact]
38-
public void Notify_UseAwaitableCallback()
39+
public async Task Notify_UseAwaitableCallback()
3940
{
4041
bool isNotified = false;
4142
MockFileSystem fileSystem = new();
@@ -53,7 +54,7 @@ public void Notify_UseAwaitableCallback()
5354
// If a timeout is provided, this will throw a TimeoutException if no event was triggered within 1000ms
5455
.Wait(timeout: 1000);
5556

56-
fileSystem.File.Exists("foo/bar.txt").Should().BeTrue();
57-
isNotified.Should().BeTrue();
57+
await Expect.That(fileSystem.File.Exists("foo/bar.txt")).IsTrue();
58+
await Expect.That(isNotified).IsTrue();
5859
}
5960
}

Examples/Directory.Build.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
</ItemGroup>
3333

3434
<ItemGroup>
35-
<PackageReference Include="AutoFixture.Xunit3" />
35+
<PackageReference Include="aweXpect" />
36+
<PackageReference Include="aweXpect.Testably" />
3637
<PackageReference Include="Microsoft.NET.Test.Sdk" />
3738
<PackageReference Include="xunit.v3" />
3839
<PackageReference Include="xunit.runner.visualstudio">

0 commit comments

Comments
 (0)