Skip to content

Commit

Permalink
Use in AccessControl tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vbreuss committed Dec 7, 2024
1 parent 81e1633 commit dd9e7ff
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 48 deletions.
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 Expect.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 Expect.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 Expect.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 Expect.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 Expect.That(result.HasSameAccessRightsAs(directorySecurity)).Should().BeTrue();
await Expect.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 Expect.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 Expect.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 Expect.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 Expect.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 Expect.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 Expect.That(creationTimeUtc).Should().Be(previousCreationTimeUtc);
await Expect.That(lastAccessTimeUtc).Should().Be(previousLastAccessTimeUtc);
await Expect.That(lastWriteTimeUtc).Should().Be(previousLastWriteTimeUtc);
}
}

0 comments on commit dd9e7ff

Please sign in to comment.