Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use aweXpect #682

Merged
merged 6 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<ItemGroup>
<PackageVersion Include="AutoFixture.AutoNSubstitute" Version="4.18.1" />
<PackageVersion Include="AutoFixture.Xunit2" Version="4.18.1" />
<PackageVersion Include="aweXpect" Version="0.7.0" />
<PackageVersion Include="FluentAssertions" Version="7.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageVersion Include="Xunit.SkippableFact" Version="1.4.13" />
Expand Down
2 changes: 1 addition & 1 deletion Tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="aweXpect" />
<PackageReference Include="AutoFixture.Xunit2" />
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Xunit.SkippableFact" />
<PackageReference Include="xunit" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" />
<PackageReference Include="AutoFixture.AutoNSubstitute" />
<PackageReference Include="AutoFixture.Xunit2" />
<PackageReference Remove="Microsoft.NET.Test.Sdk" />
<PackageReference Remove="xunit" />
<PackageReference Remove="xunit.runner.visualstudio" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ public RealFileSystemTests(ITestOutputHelper testOutputHelper, TestSettingsFixtu
#if DEBUG
if (fixture.RealFileSystemTests != TestSettingStatus.AlwaysEnabled)
{{
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."");
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."");
}}
#else
if (fixture.RealFileSystemTests == TestSettingStatus.AlwaysDisabled)
{{
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."");
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."");
}}
#endif
_fixture = fixture;
Expand All @@ -111,24 +111,24 @@ public void Dispose()
#if DEBUG
/// <inheritdoc cref=""{@class.Name}{{TFileSystem}}.SkipIfBrittleTestsShouldBeSkipped(bool)"" />
public override void SkipIfBrittleTestsShouldBeSkipped(bool condition = true)
=> Skip.If(condition && _fixture.BrittleTests != TestSettingStatus.AlwaysEnabled,
=> Xunit.Skip.If(condition && _fixture.BrittleTests != TestSettingStatus.AlwaysEnabled,
$""Brittle tests are {{_fixture.BrittleTests}}. You can enable them by executing the corresponding tests in Testably.Abstractions.TestSettings.BrittleTests."");
#else
/// <inheritdoc cref=""{@class.Name}{{TFileSystem}}.SkipIfBrittleTestsShouldBeSkipped(bool)"" />
public override void SkipIfBrittleTestsShouldBeSkipped(bool condition = true)
=> Skip.If(condition && _fixture.BrittleTests == TestSettingStatus.AlwaysDisabled,
=> Xunit.Skip.If(condition && _fixture.BrittleTests == TestSettingStatus.AlwaysDisabled,
$""Brittle tests are {{_fixture.BrittleTests}}. You can enable them by executing the corresponding tests in Testably.Abstractions.TestSettings.BrittleTests."");
#endif

#if DEBUG
/// <inheritdoc cref=""{@class.Name}{{TFileSystem}}.LongRunningTestsShouldBeSkipped()"" />
public override void SkipIfLongRunningTestsShouldBeSkipped()
=> Skip.If(_fixture.LongRunningTests != TestSettingStatus.AlwaysEnabled,
=> Xunit.Skip.If(_fixture.LongRunningTests != TestSettingStatus.AlwaysEnabled,
$""Long-running tests are {{_fixture.LongRunningTests}}. You can enable them by executing the corresponding tests in Testably.Abstractions.TestSettings.LongRunningTests."");
#else
/// <inheritdoc cref=""{@class.Name}{{TFileSystem}}.LongRunningTestsShouldBeSkipped()"" />
public override void SkipIfLongRunningTestsShouldBeSkipped()
=> Skip.If(_fixture.LongRunningTests == TestSettingStatus.AlwaysDisabled,
=> Xunit.Skip.If(_fixture.LongRunningTests == TestSettingStatus.AlwaysDisabled,
$""Long-running tests are {{_fixture.LongRunningTests}}. You can enable them by executing the corresponding tests in Testably.Abstractions.TestSettings.LongRunningTests."");
#endif
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ public RealTimeSystemTests(TestSettingsFixture fixture) : base(new RealTimeSyste
#if DEBUG
/// <inheritdoc cref=""{@class.Name}{{TTimeSystem}}.SkipIfBrittleTestsShouldBeSkipped(bool)"" />
public override void SkipIfBrittleTestsShouldBeSkipped(bool condition = true)
=> Skip.If(condition && _fixture.BrittleTests != TestSettingStatus.AlwaysEnabled,
=> Xunit.Skip.If(condition && _fixture.BrittleTests != TestSettingStatus.AlwaysEnabled,
$""Brittle tests are {{_fixture.BrittleTests}}. You can enable them by executing the corresponding tests in Testably.Abstractions.TestSettings.BrittleTests."");
#else
/// <inheritdoc cref=""{@class.Name}{{TTimeSystem}}.SkipIfBrittleTestsShouldBeSkipped(bool)"" />
public override void SkipIfBrittleTestsShouldBeSkipped(bool condition = true)
=> Skip.If(condition && _fixture.BrittleTests == TestSettingStatus.AlwaysDisabled,
=> Xunit.Skip.If(condition && _fixture.BrittleTests == TestSettingStatus.AlwaysDisabled,
$""Brittle tests are {{_fixture.BrittleTests}}. You can enable them by executing the corresponding tests in Testably.Abstractions.TestSettings.BrittleTests."");
#endif
}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.IO;
using aweXpect;
using System.IO;
using System.Threading.Tasks;

namespace Testably.Abstractions.AccessControl.Tests;

Expand All @@ -8,41 +10,26 @@ public abstract partial class AccessControlHelperTests<TFileSystem>
where TFileSystem : IFileSystem
{
[SkippableFact]
public void GetExtensibilityOrThrow_DirectoryInfo_ShouldNotThrow()
public async Task GetExtensibilityOrThrow_DirectoryInfo_ShouldNotThrow()
{
IDirectoryInfo sut = FileSystem.DirectoryInfo.New("foo");

Exception? exception = Record.Exception(() =>
{
sut.GetExtensibilityOrThrow();
});

exception.Should().BeNull();
await That(() => sut.GetExtensibilityOrThrow()).Should().NotThrow();
}

[SkippableFact]
public void GetExtensibilityOrThrow_FileInfo_ShouldNotThrow()
public async Task GetExtensibilityOrThrow_FileInfo_ShouldNotThrow()
{
IFileInfo sut = FileSystem.FileInfo.New("foo");

Exception? exception = Record.Exception(() =>
{
sut.GetExtensibilityOrThrow();
});

exception.Should().BeNull();
await That(() => sut.GetExtensibilityOrThrow()).Should().NotThrow();
}

[SkippableFact]
public void GetExtensibilityOrThrow_FileSystemStream_ShouldNotThrow()
public async Task GetExtensibilityOrThrow_FileSystemStream_ShouldNotThrow()
{
FileSystemStream sut = FileSystem.FileStream.New("foo", FileMode.Create);

Exception? exception = Record.Exception(() =>
{
sut.GetExtensibilityOrThrow();
});

exception.Should().BeNull();
await That(() => sut.GetExtensibilityOrThrow()).Should().NotThrow();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using aweXpect;
using System.Security.AccessControl;
using System.Threading.Tasks;
using Testably.Abstractions.AccessControl.Tests.TestHelpers;
using Skip = Xunit.Skip;

namespace Testably.Abstractions.AccessControl.Tests;

Expand All @@ -10,25 +12,23 @@ public abstract partial class DirectoryAclExtensionsTests<TFileSystem>
where TFileSystem : IFileSystem
{
[SkippableFact]
public void CreateDirectory_NullDirectorySecurity_ShouldThrowArgumentNullException()
public async Task CreateDirectory_NullDirectorySecurity_ShouldThrowArgumentNullException()
{
Skip.IfNot(Test.RunsOnWindows);

#pragma warning disable CA1416
Exception? exception = Record.Exception(() =>
{
void Act() =>
FileSystem.Directory.CreateDirectory("foo", null!);
});
#pragma warning restore CA1416

exception.Should().BeOfType<ArgumentNullException>()
.Which.ParamName.Should().Be("directorySecurity");
await That(Act).Should().Throw<ArgumentNullException>()
.WithParamName("directorySecurity");
}

[SkippableTheory]
[InlineData("bar")]
[InlineData("bar\\foo")]
public void CreateDirectory_ShouldChangeAccessControl(string path)
public async Task CreateDirectory_ShouldChangeAccessControl(string path)
{
Skip.IfNot(Test.RunsOnWindows);

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

result.HasSameAccessRightsAs(directorySecurity).Should().BeTrue();
FileSystem.Directory.Exists(path).Should().BeTrue();
await That(result.HasSameAccessRightsAs(directorySecurity)).Should().BeTrue();
await That(FileSystem.Directory.Exists(path)).Should().BeTrue();
}

[SkippableFact]
public void GetAccessControl_ShouldBeInitializedWithNotNullValue()
public async Task GetAccessControl_ShouldBeInitializedWithNotNullValue()
{
Skip.IfNot(Test.RunsOnWindows);

Expand All @@ -53,13 +53,13 @@ public void GetAccessControl_ShouldBeInitializedWithNotNullValue()
#pragma warning disable CA1416
DirectorySecurity result =
FileSystem.Directory.GetAccessControl("foo");
#pragma warning restore CA1416

result.Should().NotBeNull();
await That(result).Should().NotBeNull();
#pragma warning restore CA1416
}

[SkippableFact]
public void GetAccessControl_ShouldReturnSetResult()
public async Task GetAccessControl_ShouldReturnSetResult()
{
Skip.IfNot(Test.RunsOnWindows);
Skip.If(FileSystem is RealFileSystem);
Expand All @@ -74,13 +74,13 @@ public void GetAccessControl_ShouldReturnSetResult()

DirectorySecurity result =
FileSystem.Directory.GetAccessControl("foo");
#pragma warning restore CA1416

result.Should().Be(originalResult);
await That(result).Should().Be(originalResult);
#pragma warning restore CA1416
}

[SkippableFact]
public void GetAccessControl_WithAccessControlSections_ShouldBeInitializedWithNotNullValue()
public async Task GetAccessControl_WithAccessControlSections_ShouldBeInitializedWithNotNullValue()
{
Skip.IfNot(Test.RunsOnWindows);
SkipIfLongRunningTestsShouldBeSkipped();
Expand All @@ -90,13 +90,13 @@ public void GetAccessControl_WithAccessControlSections_ShouldBeInitializedWithNo
#pragma warning disable CA1416
DirectorySecurity result =
FileSystem.Directory.GetAccessControl("foo", AccessControlSections.None);
#pragma warning restore CA1416

result.Should().NotBeNull();
await That(result).Should().NotBeNull();
#pragma warning restore CA1416
}

[SkippableFact]
public void GetAccessControl_WithAccessControlSections_ShouldReturnSetResult()
public async Task GetAccessControl_WithAccessControlSections_ShouldReturnSetResult()
{
Skip.IfNot(Test.RunsOnWindows);
Skip.If(FileSystem is RealFileSystem);
Expand All @@ -111,13 +111,13 @@ public void GetAccessControl_WithAccessControlSections_ShouldReturnSetResult()

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

result.Should().Be(originalResult);
await That(result).Should().Be(originalResult);
#pragma warning restore CA1416
}

[SkippableFact]
public void SetAccessControl_ShouldChangeAccessControl()
public async Task SetAccessControl_ShouldChangeAccessControl()
{
Skip.IfNot(Test.RunsOnWindows);

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

currentAccessControl.HasSameAccessRightsAs(originalAccessControl)
await That(currentAccessControl.HasSameAccessRightsAs(originalAccessControl))
.Should().BeTrue();
}

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

creationTimeUtc.Should().Be(previousCreationTimeUtc);
lastAccessTimeUtc.Should().Be(previousLastAccessTimeUtc);
lastWriteTimeUtc.Should().Be(previousLastWriteTimeUtc);
await That(creationTimeUtc).Should().Be(previousCreationTimeUtc);
await That(lastAccessTimeUtc).Should().Be(previousLastAccessTimeUtc);
await That(lastWriteTimeUtc).Should().Be(previousLastWriteTimeUtc);
}
}
Loading
Loading