From bc9f696f034cd4966eec5f411796bf5183194b1e Mon Sep 17 00:00:00 2001 From: Florian Greinacher Date: Mon, 9 Jul 2018 21:09:27 +0200 Subject: [PATCH 1/8] Introduce SkipOnUnixAttribute and use it to simplify tests --- .../MockDirectoryGetAccessControlTests.cs | 16 +-------- .../MockDirectorySetAccessControlTests.cs | 16 +-------- TestHelpers.Tests/MockDirectoryTests.cs | 30 +++------------- .../MockDriveInfoFactoryTests.cs | 29 ++------------- TestHelpers.Tests/MockDriveInfoTests.cs | 21 +---------- .../MockFileGetAccessControlTests.cs | 18 ++-------- .../MockFileSetAccessControlTests.cs | 16 +-------- TestHelpers.Tests/MockFileTests.cs | 6 +--- TestHelpers.Tests/SkipOnUnixAttribute.cs | 36 +++++++++++++++++++ 9 files changed, 51 insertions(+), 137 deletions(-) create mode 100644 TestHelpers.Tests/SkipOnUnixAttribute.cs diff --git a/TestHelpers.Tests/MockDirectoryGetAccessControlTests.cs b/TestHelpers.Tests/MockDirectoryGetAccessControlTests.cs index aac126984..de5541217 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] + [SkipOnUnix(SkipReason.NoACLsOnUnix)] public class MockDirectoryGetAccessControlTests { [TestCase(" ")] [TestCase(" ")] public void MockDirectory_GetAccessControl_ShouldThrowArgumentExceptionIfPathContainsOnlyWhitespaces(string path) { - if (MockUnixSupport.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 (MockUnixSupport.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 (MockUnixSupport.IsUnixPlatform()) - { - Assert.Inconclusive("Unix does not support ACLs."); - } - // Arrange var expectedDirectorySecurity = new DirectorySecurity(); expectedDirectorySecurity.SetAccessRuleProtection(false, false); diff --git a/TestHelpers.Tests/MockDirectorySetAccessControlTests.cs b/TestHelpers.Tests/MockDirectorySetAccessControlTests.cs index 92b69a96d..c4e6bd4d0 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] + [SkipOnUnix(SkipReason.NoACLsOnUnix)] 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 (MockUnixSupport.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 (MockUnixSupport.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 5381e689f..804681e8a 100644 --- a/TestHelpers.Tests/MockDirectoryTests.cs +++ b/TestHelpers.Tests/MockDirectoryTests.cs @@ -540,13 +540,9 @@ public void MockDirectory_CreMockDirectory_CreateDirectory_ShouldReturnDirectory } [Test] + [SkipOnUnix(SkipReason.NoUNCPathsOnUnix)] public void MockDirectory_CreateDirectory_ShouldWorkWithUNCPath() { - if (MockUnixSupport.IsUnixPlatform()) - { - Assert.Inconclusive("Unix does not support ACLs."); - } - // Arrange var fileSystem = new MockFileSystem(); @@ -558,13 +554,9 @@ public void MockDirectory_CreateDirectory_ShouldWorkWithUNCPath() } [Test] + [SkipOnUnix(SkipReason.NoUNCPathsOnUnix)] public void MockDirectory_CreateDirectory_ShouldFailIfTryingToCreateUNCPathOnlyServer() { - if (MockUnixSupport.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] + [SkipOnUnix(SkipReason.NoUNCPathsOnUnix)] public void MockDirectory_CreateDirectory_ShouldSucceedIfTryingToCreateUNCPathShare() { - if (MockUnixSupport.IsUnixPlatform()) - { - Assert.Inconclusive("Unix does not have the concept of UNC paths."); - } - // Arrange var fileSystem = new MockFileSystem(); @@ -1305,13 +1293,9 @@ public void MockDirectory_Move_ShouldThrowAnIOExceptionIfBothPathAreIdentical() } [Test] + [SkipOnUnix(SkipReason.NoDrivesOnUnix)] 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 +1454,9 @@ public void MockDirectory_GetAccessControl_ShouldThrowExceptionOnDirectoryNotFou } [Test] + [SkipOnUnix(SkipReason.NoACLsOnUnix)] public void MockDirectory_GetAccessControl_ShouldReturnNewDirectorySecurity() { - if (MockUnixSupport.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 59c3efee6..b8924821a 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] + [SkipOnUnix(SkipReason.NoDrivesOnUnix)] public class MockDriveInfoFactoryTests { [Test] public void MockDriveInfoFactory_GetDrives_ShouldReturnDrives() { - if (MockUnixSupport.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 (MockUnixSupport.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 (MockUnixSupport.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 (MockUnixSupport.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 (MockUnixSupport.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..2b823710b 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] + [SkipOnUnix(SkipReason.NoDrivesOnUnix)] 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/MockFileGetAccessControlTests.cs b/TestHelpers.Tests/MockFileGetAccessControlTests.cs index 8c9b94c1a..a4f28b258 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] + [SkipOnUnix(SkipReason.NoACLsOnUnix)] public class MockFileGetAccessControlTests { [TestCase(" ")] [TestCase(" ")] public void MockFile_GetAccessControl_ShouldThrowArgumentExceptionIfPathContainsOnlyWhitespaces(string path) { - if (MockUnixSupport.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 (MockUnixSupport.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 (MockUnixSupport.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..063d904d6 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] + [SkipOnUnix(SkipReason.NoACLsOnUnix)] 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..bb62844ab 100644 --- a/TestHelpers.Tests/MockFileTests.cs +++ b/TestHelpers.Tests/MockFileTests.cs @@ -244,13 +244,9 @@ public void MockFile_GetAttributeOfExistingFile_ShouldReturnCorrectValue() } [Test] + [SkipOnUnix(SkipReason.NoUNCPathsOnUnix)] 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/SkipOnUnixAttribute.cs b/TestHelpers.Tests/SkipOnUnixAttribute.cs new file mode 100644 index 000000000..24a5549e7 --- /dev/null +++ b/TestHelpers.Tests/SkipOnUnixAttribute.cs @@ -0,0 +1,36 @@ +using System; +using System.Linq; +using NUnit.Framework; +using NUnit.Framework.Interfaces; + +namespace System.IO.Abstractions.TestingHelpers.Tests +{ + internal static class SkipReason + { + public const string NoDrivesOnUnix = "Unix does not have the concept of Drives"; + public const string NoACLsOnUnix = "Unix does not support ACLs"; + public const string NoUNCPathsOnUnix = "Unix does not have the concept of UNC paths"; + } + + internal sealed class SkipOnUnixAttribute : Attribute, ITestAction + { + private readonly string reason; + + public SkipOnUnixAttribute(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) { } + } +} From 947820f2e8a52c490419b806a5e7922cd54160d5 Mon Sep 17 00:00:00 2001 From: Florian Greinacher Date: Mon, 9 Jul 2018 22:57:50 +0200 Subject: [PATCH 2/8] Move SkipReason to separate file --- TestHelpers.Tests/SkipOnUnixAttribute.cs | 7 ------- TestHelpers.Tests/SkipReason.cs | 10 ++++++++++ 2 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 TestHelpers.Tests/SkipReason.cs diff --git a/TestHelpers.Tests/SkipOnUnixAttribute.cs b/TestHelpers.Tests/SkipOnUnixAttribute.cs index 24a5549e7..51eb9e2c3 100644 --- a/TestHelpers.Tests/SkipOnUnixAttribute.cs +++ b/TestHelpers.Tests/SkipOnUnixAttribute.cs @@ -5,13 +5,6 @@ namespace System.IO.Abstractions.TestingHelpers.Tests { - internal static class SkipReason - { - public const string NoDrivesOnUnix = "Unix does not have the concept of Drives"; - public const string NoACLsOnUnix = "Unix does not support ACLs"; - public const string NoUNCPathsOnUnix = "Unix does not have the concept of UNC paths"; - } - internal sealed class SkipOnUnixAttribute : Attribute, ITestAction { private readonly string reason; diff --git a/TestHelpers.Tests/SkipReason.cs b/TestHelpers.Tests/SkipReason.cs new file mode 100644 index 000000000..1339447ad --- /dev/null +++ b/TestHelpers.Tests/SkipReason.cs @@ -0,0 +1,10 @@ +namespace System.IO.Abstractions.TestingHelpers.Tests +{ + internal static class SkipReason + { + public const string NoDrivesOnUnix = "Unix does not have the concept of Drives"; + public const string NoACLsOnUnix = "Unix does not support ACLs"; + public const string NoUNCPathsOnUnix = "Unix does not have the concept of UNC paths"; + public const string WindowsOnlyPathRestrictions = "Unix does not have this path restriction"; + } +} From 6d58566d2e2459665222aa654b94e7af1f2b2d4d Mon Sep 17 00:00:00 2001 From: Florian Greinacher Date: Mon, 9 Jul 2018 22:58:12 +0200 Subject: [PATCH 3/8] Use SkipOnUnix for more tests --- TestHelpers.Tests/MockDirectoryInfoTests.cs | 21 ++++++++++---- TestHelpers.Tests/MockDirectoryTests.cs | 28 ++++++++++--------- .../MockFileAppendAllLinesTests.cs | 6 +--- TestHelpers.Tests/MockFileCreateTests.cs | 6 +--- .../MockFileWriteAllBytesTests.cs | 6 +--- .../MockFileWriteAllLinesTests.cs | 8 ++---- 6 files changed, 36 insertions(+), 39 deletions(-) diff --git a/TestHelpers.Tests/MockDirectoryInfoTests.cs b/TestHelpers.Tests/MockDirectoryInfoTests.cs index 73b5111f0..aef850899 100644 --- a/TestHelpers.Tests/MockDirectoryInfoTests.cs +++ b/TestHelpers.Tests/MockDirectoryInfoTests.cs @@ -202,14 +202,25 @@ public static IEnumerable MockDirectoryInfo_FullName_Data 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") }; - } } } + public static IEnumerable MockDirectoryInfo_FullName_Data_WindowsOnly + { + get + { + 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") }; + } + } + + [TestCaseSource("MockDirectoryInfo_FullName_Data_WindowsOnly")] + [SkipOnUnix(SkipReason.NoUNCPathsOnUnix)] + public void MockDirectoryInfo_FullName_ShouldReturnNormalizedPath_WindowsOnly(string directoryPath, string expectedFullName) + { + MockDirectoryInfo_FullName_ShouldReturnNormalizedPath(directoryPath, expectedFullName); + } + [TestCaseSource("MockDirectoryInfo_FullName_Data")] public void MockDirectoryInfo_FullName_ShouldReturnNormalizedPath(string directoryPath, string expectedFullName) { diff --git a/TestHelpers.Tests/MockDirectoryTests.cs b/TestHelpers.Tests/MockDirectoryTests.cs index 804681e8a..12659b354 100644 --- a/TestHelpers.Tests/MockDirectoryTests.cs +++ b/TestHelpers.Tests/MockDirectoryTests.cs @@ -746,18 +746,24 @@ public void MockDirectory_GetFiles_ShouldThrowAnArgumentException_IfSearchPatter Assert.Throws(action); } + public static IEnumerable GetSearchPatternForTwoDotsExceptions_WindowsOnly() + { + yield return @"..\"; + yield return @"aaa\vv..\"; + yield return @"a..\b"; + } + + [TestCaseSource(typeof(MockDirectoryTests), "GetSearchPatternForTwoDotsExceptions_WindowsOnly")] + [SkipOnUnix(SkipReason.WindowsOnlyPathRestrictions)] + public void MockDirectory_GetFiles_ShouldThrowAnArgumentException_IfSearchPatternContainsTwoDotsFollowedByOneDirectoryPathSep_WindowsOnly(string searchPattern) + { + MockDirectory_GetFiles_ShouldThrowAnArgumentException_IfSearchPatternContainsTwoDotsFollowedByOneDirectoryPathSep(searchPattern); + } + public static IEnumerable GetSearchPatternForTwoDotsExceptions() { yield return @"a../b"; yield return @"../"; - - if (!MockUnixSupport.IsUnixPlatform()) - { - // These are no problem on Unix platforms - yield return @"..\"; - yield return @"aaa\vv..\"; - yield return @"a..\b"; - } } [TestCaseSource(typeof(MockDirectoryTests), "GetSearchPatternForTwoDotsExceptions")] @@ -796,13 +802,9 @@ public void MockDirectory_GetFiles_ShouldFindFilesContainingTwoOrMoreDots() [TestCase(@"""")] #endif [TestCase("aa\t")] + [SkipOnUnix(SkipReason.WindowsOnlyPathRestrictions)] public void MockDirectory_GetFiles_ShouldThrowAnArgumentException_IfSearchPatternHasIllegalCharacters(string searchPattern) { - if (MockUnixSupport.IsUnixPlatform()) - { - Assert.Inconclusive("Unix does not have this limitation."); - } - // Arrange var directoryPath = XFS.Path(@"c:\Foo"); var fileSystem = new MockFileSystem(); diff --git a/TestHelpers.Tests/MockFileAppendAllLinesTests.cs b/TestHelpers.Tests/MockFileAppendAllLinesTests.cs index 2e5720f8c..d69a9b51b 100644 --- a/TestHelpers.Tests/MockFileAppendAllLinesTests.cs +++ b/TestHelpers.Tests/MockFileAppendAllLinesTests.cs @@ -78,13 +78,9 @@ public void MockFile_AppendAllLines_ShouldThrowArgumentExceptionIfPathContainsOn [TestCase("<")] [TestCase(">")] [TestCase("|")] + [SkipOnUnix(SkipReason.WindowsOnlyPathRestrictions)] public void MockFile_AppendAllLines_ShouldThrowArgumentExceptionIfPathContainsInvalidChar(string path) { - if (MockUnixSupport.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 7e285ead1..b6ac82f63 100644 --- a/TestHelpers.Tests/MockFileCreateTests.cs +++ b/TestHelpers.Tests/MockFileCreateTests.cs @@ -110,13 +110,9 @@ public void Mockfile_Create_ShouldThrowArgumentExceptionIfPathIsZeroLength() [TestCase("<")] [TestCase(">")] [TestCase("|")] + [SkipOnUnix(SkipReason.WindowsOnlyPathRestrictions)] public void MockFile_Create_ShouldThrowArgumentNullExceptionIfPathIsNull1(string path) { - if (MockUnixSupport.IsUnixPlatform()) - { - Assert.Inconclusive("Unix does not have these restrictions."); - } - // Arrange var fileSystem = new MockFileSystem(); diff --git a/TestHelpers.Tests/MockFileWriteAllBytesTests.cs b/TestHelpers.Tests/MockFileWriteAllBytesTests.cs index 435a34ea3..4cc6094eb 100644 --- a/TestHelpers.Tests/MockFileWriteAllBytesTests.cs +++ b/TestHelpers.Tests/MockFileWriteAllBytesTests.cs @@ -47,13 +47,9 @@ public void MockFile_WriteAllBytes_ShouldThrowAnUnauthorizedAccessExceptionIfFil } [Test] + [SkipOnUnix(SkipReason.WindowsOnlyPathRestrictions)] 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..835be0ccd 100644 --- a/TestHelpers.Tests/MockFileWriteAllLinesTests.cs +++ b/TestHelpers.Tests/MockFileWriteAllLinesTests.cs @@ -241,13 +241,9 @@ public void MockFile_WriteAllLinesGeneric_ShouldThrowAnArgumentNullExceptionIfEn } [TestCaseSource(typeof(TestDataForWriteAllLines), "ForIllegalPath")] + [SkipOnUnix(SkipReason.WindowsOnlyPathRestrictions)] 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 From 85033c0d096995d6b68016354a40cf7893fd266c Mon Sep 17 00:00:00 2001 From: Florian Greinacher Date: Tue, 10 Jul 2018 21:15:59 +0200 Subject: [PATCH 4/8] Rename SkipOnUnixAttribute to WindowsOnlyAttribute --- .../MockDirectoryGetAccessControlTests.cs | 2 +- TestHelpers.Tests/MockDirectoryInfoTests.cs | 2 +- .../MockDirectorySetAccessControlTests.cs | 2 +- TestHelpers.Tests/MockDirectoryTests.cs | 14 +++++++------- TestHelpers.Tests/MockDriveInfoFactoryTests.cs | 2 +- TestHelpers.Tests/MockDriveInfoTests.cs | 2 +- TestHelpers.Tests/MockFileAppendAllLinesTests.cs | 2 +- TestHelpers.Tests/MockFileCreateTests.cs | 2 +- TestHelpers.Tests/MockFileGetAccessControlTests.cs | 2 +- TestHelpers.Tests/MockFileSetAccessControlTests.cs | 2 +- TestHelpers.Tests/MockFileTests.cs | 2 +- TestHelpers.Tests/MockFileWriteAllBytesTests.cs | 2 +- TestHelpers.Tests/MockFileWriteAllLinesTests.cs | 2 +- TestHelpers.Tests/SkipReason.cs | 10 ---------- ...pOnUnixAttribute.cs => WindowsOnlyAttribute.cs} | 4 ++-- TestHelpers.Tests/WindowsSpecifics.cs | 13 +++++++++++++ 16 files changed, 34 insertions(+), 31 deletions(-) delete mode 100644 TestHelpers.Tests/SkipReason.cs rename TestHelpers.Tests/{SkipOnUnixAttribute.cs => WindowsOnlyAttribute.cs} (81%) create mode 100644 TestHelpers.Tests/WindowsSpecifics.cs diff --git a/TestHelpers.Tests/MockDirectoryGetAccessControlTests.cs b/TestHelpers.Tests/MockDirectoryGetAccessControlTests.cs index de5541217..a8f6d4521 100644 --- a/TestHelpers.Tests/MockDirectoryGetAccessControlTests.cs +++ b/TestHelpers.Tests/MockDirectoryGetAccessControlTests.cs @@ -10,7 +10,7 @@ namespace System.IO.Abstractions.TestingHelpers.Tests using XFS = MockUnixSupport; [TestFixture] - [SkipOnUnix(SkipReason.NoACLsOnUnix)] + [WindowsOnly(WindowsSpecifics.AccessControlLists)] public class MockDirectoryGetAccessControlTests { [TestCase(" ")] diff --git a/TestHelpers.Tests/MockDirectoryInfoTests.cs b/TestHelpers.Tests/MockDirectoryInfoTests.cs index aef850899..dfd24d692 100644 --- a/TestHelpers.Tests/MockDirectoryInfoTests.cs +++ b/TestHelpers.Tests/MockDirectoryInfoTests.cs @@ -215,7 +215,7 @@ public static IEnumerable MockDirectoryInfo_FullName_Data_WindowsOnly } [TestCaseSource("MockDirectoryInfo_FullName_Data_WindowsOnly")] - [SkipOnUnix(SkipReason.NoUNCPathsOnUnix)] + [WindowsOnly(WindowsSpecifics.UNCPaths)] public void MockDirectoryInfo_FullName_ShouldReturnNormalizedPath_WindowsOnly(string directoryPath, string expectedFullName) { MockDirectoryInfo_FullName_ShouldReturnNormalizedPath(directoryPath, expectedFullName); diff --git a/TestHelpers.Tests/MockDirectorySetAccessControlTests.cs b/TestHelpers.Tests/MockDirectorySetAccessControlTests.cs index c4e6bd4d0..7787f38e6 100644 --- a/TestHelpers.Tests/MockDirectorySetAccessControlTests.cs +++ b/TestHelpers.Tests/MockDirectorySetAccessControlTests.cs @@ -10,7 +10,7 @@ namespace System.IO.Abstractions.TestingHelpers.Tests using XFS = MockUnixSupport; [TestFixture] - [SkipOnUnix(SkipReason.NoACLsOnUnix)] + [WindowsOnly(WindowsSpecifics.AccessControlLists)] public class MockDirectorySetAccessControlTests { [TestCase(" ")] diff --git a/TestHelpers.Tests/MockDirectoryTests.cs b/TestHelpers.Tests/MockDirectoryTests.cs index 12659b354..f7a741f29 100644 --- a/TestHelpers.Tests/MockDirectoryTests.cs +++ b/TestHelpers.Tests/MockDirectoryTests.cs @@ -540,7 +540,7 @@ public void MockDirectory_CreMockDirectory_CreateDirectory_ShouldReturnDirectory } [Test] - [SkipOnUnix(SkipReason.NoUNCPathsOnUnix)] + [WindowsOnly(WindowsSpecifics.UNCPaths)] public void MockDirectory_CreateDirectory_ShouldWorkWithUNCPath() { // Arrange @@ -554,7 +554,7 @@ public void MockDirectory_CreateDirectory_ShouldWorkWithUNCPath() } [Test] - [SkipOnUnix(SkipReason.NoUNCPathsOnUnix)] + [WindowsOnly(WindowsSpecifics.UNCPaths)] public void MockDirectory_CreateDirectory_ShouldFailIfTryingToCreateUNCPathOnlyServer() { // Arrange @@ -569,7 +569,7 @@ public void MockDirectory_CreateDirectory_ShouldFailIfTryingToCreateUNCPathOnlyS } [Test] - [SkipOnUnix(SkipReason.NoUNCPathsOnUnix)] + [WindowsOnly(WindowsSpecifics.UNCPaths)] public void MockDirectory_CreateDirectory_ShouldSucceedIfTryingToCreateUNCPathShare() { // Arrange @@ -754,7 +754,7 @@ public static IEnumerable GetSearchPatternForTwoDotsExceptions_WindowsOn } [TestCaseSource(typeof(MockDirectoryTests), "GetSearchPatternForTwoDotsExceptions_WindowsOnly")] - [SkipOnUnix(SkipReason.WindowsOnlyPathRestrictions)] + [WindowsOnly(WindowsSpecifics.StrictPathRules)] public void MockDirectory_GetFiles_ShouldThrowAnArgumentException_IfSearchPatternContainsTwoDotsFollowedByOneDirectoryPathSep_WindowsOnly(string searchPattern) { MockDirectory_GetFiles_ShouldThrowAnArgumentException_IfSearchPatternContainsTwoDotsFollowedByOneDirectoryPathSep(searchPattern); @@ -802,7 +802,7 @@ public void MockDirectory_GetFiles_ShouldFindFilesContainingTwoOrMoreDots() [TestCase(@"""")] #endif [TestCase("aa\t")] - [SkipOnUnix(SkipReason.WindowsOnlyPathRestrictions)] + [WindowsOnly(WindowsSpecifics.StrictPathRules)] public void MockDirectory_GetFiles_ShouldThrowAnArgumentException_IfSearchPatternHasIllegalCharacters(string searchPattern) { // Arrange @@ -1295,7 +1295,7 @@ public void MockDirectory_Move_ShouldThrowAnIOExceptionIfBothPathAreIdentical() } [Test] - [SkipOnUnix(SkipReason.NoDrivesOnUnix)] + [WindowsOnly(WindowsSpecifics.Drives)] public void MockDirectory_Move_ShouldThrowAnIOExceptionIfDirectoriesAreOnDifferentVolumes() { // Arrange @@ -1456,7 +1456,7 @@ public void MockDirectory_GetAccessControl_ShouldThrowExceptionOnDirectoryNotFou } [Test] - [SkipOnUnix(SkipReason.NoACLsOnUnix)] + [WindowsOnly(WindowsSpecifics.AccessControlLists)] public void MockDirectory_GetAccessControl_ShouldReturnNewDirectorySecurity() { // Arrange diff --git a/TestHelpers.Tests/MockDriveInfoFactoryTests.cs b/TestHelpers.Tests/MockDriveInfoFactoryTests.cs index b8924821a..2b10ec883 100644 --- a/TestHelpers.Tests/MockDriveInfoFactoryTests.cs +++ b/TestHelpers.Tests/MockDriveInfoFactoryTests.cs @@ -7,7 +7,7 @@ namespace System.IO.Abstractions.TestingHelpers.Tests using XFS = MockUnixSupport; [TestFixture] - [SkipOnUnix(SkipReason.NoDrivesOnUnix)] + [WindowsOnly(WindowsSpecifics.Drives)] public class MockDriveInfoFactoryTests { [Test] diff --git a/TestHelpers.Tests/MockDriveInfoTests.cs b/TestHelpers.Tests/MockDriveInfoTests.cs index 2b823710b..8b33fd16f 100644 --- a/TestHelpers.Tests/MockDriveInfoTests.cs +++ b/TestHelpers.Tests/MockDriveInfoTests.cs @@ -5,7 +5,7 @@ namespace System.IO.Abstractions.TestingHelpers.Tests using XFS = MockUnixSupport; [TestFixture] - [SkipOnUnix(SkipReason.NoDrivesOnUnix)] + [WindowsOnly(WindowsSpecifics.Drives)] public class MockDriveInfoTests { [TestCase(@"c:")] diff --git a/TestHelpers.Tests/MockFileAppendAllLinesTests.cs b/TestHelpers.Tests/MockFileAppendAllLinesTests.cs index d69a9b51b..75e94ea24 100644 --- a/TestHelpers.Tests/MockFileAppendAllLinesTests.cs +++ b/TestHelpers.Tests/MockFileAppendAllLinesTests.cs @@ -78,7 +78,7 @@ public void MockFile_AppendAllLines_ShouldThrowArgumentExceptionIfPathContainsOn [TestCase("<")] [TestCase(">")] [TestCase("|")] - [SkipOnUnix(SkipReason.WindowsOnlyPathRestrictions)] + [WindowsOnly(WindowsSpecifics.StrictPathRules)] public void MockFile_AppendAllLines_ShouldThrowArgumentExceptionIfPathContainsInvalidChar(string path) { // Arrange diff --git a/TestHelpers.Tests/MockFileCreateTests.cs b/TestHelpers.Tests/MockFileCreateTests.cs index b6ac82f63..0f221d152 100644 --- a/TestHelpers.Tests/MockFileCreateTests.cs +++ b/TestHelpers.Tests/MockFileCreateTests.cs @@ -110,7 +110,7 @@ public void Mockfile_Create_ShouldThrowArgumentExceptionIfPathIsZeroLength() [TestCase("<")] [TestCase(">")] [TestCase("|")] - [SkipOnUnix(SkipReason.WindowsOnlyPathRestrictions)] + [WindowsOnly(WindowsSpecifics.StrictPathRules)] public void MockFile_Create_ShouldThrowArgumentNullExceptionIfPathIsNull1(string path) { // Arrange diff --git a/TestHelpers.Tests/MockFileGetAccessControlTests.cs b/TestHelpers.Tests/MockFileGetAccessControlTests.cs index a4f28b258..ba183e26f 100644 --- a/TestHelpers.Tests/MockFileGetAccessControlTests.cs +++ b/TestHelpers.Tests/MockFileGetAccessControlTests.cs @@ -10,7 +10,7 @@ namespace System.IO.Abstractions.TestingHelpers.Tests using XFS = MockUnixSupport; [TestFixture] - [SkipOnUnix(SkipReason.NoACLsOnUnix)] + [WindowsOnly(WindowsSpecifics.AccessControlLists)] public class MockFileGetAccessControlTests { [TestCase(" ")] diff --git a/TestHelpers.Tests/MockFileSetAccessControlTests.cs b/TestHelpers.Tests/MockFileSetAccessControlTests.cs index 063d904d6..8390b14f1 100644 --- a/TestHelpers.Tests/MockFileSetAccessControlTests.cs +++ b/TestHelpers.Tests/MockFileSetAccessControlTests.cs @@ -10,7 +10,7 @@ namespace System.IO.Abstractions.TestingHelpers.Tests using XFS = MockUnixSupport; [TestFixture] - [SkipOnUnix(SkipReason.NoACLsOnUnix)] + [WindowsOnly(WindowsSpecifics.AccessControlLists)] public class MockFileSetAccessControlTests { [TestCase(" ")] diff --git a/TestHelpers.Tests/MockFileTests.cs b/TestHelpers.Tests/MockFileTests.cs index bb62844ab..86174dcaf 100644 --- a/TestHelpers.Tests/MockFileTests.cs +++ b/TestHelpers.Tests/MockFileTests.cs @@ -244,7 +244,7 @@ public void MockFile_GetAttributeOfExistingFile_ShouldReturnCorrectValue() } [Test] - [SkipOnUnix(SkipReason.NoUNCPathsOnUnix)] + [WindowsOnly(WindowsSpecifics.UNCPaths)] public void MockFile_GetAttributeOfExistingUncDirectory_ShouldReturnCorrectValue() { var filedata = new MockFileData("test"); diff --git a/TestHelpers.Tests/MockFileWriteAllBytesTests.cs b/TestHelpers.Tests/MockFileWriteAllBytesTests.cs index 4cc6094eb..0b4bdf66b 100644 --- a/TestHelpers.Tests/MockFileWriteAllBytesTests.cs +++ b/TestHelpers.Tests/MockFileWriteAllBytesTests.cs @@ -47,7 +47,7 @@ public void MockFile_WriteAllBytes_ShouldThrowAnUnauthorizedAccessExceptionIfFil } [Test] - [SkipOnUnix(SkipReason.WindowsOnlyPathRestrictions)] + [WindowsOnly(WindowsSpecifics.StrictPathRules)] public void MockFile_WriteAllBytes_ShouldThrowAnArgumentExceptionIfContainsIllegalCharacters() { var fileSystem = new MockFileSystem(); diff --git a/TestHelpers.Tests/MockFileWriteAllLinesTests.cs b/TestHelpers.Tests/MockFileWriteAllLinesTests.cs index 835be0ccd..9d49edcfb 100644 --- a/TestHelpers.Tests/MockFileWriteAllLinesTests.cs +++ b/TestHelpers.Tests/MockFileWriteAllLinesTests.cs @@ -241,7 +241,7 @@ public void MockFile_WriteAllLinesGeneric_ShouldThrowAnArgumentNullExceptionIfEn } [TestCaseSource(typeof(TestDataForWriteAllLines), "ForIllegalPath")] - [SkipOnUnix(SkipReason.WindowsOnlyPathRestrictions)] + [WindowsOnly(WindowsSpecifics.StrictPathRules)] public void MockFile_WriteAllLinesGeneric_ShouldThrowAnArgumentExceptionIfPathContainsIllegalCharacters(TestDelegate action) { // Arrange diff --git a/TestHelpers.Tests/SkipReason.cs b/TestHelpers.Tests/SkipReason.cs deleted file mode 100644 index 1339447ad..000000000 --- a/TestHelpers.Tests/SkipReason.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace System.IO.Abstractions.TestingHelpers.Tests -{ - internal static class SkipReason - { - public const string NoDrivesOnUnix = "Unix does not have the concept of Drives"; - public const string NoACLsOnUnix = "Unix does not support ACLs"; - public const string NoUNCPathsOnUnix = "Unix does not have the concept of UNC paths"; - public const string WindowsOnlyPathRestrictions = "Unix does not have this path restriction"; - } -} diff --git a/TestHelpers.Tests/SkipOnUnixAttribute.cs b/TestHelpers.Tests/WindowsOnlyAttribute.cs similarity index 81% rename from TestHelpers.Tests/SkipOnUnixAttribute.cs rename to TestHelpers.Tests/WindowsOnlyAttribute.cs index 51eb9e2c3..b0b63d79d 100644 --- a/TestHelpers.Tests/SkipOnUnixAttribute.cs +++ b/TestHelpers.Tests/WindowsOnlyAttribute.cs @@ -5,11 +5,11 @@ namespace System.IO.Abstractions.TestingHelpers.Tests { - internal sealed class SkipOnUnixAttribute : Attribute, ITestAction + internal sealed class WindowsOnlyAttribute : Attribute, ITestAction { private readonly string reason; - public SkipOnUnixAttribute(string reason) + public WindowsOnlyAttribute(string reason) { this.reason = reason; } 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"; + } +} From b6a744cbef28c9f03255eae88337291f2e7b5393 Mon Sep 17 00:00:00 2001 From: Florian Greinacher Date: Tue, 10 Jul 2018 21:21:17 +0200 Subject: [PATCH 5/8] Improve windows-specific tests --- TestHelpers.Tests/MockDirectoryTests.cs | 33 ++++++++++++------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/TestHelpers.Tests/MockDirectoryTests.cs b/TestHelpers.Tests/MockDirectoryTests.cs index f7a741f29..bacf3f528 100644 --- a/TestHelpers.Tests/MockDirectoryTests.cs +++ b/TestHelpers.Tests/MockDirectoryTests.cs @@ -746,28 +746,27 @@ public void MockDirectory_GetFiles_ShouldThrowAnArgumentException_IfSearchPatter Assert.Throws(action); } - public static IEnumerable GetSearchPatternForTwoDotsExceptions_WindowsOnly() - { - yield return @"..\"; - yield return @"aaa\vv..\"; - yield return @"a..\b"; - } - - [TestCaseSource(typeof(MockDirectoryTests), "GetSearchPatternForTwoDotsExceptions_WindowsOnly")] + [TestCase(@"..\")] + [TestCase(@"aaa\vv..\")] + [TestCase(@"a..\b")] [WindowsOnly(WindowsSpecifics.StrictPathRules)] - public void MockDirectory_GetFiles_ShouldThrowAnArgumentException_IfSearchPatternContainsTwoDotsFollowedByOneDirectoryPathSep_WindowsOnly(string searchPattern) + public void MockDirectory_GetFiles_ShouldThrowAnArgumentException_IfSearchPatternContainsTwoDotsFollowedByOneBackslash(string searchPattern) { - MockDirectory_GetFiles_ShouldThrowAnArgumentException_IfSearchPatternContainsTwoDotsFollowedByOneDirectoryPathSep(searchPattern); - } + // Arrange + var directoryPath = XFS.Path(@"c:\Foo"); + var fileSystem = new MockFileSystem(); + fileSystem.AddDirectory(directoryPath); - public static IEnumerable GetSearchPatternForTwoDotsExceptions() - { - yield return @"a../b"; - yield return @"../"; + // 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"); From 281ce443f5b070262fed6bc713a4e70d445f43f3 Mon Sep 17 00:00:00 2001 From: Florian Greinacher Date: Wed, 11 Jul 2018 21:42:18 +0200 Subject: [PATCH 6/8] Improve tests --- TestHelpers.Tests/MockDirectoryInfoTests.cs | 42 +++++++++++---------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/TestHelpers.Tests/MockDirectoryInfoTests.cs b/TestHelpers.Tests/MockDirectoryInfoTests.cs index dfd24d692..f560205c9 100644 --- a/TestHelpers.Tests/MockDirectoryInfoTests.cs +++ b/TestHelpers.Tests/MockDirectoryInfoTests.cs @@ -195,40 +195,42 @@ public void MockDirectoryInfo_EnumerateDirectories_ShouldReturnAllDirectories() Assert.AreEqual(new[] { "b", "c" }, directories); } - public static IEnumerable MockDirectoryInfo_FullName_Data - { - 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") }; - } - } - public static IEnumerable MockDirectoryInfo_FullName_Data_WindowsOnly { get { - 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") }; + yield return new object[] { XFS.Path(@"\\unc\folder"), XFS.Path(@) }; + yield return new object[] { XFS.Path(), XFS.Path() }; } } - [TestCaseSource("MockDirectoryInfo_FullName_Data_WindowsOnly")] + [TestCase(@"\\unc\folder", @"\\unc\folder")] + [TestCase(@"\\unc/folder\\foo", @"\\unc\folder\foo")] [WindowsOnly(WindowsSpecifics.UNCPaths)] - public void MockDirectoryInfo_FullName_ShouldReturnNormalizedPath_WindowsOnly(string directoryPath, string expectedFullName) + public void MockDirectoryInfo_FullName_ShouldReturnNormalizedUNCPath(string directoryPath, string expectedFullName) { - MockDirectoryInfo_FullName_ShouldReturnNormalizedPath(directoryPath, expectedFullName); + // 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 From 46ac386cc610a3dde6de33eba4a393a6e27ffc0f Mon Sep 17 00:00:00 2001 From: Florian Greinacher Date: Wed, 11 Jul 2018 21:42:18 +0200 Subject: [PATCH 7/8] Improve tests --- TestHelpers.Tests/MockDirectoryInfoTests.cs | 42 +++++++++++---------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/TestHelpers.Tests/MockDirectoryInfoTests.cs b/TestHelpers.Tests/MockDirectoryInfoTests.cs index dfd24d692..f560205c9 100644 --- a/TestHelpers.Tests/MockDirectoryInfoTests.cs +++ b/TestHelpers.Tests/MockDirectoryInfoTests.cs @@ -195,40 +195,42 @@ public void MockDirectoryInfo_EnumerateDirectories_ShouldReturnAllDirectories() Assert.AreEqual(new[] { "b", "c" }, directories); } - public static IEnumerable MockDirectoryInfo_FullName_Data - { - 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") }; - } - } - public static IEnumerable MockDirectoryInfo_FullName_Data_WindowsOnly { get { - 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") }; + yield return new object[] { XFS.Path(@"\\unc\folder"), XFS.Path(@) }; + yield return new object[] { XFS.Path(), XFS.Path() }; } } - [TestCaseSource("MockDirectoryInfo_FullName_Data_WindowsOnly")] + [TestCase(@"\\unc\folder", @"\\unc\folder")] + [TestCase(@"\\unc/folder\\foo", @"\\unc\folder\foo")] [WindowsOnly(WindowsSpecifics.UNCPaths)] - public void MockDirectoryInfo_FullName_ShouldReturnNormalizedPath_WindowsOnly(string directoryPath, string expectedFullName) + public void MockDirectoryInfo_FullName_ShouldReturnNormalizedUNCPath(string directoryPath, string expectedFullName) { - MockDirectoryInfo_FullName_ShouldReturnNormalizedPath(directoryPath, expectedFullName); + // 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 From 1b7b9e86e28f9bd42db3dc6056bb21f7a33b06f3 Mon Sep 17 00:00:00 2001 From: Florian Greinacher Date: Wed, 11 Jul 2018 22:24:46 +0200 Subject: [PATCH 8/8] Fix merge error --- TestHelpers.Tests/MockDirectoryInfoTests.cs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/TestHelpers.Tests/MockDirectoryInfoTests.cs b/TestHelpers.Tests/MockDirectoryInfoTests.cs index f560205c9..194dde31b 100644 --- a/TestHelpers.Tests/MockDirectoryInfoTests.cs +++ b/TestHelpers.Tests/MockDirectoryInfoTests.cs @@ -195,15 +195,6 @@ public void MockDirectoryInfo_EnumerateDirectories_ShouldReturnAllDirectories() Assert.AreEqual(new[] { "b", "c" }, directories); } - public static IEnumerable MockDirectoryInfo_FullName_Data_WindowsOnly - { - get - { - yield return new object[] { XFS.Path(@"\\unc\folder"), XFS.Path(@) }; - yield return new object[] { XFS.Path(), XFS.Path() }; - } - } - [TestCase(@"\\unc\folder", @"\\unc\folder")] [TestCase(@"\\unc/folder\\foo", @"\\unc\folder\foo")] [WindowsOnly(WindowsSpecifics.UNCPaths)]