diff --git a/TestHelpers.Tests/MockDirectoryGetAccessControlTests.cs b/TestHelpers.Tests/MockDirectoryGetAccessControlTests.cs index d2351c076..a8f6d4521 100644 --- a/TestHelpers.Tests/MockDirectoryGetAccessControlTests.cs +++ b/TestHelpers.Tests/MockDirectoryGetAccessControlTests.cs @@ -10,17 +10,13 @@ namespace System.IO.Abstractions.TestingHelpers.Tests using XFS = MockUnixSupport; [TestFixture] + [WindowsOnly(WindowsSpecifics.AccessControlLists)] public class MockDirectoryGetAccessControlTests { [TestCase(" ")] [TestCase(" ")] public void MockDirectory_GetAccessControl_ShouldThrowArgumentExceptionIfPathContainsOnlyWhitespaces(string path) { - if (XFS.IsUnixPlatform()) - { - Assert.Inconclusive("Unix does not support ACLs."); - } - // Arrange var fileSystem = new MockFileSystem(); @@ -35,11 +31,6 @@ public void MockDirectory_GetAccessControl_ShouldThrowArgumentExceptionIfPathCon [Test] public void MockDirectory_GetAccessControl_ShouldThrowDirectoryNotFoundExceptionIfDirectoryDoesNotExistInMockData() { - if (XFS.IsUnixPlatform()) - { - Assert.Inconclusive("Unix does not support ACLs."); - } - // Arrange var fileSystem = new MockFileSystem(); var expectedDirectoryName = XFS.Path(@"c:\a"); @@ -54,11 +45,6 @@ public void MockDirectory_GetAccessControl_ShouldThrowDirectoryNotFoundException [Test] public void MockDirectory_GetAccessControl_ShouldReturnAccessControlOfDirectoryData() { - if (XFS.IsUnixPlatform()) - { - Assert.Inconclusive("Unix does not support ACLs."); - } - // Arrange var expectedDirectorySecurity = new DirectorySecurity(); expectedDirectorySecurity.SetAccessRuleProtection(false, false); diff --git a/TestHelpers.Tests/MockDirectoryInfoTests.cs b/TestHelpers.Tests/MockDirectoryInfoTests.cs index 73b5111f0..194dde31b 100644 --- a/TestHelpers.Tests/MockDirectoryInfoTests.cs +++ b/TestHelpers.Tests/MockDirectoryInfoTests.cs @@ -195,29 +195,33 @@ public void MockDirectoryInfo_EnumerateDirectories_ShouldReturnAllDirectories() Assert.AreEqual(new[] { "b", "c" }, directories); } - public static IEnumerable MockDirectoryInfo_FullName_Data + [TestCase(@"\\unc\folder", @"\\unc\folder")] + [TestCase(@"\\unc/folder\\foo", @"\\unc\folder\foo")] + [WindowsOnly(WindowsSpecifics.UNCPaths)] + public void MockDirectoryInfo_FullName_ShouldReturnNormalizedUNCPath(string directoryPath, string expectedFullName) { - get - { - yield return new object[] { XFS.Path(@"c:\temp\\folder"), XFS.Path(@"c:\temp\folder") }; - yield return new object[] { XFS.Path(@"c:\temp//folder"), XFS.Path(@"c:\temp\folder") }; - yield return new object[] { XFS.Path(@"c:\temp//\\///folder"), XFS.Path(@"c:\temp\folder") }; - if (!MockUnixSupport.IsUnixPlatform()) - { - yield return new object[] { XFS.Path(@"\\unc\folder"), XFS.Path(@"\\unc\folder") }; - yield return new object[] { XFS.Path(@"\\unc/folder\\foo"), XFS.Path(@"\\unc\folder\foo") }; - } - } + // Arrange + directoryPath = XFS.Path(directoryPath); + expectedFullName = XFS.Path(expectedFullName); + var fileSystem = new MockFileSystem(new Dictionary()); + var directoryInfo = new MockDirectoryInfo(fileSystem, directoryPath); + + // Act + var actualFullName = directoryInfo.FullName; + + // Assert + Assert.AreEqual(expectedFullName, actualFullName); } - [TestCaseSource("MockDirectoryInfo_FullName_Data")] + [TestCase(@"c:\temp\\folder", @"c:\temp\folder")] + [TestCase(@"c:\temp//folder", @"c:\temp\folder")] + [TestCase(@"c:\temp//\\///folder", @"c:\temp\folder")] public void MockDirectoryInfo_FullName_ShouldReturnNormalizedPath(string directoryPath, string expectedFullName) { // Arrange - var fileSystem = new MockFileSystem(new Dictionary - { - { XFS.Path(@"c:\temp\folder\a.txt"), "" } - }); + directoryPath = XFS.Path(directoryPath); + expectedFullName = XFS.Path(expectedFullName); + var fileSystem = new MockFileSystem(new Dictionary()); var directoryInfo = new MockDirectoryInfo(fileSystem, directoryPath); // Act diff --git a/TestHelpers.Tests/MockDirectorySetAccessControlTests.cs b/TestHelpers.Tests/MockDirectorySetAccessControlTests.cs index 9a0096284..7787f38e6 100644 --- a/TestHelpers.Tests/MockDirectorySetAccessControlTests.cs +++ b/TestHelpers.Tests/MockDirectorySetAccessControlTests.cs @@ -10,17 +10,13 @@ namespace System.IO.Abstractions.TestingHelpers.Tests using XFS = MockUnixSupport; [TestFixture] + [WindowsOnly(WindowsSpecifics.AccessControlLists)] public class MockDirectorySetAccessControlTests { [TestCase(" ")] [TestCase(" ")] public void MockDirectory_SetAccessControl_ShouldThrowArgumentExceptionIfPathContainsOnlyWhitespaces(string path) { - if (MockUnixSupport.IsUnixPlatform()) - { - Assert.Inconclusive("Unix does not support ACLs."); - } - // Arrange var fileSystem = new MockFileSystem(); var directorySecurity = new DirectorySecurity(); @@ -36,11 +32,6 @@ public void MockDirectory_SetAccessControl_ShouldThrowArgumentExceptionIfPathCon [Test] public void MockDirectory_SetAccessControl_ShouldThrowDirectoryNotFoundExceptionIfDirectoryDoesNotExistInMockData() { - if (XFS.IsUnixPlatform()) - { - Assert.Inconclusive("Unix does not support ACLs."); - } - // Arrange var fileSystem = new MockFileSystem(); var expectedFileName = XFS.Path(@"c:\a\"); @@ -56,11 +47,6 @@ public void MockDirectory_SetAccessControl_ShouldThrowDirectoryNotFoundException [Test] public void MockDirectory_SetAccessControl_ShouldReturnAccessControlOfDirectoryData() { - if (XFS.IsUnixPlatform()) - { - Assert.Inconclusive("Unix does not support ACLs."); - } - // Arrange var filePath = XFS.Path(@"c:\a\"); var fileData = new MockDirectoryData(); diff --git a/TestHelpers.Tests/MockDirectoryTests.cs b/TestHelpers.Tests/MockDirectoryTests.cs index ca2ff0437..bacf3f528 100644 --- a/TestHelpers.Tests/MockDirectoryTests.cs +++ b/TestHelpers.Tests/MockDirectoryTests.cs @@ -540,13 +540,9 @@ public void MockDirectory_CreMockDirectory_CreateDirectory_ShouldReturnDirectory } [Test] + [WindowsOnly(WindowsSpecifics.UNCPaths)] public void MockDirectory_CreateDirectory_ShouldWorkWithUNCPath() { - if (XFS.IsUnixPlatform()) - { - Assert.Inconclusive("Unix does not support ACLs."); - } - // Arrange var fileSystem = new MockFileSystem(); @@ -558,13 +554,9 @@ public void MockDirectory_CreateDirectory_ShouldWorkWithUNCPath() } [Test] + [WindowsOnly(WindowsSpecifics.UNCPaths)] public void MockDirectory_CreateDirectory_ShouldFailIfTryingToCreateUNCPathOnlyServer() { - if (XFS.IsUnixPlatform()) - { - Assert.Inconclusive("Unix does not have the concept of UNC paths."); - } - // Arrange var fileSystem = new MockFileSystem(); @@ -577,13 +569,9 @@ public void MockDirectory_CreateDirectory_ShouldFailIfTryingToCreateUNCPathOnlyS } [Test] + [WindowsOnly(WindowsSpecifics.UNCPaths)] public void MockDirectory_CreateDirectory_ShouldSucceedIfTryingToCreateUNCPathShare() { - if (XFS.IsUnixPlatform()) - { - Assert.Inconclusive("Unix does not have the concept of UNC paths."); - } - // Arrange var fileSystem = new MockFileSystem(); @@ -758,22 +746,27 @@ public void MockDirectory_GetFiles_ShouldThrowAnArgumentException_IfSearchPatter Assert.Throws(action); } - public static IEnumerable GetSearchPatternForTwoDotsExceptions() + [TestCase(@"..\")] + [TestCase(@"aaa\vv..\")] + [TestCase(@"a..\b")] + [WindowsOnly(WindowsSpecifics.StrictPathRules)] + public void MockDirectory_GetFiles_ShouldThrowAnArgumentException_IfSearchPatternContainsTwoDotsFollowedByOneBackslash(string searchPattern) { - yield return @"a../b"; - yield return @"../"; + // Arrange + var directoryPath = XFS.Path(@"c:\Foo"); + var fileSystem = new MockFileSystem(); + fileSystem.AddDirectory(directoryPath); - if (!XFS.IsUnixPlatform()) - { - // These are no problems on Unix platforms - yield return @"..\"; - yield return @"aaa\vv..\"; - yield return @"a..\b"; - } + // Act + TestDelegate action = () => fileSystem.Directory.GetFiles(directoryPath, searchPattern); + + // Assert + Assert.Throws(action); } - [TestCaseSource(typeof(MockDirectoryTests), "GetSearchPatternForTwoDotsExceptions")] - public void MockDirectory_GetFiles_ShouldThrowAnArgumentException_IfSearchPatternContainsTwoDotsFollowedByOneDirectoryPathSep(string searchPattern) + [TestCase(@"a../b")] + [TestCase(@"../")] + public void MockDirectory_GetFiles_ShouldThrowAnArgumentException_IfSearchPatternContainsTwoDotsFollowedByOneSlash(string searchPattern) { // Arrange var directoryPath = XFS.Path(@"c:\Foo"); @@ -808,13 +801,9 @@ public void MockDirectory_GetFiles_ShouldFindFilesContainingTwoOrMoreDots() [TestCase(@"""")] #endif [TestCase("aa\t")] + [WindowsOnly(WindowsSpecifics.StrictPathRules)] public void MockDirectory_GetFiles_ShouldThrowAnArgumentException_IfSearchPatternHasIllegalCharacters(string searchPattern) { - if (XFS.IsUnixPlatform()) - { - Assert.Inconclusive("Unix does not have this limitation."); - } - // Arrange var directoryPath = XFS.Path(@"c:\Foo"); var fileSystem = new MockFileSystem(); @@ -1305,13 +1294,9 @@ public void MockDirectory_Move_ShouldThrowAnIOExceptionIfBothPathAreIdentical() } [Test] + [WindowsOnly(WindowsSpecifics.Drives)] public void MockDirectory_Move_ShouldThrowAnIOExceptionIfDirectoriesAreOnDifferentVolumes() { - if(XFS.IsUnixPlatform()) - { - Assert.Inconclusive("Unix does not have the concept of volumes"); - } - // Arrange string sourcePath = XFS.Path(@"c:\a"); string destPath = XFS.Path(@"d:\v"); @@ -1470,13 +1455,9 @@ public void MockDirectory_GetAccessControl_ShouldThrowExceptionOnDirectoryNotFou } [Test] + [WindowsOnly(WindowsSpecifics.AccessControlLists)] public void MockDirectory_GetAccessControl_ShouldReturnNewDirectorySecurity() { - if (XFS.IsUnixPlatform()) - { - Assert.Inconclusive("Unix does not have the concept of UNC paths."); - } - // Arrange var fileSystem = new MockFileSystem(); fileSystem.Directory.CreateDirectory(XFS.Path(@"c:\foo\")); diff --git a/TestHelpers.Tests/MockDriveInfoFactoryTests.cs b/TestHelpers.Tests/MockDriveInfoFactoryTests.cs index a5362bd09..2b10ec883 100644 --- a/TestHelpers.Tests/MockDriveInfoFactoryTests.cs +++ b/TestHelpers.Tests/MockDriveInfoFactoryTests.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System; +using System.Linq; using NUnit.Framework; namespace System.IO.Abstractions.TestingHelpers.Tests @@ -6,16 +7,12 @@ namespace System.IO.Abstractions.TestingHelpers.Tests using XFS = MockUnixSupport; [TestFixture] + [WindowsOnly(WindowsSpecifics.Drives)] public class MockDriveInfoFactoryTests { [Test] public void MockDriveInfoFactory_GetDrives_ShouldReturnDrives() { - if (XFS.IsUnixPlatform()) - { - Assert.Inconclusive("Unix does not have the concept of drives."); - } - // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddDirectory(XFS.Path(@"C:\Test")); @@ -35,11 +32,6 @@ public void MockDriveInfoFactory_GetDrives_ShouldReturnDrives() [Test] public void MockDriveInfoFactory_GetDrives_ShouldReturnDrivesWithNoDuplicates() { - if (XFS.IsUnixPlatform()) - { - Assert.Inconclusive("Unix does not have the concept of drives."); - } - // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddDirectory(XFS.Path(@"C:\Test")); @@ -61,11 +53,6 @@ public void MockDriveInfoFactory_GetDrives_ShouldReturnDrivesWithNoDuplicates() [Test] public void MockDriveInfoFactory_GetDrives_ShouldReturnOnlyLocalDrives() { - if (XFS.IsUnixPlatform()) - { - Assert.Inconclusive("Unix does not have the concept of drives."); - } - // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddDirectory(XFS.Path(@"C:\Test")); @@ -86,11 +73,6 @@ public void MockDriveInfoFactory_GetDrives_ShouldReturnOnlyLocalDrives() [Test] public void MockDriveInfoFactory_FromDriveName_WithDriveShouldReturnDrive() { - if (XFS.IsUnixPlatform()) - { - Assert.Inconclusive("Unix does not have the concept of drives."); - } - // Arrange var fileSystem = new MockFileSystem(); var factory = new MockDriveInfoFactory(fileSystem); @@ -105,11 +87,6 @@ public void MockDriveInfoFactory_FromDriveName_WithDriveShouldReturnDrive() [Test] public void MockDriveInfoFactory_FromDriveName_WithPathShouldReturnDrive() { - if (XFS.IsUnixPlatform()) - { - Assert.Inconclusive("Unix does not have the concept of drives."); - } - // Arrange var fileSystem = new MockFileSystem(); var factory = new MockDriveInfoFactory(fileSystem); diff --git a/TestHelpers.Tests/MockDriveInfoTests.cs b/TestHelpers.Tests/MockDriveInfoTests.cs index 71aca296c..8b33fd16f 100644 --- a/TestHelpers.Tests/MockDriveInfoTests.cs +++ b/TestHelpers.Tests/MockDriveInfoTests.cs @@ -5,17 +5,13 @@ namespace System.IO.Abstractions.TestingHelpers.Tests using XFS = MockUnixSupport; [TestFixture] + [WindowsOnly(WindowsSpecifics.Drives)] public class MockDriveInfoTests { [TestCase(@"c:")] [TestCase(@"c:\")] public void MockDriveInfo_Constructor_ShouldInitializeLocalWindowsDrives(string driveName) { - if (XFS.IsUnixPlatform()) - { - Assert.Inconclusive("Unix does not have the concept of drives."); - } - // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddDirectory(XFS.Path(@"c:\Test")); @@ -31,11 +27,6 @@ public void MockDriveInfo_Constructor_ShouldInitializeLocalWindowsDrives(string [Test] public void MockDriveInfo_Constructor_ShouldInitializeLocalWindowsDrives_SpecialForWindows() { - if (XFS.IsUnixPlatform()) - { - Assert.Inconclusive("Using XFS.Path transform c into c:."); - } - // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddDirectory(XFS.Path(@"c:\Test")); @@ -51,11 +42,6 @@ public void MockDriveInfo_Constructor_ShouldInitializeLocalWindowsDrives_Special [TestCase(@"\\unctoo")] public void MockDriveInfo_Constructor_ShouldThrowExceptionIfUncPath(string driveName) { - if (XFS.IsUnixPlatform()) - { - Assert.Inconclusive("Unix does not have the concept of drives."); - } - // Arrange var fileSystem = new MockFileSystem(); @@ -69,11 +55,6 @@ public void MockDriveInfo_Constructor_ShouldThrowExceptionIfUncPath(string drive [Test] public void MockDriveInfo_RootDirectory_ShouldReturnTheDirectoryBase() { - if (XFS.IsUnixPlatform()) - { - Assert.Inconclusive("Unix does not have the concept of drives."); - } - // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddDirectory(XFS.Path(@"c:\Test")); diff --git a/TestHelpers.Tests/MockFileAppendAllLinesTests.cs b/TestHelpers.Tests/MockFileAppendAllLinesTests.cs index b6b085a80..75e94ea24 100644 --- a/TestHelpers.Tests/MockFileAppendAllLinesTests.cs +++ b/TestHelpers.Tests/MockFileAppendAllLinesTests.cs @@ -78,13 +78,9 @@ public void MockFile_AppendAllLines_ShouldThrowArgumentExceptionIfPathContainsOn [TestCase("<")] [TestCase(">")] [TestCase("|")] + [WindowsOnly(WindowsSpecifics.StrictPathRules)] public void MockFile_AppendAllLines_ShouldThrowArgumentExceptionIfPathContainsInvalidChar(string path) { - if (XFS.IsUnixPlatform()) - { - Assert.Inconclusive("Unix does not have these restrictions."); - } - // Arrange var fileSystem = new MockFileSystem(); diff --git a/TestHelpers.Tests/MockFileCreateTests.cs b/TestHelpers.Tests/MockFileCreateTests.cs index abfa03b50..0f221d152 100644 --- a/TestHelpers.Tests/MockFileCreateTests.cs +++ b/TestHelpers.Tests/MockFileCreateTests.cs @@ -110,13 +110,9 @@ public void Mockfile_Create_ShouldThrowArgumentExceptionIfPathIsZeroLength() [TestCase("<")] [TestCase(">")] [TestCase("|")] + [WindowsOnly(WindowsSpecifics.StrictPathRules)] public void MockFile_Create_ShouldThrowArgumentNullExceptionIfPathIsNull1(string path) { - if (XFS.IsUnixPlatform()) - { - Assert.Inconclusive("Unix does not have these restrictions."); - } - // Arrange var fileSystem = new MockFileSystem(); diff --git a/TestHelpers.Tests/MockFileGetAccessControlTests.cs b/TestHelpers.Tests/MockFileGetAccessControlTests.cs index 89875fac7..ba183e26f 100644 --- a/TestHelpers.Tests/MockFileGetAccessControlTests.cs +++ b/TestHelpers.Tests/MockFileGetAccessControlTests.cs @@ -10,17 +10,13 @@ namespace System.IO.Abstractions.TestingHelpers.Tests using XFS = MockUnixSupport; [TestFixture] + [WindowsOnly(WindowsSpecifics.AccessControlLists)] public class MockFileGetAccessControlTests { [TestCase(" ")] [TestCase(" ")] public void MockFile_GetAccessControl_ShouldThrowArgumentExceptionIfPathContainsOnlyWhitespaces(string path) { - if (XFS.IsUnixPlatform()) - { - Assert.Inconclusive("Unix does not support ACLs."); - } - // Arrange var fileSystem = new MockFileSystem(); @@ -34,12 +30,7 @@ public void MockFile_GetAccessControl_ShouldThrowArgumentExceptionIfPathContains [Test] public void MockFile_GetAccessControl_ShouldThrowFileNotFoundExceptionIfFileDoesNotExistInMockData() - { - if (XFS.IsUnixPlatform()) - { - Assert.Inconclusive("Unix does not support ACLs."); - } - + { // Arrange var fileSystem = new MockFileSystem(); var expectedFileName = XFS.Path(@"c:\a.txt"); @@ -54,11 +45,6 @@ public void MockFile_GetAccessControl_ShouldThrowFileNotFoundExceptionIfFileDoes [Test] public void MockFile_GetAccessControl_ShouldReturnAccessControlOfFileData() { - if (XFS.IsUnixPlatform()) - { - Assert.Inconclusive("Unix does not support ACLs."); - } - // Arrange var expectedFileSecurity = new FileSecurity(); expectedFileSecurity.SetAccessRuleProtection(false, false); diff --git a/TestHelpers.Tests/MockFileSetAccessControlTests.cs b/TestHelpers.Tests/MockFileSetAccessControlTests.cs index aca9fab1c..8390b14f1 100644 --- a/TestHelpers.Tests/MockFileSetAccessControlTests.cs +++ b/TestHelpers.Tests/MockFileSetAccessControlTests.cs @@ -10,17 +10,13 @@ namespace System.IO.Abstractions.TestingHelpers.Tests using XFS = MockUnixSupport; [TestFixture] + [WindowsOnly(WindowsSpecifics.AccessControlLists)] public class MockFileSetAccessControlTests { [TestCase(" ")] [TestCase(" ")] public void MockFile_SetAccessControl_ShouldThrowArgumentExceptionIfPathContainsOnlyWhitespaces(string path) { - if (MockUnixSupport.IsUnixPlatform()) - { - Assert.Inconclusive("Unix does not support ACLs."); - } - // Arrange var fileSystem = new MockFileSystem(); var fileSecurity = new FileSecurity(); @@ -36,11 +32,6 @@ public void MockFile_SetAccessControl_ShouldThrowArgumentExceptionIfPathContains [Test] public void MockFile_SetAccessControl_ShouldThrowFileNotFoundExceptionIfFileDoesNotExistInMockData() { - if (MockUnixSupport.IsUnixPlatform()) - { - Assert.Inconclusive("Unix does not support ACLs."); - } - // Arrange var fileSystem = new MockFileSystem(); var expectedFileName = XFS.Path(@"c:\a.txt"); @@ -57,11 +48,6 @@ public void MockFile_SetAccessControl_ShouldThrowFileNotFoundExceptionIfFileDoes [Test] public void MockFile_SetAccessControl_ShouldReturnAccessControlOfFileData() { - if (MockUnixSupport.IsUnixPlatform()) - { - Assert.Inconclusive("Unix does not support ACLs."); - } - // Arrange var filePath = XFS.Path(@"c:\a.txt"); var fileData = new MockFileData("Test content"); diff --git a/TestHelpers.Tests/MockFileTests.cs b/TestHelpers.Tests/MockFileTests.cs index d0f4a3374..86174dcaf 100644 --- a/TestHelpers.Tests/MockFileTests.cs +++ b/TestHelpers.Tests/MockFileTests.cs @@ -244,13 +244,9 @@ public void MockFile_GetAttributeOfExistingFile_ShouldReturnCorrectValue() } [Test] + [WindowsOnly(WindowsSpecifics.UNCPaths)] public void MockFile_GetAttributeOfExistingUncDirectory_ShouldReturnCorrectValue() { - if (MockUnixSupport.IsUnixPlatform()) - { - Assert.Inconclusive("Unix does not have the concept of UNC paths."); - } - var filedata = new MockFileData("test"); var fileSystem = new MockFileSystem(new Dictionary { diff --git a/TestHelpers.Tests/MockFileWriteAllBytesTests.cs b/TestHelpers.Tests/MockFileWriteAllBytesTests.cs index 435a34ea3..0b4bdf66b 100644 --- a/TestHelpers.Tests/MockFileWriteAllBytesTests.cs +++ b/TestHelpers.Tests/MockFileWriteAllBytesTests.cs @@ -47,13 +47,9 @@ public void MockFile_WriteAllBytes_ShouldThrowAnUnauthorizedAccessExceptionIfFil } [Test] + [WindowsOnly(WindowsSpecifics.StrictPathRules)] public void MockFile_WriteAllBytes_ShouldThrowAnArgumentExceptionIfContainsIllegalCharacters() { - if (MockUnixSupport.IsUnixPlatform()) - { - Assert.Inconclusive("Unix only disallows NULL characters."); - } - var fileSystem = new MockFileSystem(); fileSystem.AddDirectory(XFS.Path(@"C:")); diff --git a/TestHelpers.Tests/MockFileWriteAllLinesTests.cs b/TestHelpers.Tests/MockFileWriteAllLinesTests.cs index 170562c43..9d49edcfb 100644 --- a/TestHelpers.Tests/MockFileWriteAllLinesTests.cs +++ b/TestHelpers.Tests/MockFileWriteAllLinesTests.cs @@ -241,13 +241,9 @@ public void MockFile_WriteAllLinesGeneric_ShouldThrowAnArgumentNullExceptionIfEn } [TestCaseSource(typeof(TestDataForWriteAllLines), "ForIllegalPath")] + [WindowsOnly(WindowsSpecifics.StrictPathRules)] public void MockFile_WriteAllLinesGeneric_ShouldThrowAnArgumentExceptionIfPathContainsIllegalCharacters(TestDelegate action) - { - if (MockUnixSupport.IsUnixPlatform()) - { - Assert.Inconclusive("Unix does not have these restrictions."); - } - + { // Arrange // is done in the test case source diff --git a/TestHelpers.Tests/WindowsOnlyAttribute.cs b/TestHelpers.Tests/WindowsOnlyAttribute.cs new file mode 100644 index 000000000..b0b63d79d --- /dev/null +++ b/TestHelpers.Tests/WindowsOnlyAttribute.cs @@ -0,0 +1,29 @@ +using System; +using System.Linq; +using NUnit.Framework; +using NUnit.Framework.Interfaces; + +namespace System.IO.Abstractions.TestingHelpers.Tests +{ + internal sealed class WindowsOnlyAttribute : Attribute, ITestAction + { + private readonly string reason; + + public WindowsOnlyAttribute(string reason) + { + this.reason = reason; + } + + public ActionTargets Targets => ActionTargets.Test; + + public void BeforeTest(ITest test) + { + if (MockUnixSupport.IsUnixPlatform()) + { + Assert.Inconclusive(this.reason); + } + } + + public void AfterTest(ITest test) { } + } +} diff --git a/TestHelpers.Tests/WindowsSpecifics.cs b/TestHelpers.Tests/WindowsSpecifics.cs new file mode 100644 index 000000000..a44dea526 --- /dev/null +++ b/TestHelpers.Tests/WindowsSpecifics.cs @@ -0,0 +1,13 @@ +namespace System.IO.Abstractions.TestingHelpers.Tests +{ + internal static class WindowsSpecifics + { + public const string Drives = "Drives are a Windows-only concept"; + + public const string AccessControlLists = "ACLs are a Windows-only concept"; + + public const string UNCPaths = "UNC paths are a Windows-only concept"; + + public const string StrictPathRules = "Windows has stricter path rules than other platforms"; + } +}