Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
using System.IO;
using System.Linq;
using System.Reflection;
using Testably.Abstractions.TestHelpers.Settings;
using Testably.Abstractions.Testing.Initializer;

namespace Testably.Abstractions.Testing.Tests;

public class FileSystemInitializerExtensionsTests
[Collection("RealFileSystemTests")]
public class FileSystemInitializerExtensionsTests(TestSettingsFixture fixture)
{
[Fact]
public async Task Initialize_WithAFile_ShouldCreateFile()
Expand Down Expand Up @@ -250,6 +252,7 @@ public async Task InitializeFromRealDirectory_MissingDrive_ShouldCreateDrive(
string directoryName)
{
Skip.IfNot(Test.RunsOnWindows);
SkipIfRealFileSystemShouldBeSkipped();

string tempPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
try
Expand Down Expand Up @@ -282,6 +285,8 @@ public async Task InitializeFromRealDirectory_MissingDrive_ShouldCreateDrive(
[Fact]
public async Task InitializeFromRealDirectory_ShouldCopyFileToTargetDirectory()
{
SkipIfRealFileSystemShouldBeSkipped();

MockFileSystem fileSystem = new();
string tempPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
try
Expand All @@ -305,6 +310,8 @@ public async Task InitializeFromRealDirectory_ShouldCopyFileToTargetDirectory()
public async Task
InitializeFromRealDirectory_ShouldRecursivelyCopyDirectoriesToTargetDirectory()
{
SkipIfRealFileSystemShouldBeSkipped();

MockFileSystem fileSystem = new();
string tempPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
try
Expand Down Expand Up @@ -383,4 +390,24 @@ public async Task InitializeIn_ShouldSetCurrentDirectory(string path)
await That(sut.Statistics.TotalCount).IsEqualTo(0);
await That(sut.Directory.GetCurrentDirectory()).IsEqualTo(expectedPath);
}

#region Helpers

private void SkipIfRealFileSystemShouldBeSkipped()
{
#if DEBUG
if (fixture.RealFileSystemTests != TestSettingStatus.AlwaysEnabled)
{
aweXpect.Skip.Test(
$"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)
{
aweXpect.Skip.Test($"Tests against the real file system are {fixture.RealFileSystemTests}. You can enable them by executing the corresponding tests in Testably.Abstractions.TestSettings.RealFileSystemTests.");
}
#endif
}

#endregion
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Testably.Abstractions.TestHelpers.Settings;

namespace Testably.Abstractions.Testing.Tests.TestHelpers;

[CollectionDefinition("RealFileSystemTests")]
public class FileSystemTestSettingsFixture : ICollectionFixture<TestSettingsFixture>
{
// This class has no code, and is never created. Its purpose is simply
// to be the place to apply [CollectionDefinition] and all the
// ICollectionFixture<> interfaces.
}
Loading