Skip to content

Commit 3386304

Browse files
authored
refactor: use aweXpect (#682)
Start using [aweXpect](https://github.com/aweXpect/aweXpect) as an assertion library: - Testably.Abstractions.AccessControl.Tests - Testably.Abstractions.Parity.Tests
1 parent c323447 commit 3386304

File tree

20 files changed

+280
-300
lines changed

20 files changed

+280
-300
lines changed

Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<ItemGroup>
2323
<PackageVersion Include="AutoFixture.AutoNSubstitute" Version="4.18.1" />
2424
<PackageVersion Include="AutoFixture.Xunit2" Version="4.18.1" />
25+
<PackageVersion Include="aweXpect" Version="0.7.0" />
2526
<PackageVersion Include="FluentAssertions" Version="7.0.0" />
2627
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
2728
<PackageVersion Include="Xunit.SkippableFact" Version="1.4.13" />

Tests/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
</PropertyGroup>
2525

2626
<ItemGroup>
27+
<PackageReference Include="aweXpect" />
2728
<PackageReference Include="AutoFixture.Xunit2" />
28-
<PackageReference Include="FluentAssertions" />
2929
<PackageReference Include="Microsoft.NET.Test.Sdk" />
3030
<PackageReference Include="Xunit.SkippableFact" />
3131
<PackageReference Include="xunit" />

Tests/Helpers/Testably.Abstractions.TestHelpers/Testably.Abstractions.TestHelpers.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
</ItemGroup>
2020

2121
<ItemGroup>
22+
<PackageReference Include="FluentAssertions" />
2223
<PackageReference Include="AutoFixture.AutoNSubstitute" />
23-
<PackageReference Include="AutoFixture.Xunit2" />
2424
<PackageReference Remove="Microsoft.NET.Test.Sdk" />
2525
<PackageReference Remove="xunit" />
2626
<PackageReference Remove="xunit.runner.visualstudio" />

Tests/Helpers/Testably.Abstractions.Tests.SourceGenerator/ClassGenerators/FileSystemClassGenerator.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ public RealFileSystemTests(ITestOutputHelper testOutputHelper, TestSettingsFixtu
9191
#if DEBUG
9292
if (fixture.RealFileSystemTests != TestSettingStatus.AlwaysEnabled)
9393
{{
94-
throw new SkipException($""Tests against the real file system are {{fixture.RealFileSystemTests}}. You can enable them by executing the corresponding tests in Testably.Abstractions.TestSettings.RealFileSystemTests."");
94+
throw new Xunit.SkipException($""Tests against the real file system are {{fixture.RealFileSystemTests}}. You can enable them by executing the corresponding tests in Testably.Abstractions.TestSettings.RealFileSystemTests."");
9595
}}
9696
#else
9797
if (fixture.RealFileSystemTests == TestSettingStatus.AlwaysDisabled)
9898
{{
99-
throw new SkipException($""Tests against the real file system are {{fixture.RealFileSystemTests}}. You can enable them by executing the corresponding tests in Testably.Abstractions.TestSettings.RealFileSystemTests."");
99+
throw new Xunit.SkipException($""Tests against the real file system are {{fixture.RealFileSystemTests}}. You can enable them by executing the corresponding tests in Testably.Abstractions.TestSettings.RealFileSystemTests."");
100100
}}
101101
#endif
102102
_fixture = fixture;
@@ -111,24 +111,24 @@ public void Dispose()
111111
#if DEBUG
112112
/// <inheritdoc cref=""{@class.Name}{{TFileSystem}}.SkipIfBrittleTestsShouldBeSkipped(bool)"" />
113113
public override void SkipIfBrittleTestsShouldBeSkipped(bool condition = true)
114-
=> Skip.If(condition && _fixture.BrittleTests != TestSettingStatus.AlwaysEnabled,
114+
=> Xunit.Skip.If(condition && _fixture.BrittleTests != TestSettingStatus.AlwaysEnabled,
115115
$""Brittle tests are {{_fixture.BrittleTests}}. You can enable them by executing the corresponding tests in Testably.Abstractions.TestSettings.BrittleTests."");
116116
#else
117117
/// <inheritdoc cref=""{@class.Name}{{TFileSystem}}.SkipIfBrittleTestsShouldBeSkipped(bool)"" />
118118
public override void SkipIfBrittleTestsShouldBeSkipped(bool condition = true)
119-
=> Skip.If(condition && _fixture.BrittleTests == TestSettingStatus.AlwaysDisabled,
119+
=> Xunit.Skip.If(condition && _fixture.BrittleTests == TestSettingStatus.AlwaysDisabled,
120120
$""Brittle tests are {{_fixture.BrittleTests}}. You can enable them by executing the corresponding tests in Testably.Abstractions.TestSettings.BrittleTests."");
121121
#endif
122122
123123
#if DEBUG
124124
/// <inheritdoc cref=""{@class.Name}{{TFileSystem}}.LongRunningTestsShouldBeSkipped()"" />
125125
public override void SkipIfLongRunningTestsShouldBeSkipped()
126-
=> Skip.If(_fixture.LongRunningTests != TestSettingStatus.AlwaysEnabled,
126+
=> Xunit.Skip.If(_fixture.LongRunningTests != TestSettingStatus.AlwaysEnabled,
127127
$""Long-running tests are {{_fixture.LongRunningTests}}. You can enable them by executing the corresponding tests in Testably.Abstractions.TestSettings.LongRunningTests."");
128128
#else
129129
/// <inheritdoc cref=""{@class.Name}{{TFileSystem}}.LongRunningTestsShouldBeSkipped()"" />
130130
public override void SkipIfLongRunningTestsShouldBeSkipped()
131-
=> Skip.If(_fixture.LongRunningTests == TestSettingStatus.AlwaysDisabled,
131+
=> Xunit.Skip.If(_fixture.LongRunningTests == TestSettingStatus.AlwaysDisabled,
132132
$""Long-running tests are {{_fixture.LongRunningTests}}. You can enable them by executing the corresponding tests in Testably.Abstractions.TestSettings.LongRunningTests."");
133133
#endif
134134
}}

Tests/Helpers/Testably.Abstractions.Tests.SourceGenerator/ClassGenerators/TimeSystemClassGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ public RealTimeSystemTests(TestSettingsFixture fixture) : base(new RealTimeSyste
5858
#if DEBUG
5959
/// <inheritdoc cref=""{@class.Name}{{TTimeSystem}}.SkipIfBrittleTestsShouldBeSkipped(bool)"" />
6060
public override void SkipIfBrittleTestsShouldBeSkipped(bool condition = true)
61-
=> Skip.If(condition && _fixture.BrittleTests != TestSettingStatus.AlwaysEnabled,
61+
=> Xunit.Skip.If(condition && _fixture.BrittleTests != TestSettingStatus.AlwaysEnabled,
6262
$""Brittle tests are {{_fixture.BrittleTests}}. You can enable them by executing the corresponding tests in Testably.Abstractions.TestSettings.BrittleTests."");
6363
#else
6464
/// <inheritdoc cref=""{@class.Name}{{TTimeSystem}}.SkipIfBrittleTestsShouldBeSkipped(bool)"" />
6565
public override void SkipIfBrittleTestsShouldBeSkipped(bool condition = true)
66-
=> Skip.If(condition && _fixture.BrittleTests == TestSettingStatus.AlwaysDisabled,
66+
=> Xunit.Skip.If(condition && _fixture.BrittleTests == TestSettingStatus.AlwaysDisabled,
6767
$""Brittle tests are {{_fixture.BrittleTests}}. You can enable them by executing the corresponding tests in Testably.Abstractions.TestSettings.BrittleTests."");
6868
#endif
6969
}}
Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using System.IO;
1+
using aweXpect;
2+
using System.IO;
3+
using System.Threading.Tasks;
24

35
namespace Testably.Abstractions.AccessControl.Tests;
46

@@ -8,41 +10,26 @@ public abstract partial class AccessControlHelperTests<TFileSystem>
810
where TFileSystem : IFileSystem
911
{
1012
[SkippableFact]
11-
public void GetExtensibilityOrThrow_DirectoryInfo_ShouldNotThrow()
13+
public async Task GetExtensibilityOrThrow_DirectoryInfo_ShouldNotThrow()
1214
{
1315
IDirectoryInfo sut = FileSystem.DirectoryInfo.New("foo");
1416

15-
Exception? exception = Record.Exception(() =>
16-
{
17-
sut.GetExtensibilityOrThrow();
18-
});
19-
20-
exception.Should().BeNull();
17+
await That(() => sut.GetExtensibilityOrThrow()).Should().NotThrow();
2118
}
2219

2320
[SkippableFact]
24-
public void GetExtensibilityOrThrow_FileInfo_ShouldNotThrow()
21+
public async Task GetExtensibilityOrThrow_FileInfo_ShouldNotThrow()
2522
{
2623
IFileInfo sut = FileSystem.FileInfo.New("foo");
2724

28-
Exception? exception = Record.Exception(() =>
29-
{
30-
sut.GetExtensibilityOrThrow();
31-
});
32-
33-
exception.Should().BeNull();
25+
await That(() => sut.GetExtensibilityOrThrow()).Should().NotThrow();
3426
}
3527

3628
[SkippableFact]
37-
public void GetExtensibilityOrThrow_FileSystemStream_ShouldNotThrow()
29+
public async Task GetExtensibilityOrThrow_FileSystemStream_ShouldNotThrow()
3830
{
3931
FileSystemStream sut = FileSystem.FileStream.New("foo", FileMode.Create);
4032

41-
Exception? exception = Record.Exception(() =>
42-
{
43-
sut.GetExtensibilityOrThrow();
44-
});
45-
46-
exception.Should().BeNull();
33+
await That(() => sut.GetExtensibilityOrThrow()).Should().NotThrow();
4734
}
4835
}

Tests/Testably.Abstractions.AccessControl.Tests/DirectoryAclExtensionsTests.cs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
using aweXpect;
12
using System.Security.AccessControl;
23
using System.Threading.Tasks;
34
using Testably.Abstractions.AccessControl.Tests.TestHelpers;
5+
using Skip = Xunit.Skip;
46

57
namespace Testably.Abstractions.AccessControl.Tests;
68

@@ -10,25 +12,23 @@ public abstract partial class DirectoryAclExtensionsTests<TFileSystem>
1012
where TFileSystem : IFileSystem
1113
{
1214
[SkippableFact]
13-
public void CreateDirectory_NullDirectorySecurity_ShouldThrowArgumentNullException()
15+
public async Task CreateDirectory_NullDirectorySecurity_ShouldThrowArgumentNullException()
1416
{
1517
Skip.IfNot(Test.RunsOnWindows);
1618

1719
#pragma warning disable CA1416
18-
Exception? exception = Record.Exception(() =>
19-
{
20+
void Act() =>
2021
FileSystem.Directory.CreateDirectory("foo", null!);
21-
});
2222
#pragma warning restore CA1416
2323

24-
exception.Should().BeOfType<ArgumentNullException>()
25-
.Which.ParamName.Should().Be("directorySecurity");
24+
await That(Act).Should().Throw<ArgumentNullException>()
25+
.WithParamName("directorySecurity");
2626
}
2727

2828
[SkippableTheory]
2929
[InlineData("bar")]
3030
[InlineData("bar\\foo")]
31-
public void CreateDirectory_ShouldChangeAccessControl(string path)
31+
public async Task CreateDirectory_ShouldChangeAccessControl(string path)
3232
{
3333
Skip.IfNot(Test.RunsOnWindows);
3434

@@ -39,12 +39,12 @@ public void CreateDirectory_ShouldChangeAccessControl(string path)
3939
DirectorySecurity result = FileSystem.Directory.GetAccessControl(path);
4040
#pragma warning restore CA1416
4141

42-
result.HasSameAccessRightsAs(directorySecurity).Should().BeTrue();
43-
FileSystem.Directory.Exists(path).Should().BeTrue();
42+
await That(result.HasSameAccessRightsAs(directorySecurity)).Should().BeTrue();
43+
await That(FileSystem.Directory.Exists(path)).Should().BeTrue();
4444
}
4545

4646
[SkippableFact]
47-
public void GetAccessControl_ShouldBeInitializedWithNotNullValue()
47+
public async Task GetAccessControl_ShouldBeInitializedWithNotNullValue()
4848
{
4949
Skip.IfNot(Test.RunsOnWindows);
5050

@@ -53,13 +53,13 @@ public void GetAccessControl_ShouldBeInitializedWithNotNullValue()
5353
#pragma warning disable CA1416
5454
DirectorySecurity result =
5555
FileSystem.Directory.GetAccessControl("foo");
56-
#pragma warning restore CA1416
5756

58-
result.Should().NotBeNull();
57+
await That(result).Should().NotBeNull();
58+
#pragma warning restore CA1416
5959
}
6060

6161
[SkippableFact]
62-
public void GetAccessControl_ShouldReturnSetResult()
62+
public async Task GetAccessControl_ShouldReturnSetResult()
6363
{
6464
Skip.IfNot(Test.RunsOnWindows);
6565
Skip.If(FileSystem is RealFileSystem);
@@ -74,13 +74,13 @@ public void GetAccessControl_ShouldReturnSetResult()
7474

7575
DirectorySecurity result =
7676
FileSystem.Directory.GetAccessControl("foo");
77-
#pragma warning restore CA1416
7877

79-
result.Should().Be(originalResult);
78+
await That(result).Should().Be(originalResult);
79+
#pragma warning restore CA1416
8080
}
8181

8282
[SkippableFact]
83-
public void GetAccessControl_WithAccessControlSections_ShouldBeInitializedWithNotNullValue()
83+
public async Task GetAccessControl_WithAccessControlSections_ShouldBeInitializedWithNotNullValue()
8484
{
8585
Skip.IfNot(Test.RunsOnWindows);
8686
SkipIfLongRunningTestsShouldBeSkipped();
@@ -90,13 +90,13 @@ public void GetAccessControl_WithAccessControlSections_ShouldBeInitializedWithNo
9090
#pragma warning disable CA1416
9191
DirectorySecurity result =
9292
FileSystem.Directory.GetAccessControl("foo", AccessControlSections.None);
93-
#pragma warning restore CA1416
9493

95-
result.Should().NotBeNull();
94+
await That(result).Should().NotBeNull();
95+
#pragma warning restore CA1416
9696
}
9797

9898
[SkippableFact]
99-
public void GetAccessControl_WithAccessControlSections_ShouldReturnSetResult()
99+
public async Task GetAccessControl_WithAccessControlSections_ShouldReturnSetResult()
100100
{
101101
Skip.IfNot(Test.RunsOnWindows);
102102
Skip.If(FileSystem is RealFileSystem);
@@ -111,13 +111,13 @@ public void GetAccessControl_WithAccessControlSections_ShouldReturnSetResult()
111111

112112
DirectorySecurity result =
113113
FileSystem.Directory.GetAccessControl("foo", AccessControlSections.None);
114-
#pragma warning restore CA1416
115114

116-
result.Should().Be(originalResult);
115+
await That(result).Should().Be(originalResult);
116+
#pragma warning restore CA1416
117117
}
118118

119119
[SkippableFact]
120-
public void SetAccessControl_ShouldChangeAccessControl()
120+
public async Task SetAccessControl_ShouldChangeAccessControl()
121121
{
122122
Skip.IfNot(Test.RunsOnWindows);
123123

@@ -131,7 +131,7 @@ public void SetAccessControl_ShouldChangeAccessControl()
131131
AccessControlSections.Access);
132132
#pragma warning restore CA1416
133133

134-
currentAccessControl.HasSameAccessRightsAs(originalAccessControl)
134+
await That(currentAccessControl.HasSameAccessRightsAs(originalAccessControl))
135135
.Should().BeTrue();
136136
}
137137

@@ -154,8 +154,8 @@ public async Task SetAccessControl_ShouldNotUpdateTimes()
154154
DateTime lastAccessTimeUtc = FileSystem.File.GetLastAccessTimeUtc("foo.txt");
155155
DateTime lastWriteTimeUtc = FileSystem.File.GetLastWriteTimeUtc("foo.txt");
156156

157-
creationTimeUtc.Should().Be(previousCreationTimeUtc);
158-
lastAccessTimeUtc.Should().Be(previousLastAccessTimeUtc);
159-
lastWriteTimeUtc.Should().Be(previousLastWriteTimeUtc);
157+
await That(creationTimeUtc).Should().Be(previousCreationTimeUtc);
158+
await That(lastAccessTimeUtc).Should().Be(previousLastAccessTimeUtc);
159+
await That(lastWriteTimeUtc).Should().Be(previousLastWriteTimeUtc);
160160
}
161161
}

0 commit comments

Comments
 (0)