From b30e223dc0028efe463c0fac310fd180aafe3758 Mon Sep 17 00:00:00 2001 From: Florian Greinacher Date: Wed, 4 Jul 2018 22:38:46 +0200 Subject: [PATCH] Fix/disable tests that fail on Unix --- .../MockDirectoryGetAccessControlTests.cs | 15 ++++ TestHelpers.Tests/MockDirectoryInfoTests.cs | 11 ++- .../MockDirectorySetAccessControlTests.cs | 15 ++++ TestHelpers.Tests/MockDirectoryTests.cs | 79 +++++++++++++------ .../MockDriveInfoFactoryTests.cs | 15 ++++ TestHelpers.Tests/MockDriveInfoTests.cs | 15 ++++ .../MockFileAppendAllLinesTests.cs | 5 ++ .../MockFileAppendAllTextTests.cs | 15 +--- TestHelpers.Tests/MockFileCreateTests.cs | 11 ++- .../MockFileGetAccessControlTests.cs | 15 ++++ TestHelpers.Tests/MockFileInfoTests.cs | 2 +- TestHelpers.Tests/MockFileOpenTests.cs | 6 +- .../MockFileSetAccessControlTests.cs | 15 ++++ TestHelpers.Tests/MockFileSystemTests.cs | 58 +++++++------- TestHelpers.Tests/MockFileTests.cs | 9 ++- .../MockFileWriteAllBytesTests.cs | 2 +- .../MockFileWriteAllLinesTests.cs | 9 ++- .../MockFileWriteAllTextTests.cs | 8 +- TestingHelpers/MockDirectory.cs | 7 ++ TestingHelpers/MockDirectoryInfo.cs | 2 +- 20 files changed, 229 insertions(+), 85 deletions(-) diff --git a/TestHelpers.Tests/MockDirectoryGetAccessControlTests.cs b/TestHelpers.Tests/MockDirectoryGetAccessControlTests.cs index aae22c2e9..aac126984 100644 --- a/TestHelpers.Tests/MockDirectoryGetAccessControlTests.cs +++ b/TestHelpers.Tests/MockDirectoryGetAccessControlTests.cs @@ -16,6 +16,11 @@ public class MockDirectoryGetAccessControlTests [TestCase(" ")] public void MockDirectory_GetAccessControl_ShouldThrowArgumentExceptionIfPathContainsOnlyWhitespaces(string path) { + if (MockUnixSupport.IsUnixPlatform()) + { + Assert.Inconclusive("Unix does not support ACLs."); + } + // Arrange var fileSystem = new MockFileSystem(); @@ -30,6 +35,11 @@ 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"); @@ -44,6 +54,11 @@ 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/MockDirectoryInfoTests.cs b/TestHelpers.Tests/MockDirectoryInfoTests.cs index 948422c71..73b5111f0 100644 --- a/TestHelpers.Tests/MockDirectoryInfoTests.cs +++ b/TestHelpers.Tests/MockDirectoryInfoTests.cs @@ -202,8 +202,11 @@ 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") }; - 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") }; + 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") }; + } } } @@ -263,8 +266,8 @@ public void MockDirectoryInfo_Constructor_ShouldThrowArgumentException_IfArgumen // Assert var exception = Assert.Throws(action); Assert.That(exception.Message, Does.StartWith("The path is not of a legal form.")); - } - + } + [Test] public void MockDirectoryInfo_ToString_ShouldReturnDirectoryName() { diff --git a/TestHelpers.Tests/MockDirectorySetAccessControlTests.cs b/TestHelpers.Tests/MockDirectorySetAccessControlTests.cs index 49255eeed..92b69a96d 100644 --- a/TestHelpers.Tests/MockDirectorySetAccessControlTests.cs +++ b/TestHelpers.Tests/MockDirectorySetAccessControlTests.cs @@ -16,6 +16,11 @@ public class MockDirectorySetAccessControlTests [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(); @@ -31,6 +36,11 @@ 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\"); @@ -46,6 +56,11 @@ 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 66b2e7808..38edcb67c 100644 --- a/TestHelpers.Tests/MockDirectoryTests.cs +++ b/TestHelpers.Tests/MockDirectoryTests.cs @@ -542,6 +542,11 @@ public void MockDirectory_CreMockDirectory_CreateDirectory_ShouldReturnDirectory [Test] public void MockDirectory_CreateDirectory_ShouldWorkWithUNCPath() { + if (MockUnixSupport.IsUnixPlatform()) + { + Assert.Inconclusive("Unix does not support ACLs."); + } + // Arrange var fileSystem = new MockFileSystem(); @@ -555,6 +560,11 @@ public void MockDirectory_CreateDirectory_ShouldWorkWithUNCPath() [Test] public void MockDirectory_CreateDirectory_ShouldFailIfTryingToCreateUNCPathOnlyServer() { + if (MockUnixSupport.IsUnixPlatform()) + { + Assert.Inconclusive("Unix does not have the concept of UNC paths."); + } + // Arrange var fileSystem = new MockFileSystem(); @@ -569,6 +579,11 @@ public void MockDirectory_CreateDirectory_ShouldFailIfTryingToCreateUNCPathOnlyS [Test] public void MockDirectory_CreateDirectory_ShouldSucceedIfTryingToCreateUNCPathShare() { + if (MockUnixSupport.IsUnixPlatform()) + { + Assert.Inconclusive("Unix does not have the concept of UNC paths."); + } + // Arrange var fileSystem = new MockFileSystem(); @@ -745,11 +760,16 @@ public void MockDirectory_GetFiles_ShouldThrowAnArgumentException_IfSearchPatter public static IEnumerable GetSearchPatternForTwoDotsExceptions() { - yield return @"a..\b"; yield return @"a../b"; yield return @"../"; - yield return @"..\"; - yield return @"aaa\vv..\"; + + if (!MockUnixSupport.IsUnixPlatform()) + { + // These are no problem on Unix platforms + yield return @"..\"; + yield return @"aaa\vv..\"; + yield return @"a..\b"; + } } [TestCaseSource(typeof(MockDirectoryTests), "GetSearchPatternForTwoDotsExceptions")] @@ -778,7 +798,7 @@ public void MockDirectory_GetFiles_ShouldFindFilesContainingTwoOrMoreDots() }); // Act - var actualResult = fileSystem.Directory.GetFiles(XFS.Path(@"c:\"), @"foo..r\*"); + var actualResult = fileSystem.Directory.GetFiles(XFS.Path(@"c:\"), XFS.Path(@"foo..r\*")); // Assert Assert.That(actualResult, Is.EquivalentTo(new [] { testPath })); @@ -790,6 +810,11 @@ public void MockDirectory_GetFiles_ShouldFindFilesContainingTwoOrMoreDots() [TestCase("aa\t")] 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(); @@ -913,17 +938,17 @@ public void MockDirectory_GetDirectories_RelativeDirectory_WithoutChildren_Shoul public void MockDirectory_GetDirectories_RelativeDirectory_WithChildren_ShouldReturnChildDirectories(string relativeDirPath) { // Arrange - const string currentDirectory = @"T:\foo"; + var currentDirectory = XFS.Path(@"T:\foo"); var fileSystem = new MockFileSystem(null, currentDirectory: currentDirectory); - fileSystem.Directory.CreateDirectory(relativeDirPath); - fileSystem.Directory.CreateDirectory(relativeDirPath + @"\child"); + fileSystem.Directory.CreateDirectory(XFS.Path(relativeDirPath)); + fileSystem.Directory.CreateDirectory(XFS.Path(relativeDirPath + @"\child")); // Act - var actualResult = fileSystem.Directory.GetDirectories(relativeDirPath); + var actualResult = fileSystem.Directory.GetDirectories(XFS.Path(relativeDirPath)); // Assert CollectionAssert.AreEqual( - new[] { currentDirectory + @"\" + relativeDirPath + @"\child\" }, + new[] { XFS.Path(currentDirectory + @"\" + relativeDirPath + @"\child\") }, actualResult ); } @@ -1067,13 +1092,13 @@ public void MockDirectory_EnumerateDirectories_ShouldThrowWhenPathIsNotMocked() public static IEnumerable GetPathsForMoving() { - yield return new object[] { @"a:\folder1\", @"A:\folder3\", "file.txt", @"folder2\file2.txt" }; - yield return new object[] { @"A:\folder1\", @"A:\folder3\", "file.txt", @"folder2\file2.txt" }; - yield return new object[] { @"a:\folder1\", @"a:\folder3\", "file.txt", @"folder2\file2.txt" }; - yield return new object[] { @"A:\folder1\", @"a:\folder3\", "file.txt", @"folder2\file2.txt" }; - yield return new object[] { @"A:\folder1\", @"a:\folder3\", "file.txt", @"Folder2\file2.txt" }; - yield return new object[] { @"A:\folder1\", @"a:\folder3\", "file.txt", @"Folder2\fiLe2.txt" }; - yield return new object[] { @"A:\folder1\", @"a:\folder3\", "folder444\\file.txt", @"Folder2\fiLe2.txt" }; + yield return new object[] { XFS.Path(@"a:\folder1\"), XFS.Path(@"A:\folder3\"), XFS.Path("file.txt"), XFS.Path(@"folder2\file2.txt") }; + yield return new object[] { XFS.Path(@"A:\folder1\"), XFS.Path(@"A:\folder3\"), XFS.Path("file.txt"), XFS.Path(@"folder2\file2.txt") }; + yield return new object[] { XFS.Path(@"a:\folder1\"), XFS.Path(@"a:\folder3\"), XFS.Path("file.txt"), XFS.Path(@"folder2\file2.txt") }; + yield return new object[] { XFS.Path(@"A:\folder1\"), XFS.Path(@"a:\folder3\"), XFS.Path("file.txt"), XFS.Path(@"folder2\file2.txt") }; + yield return new object[] { XFS.Path(@"A:\folder1\"), XFS.Path(@"a:\folder3\"), XFS.Path("file.txt"), XFS.Path(@"Folder2\file2.txt") }; + yield return new object[] { XFS.Path(@"A:\folder1\"), XFS.Path(@"a:\folder3\"), XFS.Path("file.txt"), XFS.Path(@"Folder2\fiLe2.txt") }; + yield return new object[] { XFS.Path(@"A:\folder1\"), XFS.Path(@"a:\folder3\"), XFS.Path("folder444\\file.txt"), XFS.Path(@"Folder2\fiLe2.txt") }; } [Test] @@ -1081,14 +1106,14 @@ public void Move_DirectoryExistsWithDifferentCase_DirectorySuccessfullyMoved() { // Arrange var fileSystem = new MockFileSystem(); - fileSystem.AddDirectory(@"C:\OLD_LOCATION\Data"); - fileSystem.AddFile(@"C:\old_location\Data\someFile.txt", new MockFileData("abc")); + fileSystem.AddDirectory(XFS.Path(@"C:\OLD_LOCATION\Data")); + fileSystem.AddFile(XFS.Path(@"C:\old_location\Data\someFile.txt"), new MockFileData("abc")); // Act - fileSystem.Directory.Move(@"C:\old_location", @"C:\NewLocation\"); + fileSystem.Directory.Move(XFS.Path(@"C:\old_location"), XFS.Path(@"C:\NewLocation\")); // Assert - Assert.IsTrue(fileSystem.File.Exists(@"C:\NewLocation\Data\someFile.txt")); + Assert.IsTrue(fileSystem.File.Exists(XFS.Path(@"C:\NewLocation\Data\someFile.txt"))); } [TestCaseSource("GetPathsForMoving")] @@ -1114,8 +1139,8 @@ public void MockDirectory_Move_ShouldMove(string sourceDirName, string destDirNa public void MockDirectory_Move_ShouldMoveDirectoryAtrributes() { // Arrange - const string sourceDirName = @"a:\folder1\"; - const string destDirName = @"a:\folder2\"; + var sourceDirName = XFS.Path(@"a:\folder1\"); + var destDirName = XFS.Path(@"a:\folder2\"); const string filePathOne = "file1.txt"; const string filePathTwo = "file2.txt"; var fileSystem = new MockFileSystem(new Dictionary @@ -1282,6 +1307,11 @@ public void MockDirectory_Move_ShouldThrowAnIOExceptionIfBothPathAreIdentical() [Test] 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"); @@ -1391,6 +1421,11 @@ public void MockDirectory_GetAccessControl_ShouldThrowExceptionOnDirectoryNotFou [Test] 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 33bcc507d..93ecfbf8a 100644 --- a/TestHelpers.Tests/MockDriveInfoFactoryTests.cs +++ b/TestHelpers.Tests/MockDriveInfoFactoryTests.cs @@ -11,6 +11,11 @@ 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")); @@ -30,6 +35,11 @@ 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")); @@ -51,6 +61,11 @@ 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")); diff --git a/TestHelpers.Tests/MockDriveInfoTests.cs b/TestHelpers.Tests/MockDriveInfoTests.cs index aa655a642..71aca296c 100644 --- a/TestHelpers.Tests/MockDriveInfoTests.cs +++ b/TestHelpers.Tests/MockDriveInfoTests.cs @@ -11,6 +11,11 @@ public class MockDriveInfoTests [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")); @@ -46,6 +51,11 @@ 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(); @@ -59,6 +69,11 @@ 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 e99dcb8f6..2e5720f8c 100644 --- a/TestHelpers.Tests/MockFileAppendAllLinesTests.cs +++ b/TestHelpers.Tests/MockFileAppendAllLinesTests.cs @@ -80,6 +80,11 @@ public void MockFile_AppendAllLines_ShouldThrowArgumentExceptionIfPathContainsOn [TestCase("|")] 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/MockFileAppendAllTextTests.cs b/TestHelpers.Tests/MockFileAppendAllTextTests.cs index e57bca080..8cc5c85f2 100644 --- a/TestHelpers.Tests/MockFileAppendAllTextTests.cs +++ b/TestHelpers.Tests/MockFileAppendAllTextTests.cs @@ -78,8 +78,8 @@ public void MockFile_AppendAllText_ShouldCreateIfNotExistWithBom() { // Arrange var fileSystem = new MockFileSystem(new Dictionary()); - const string path = @"c:\something\demo3.txt"; - fileSystem.AddDirectory(@"c:\something\"); + var path = XFS.Path(@"c:\something\demo3.txt"); + fileSystem.AddDirectory(XFS.Path(@"c:\something\")); // Act fileSystem.File.AppendAllText(path, "AA", Encoding.UTF32); @@ -139,17 +139,6 @@ public void MockFile_AppendAllText_ShouldPersistNewTextWithCustomEncoding() 0, 32, 0, 116, 0, 101, 0, 120, 0, 116 }; - if (XFS.IsUnixPlatform()) - { - // Remove EOF on mono - expected = new byte[] - { - 68, 101, 109, 111, 32, 116, 101, 120, 116, 32, 99, 111, 110, 116, - 101, 110, 0, 43, 0, 32, 0, 115, 0, 111, 0, 109, 0, 101, - 0, 32, 0, 116, 0, 101, 0, 120, 0, 116 - }; - } - CollectionAssert.AreEqual( expected, file.ReadAllBytes(path)); diff --git a/TestHelpers.Tests/MockFileCreateTests.cs b/TestHelpers.Tests/MockFileCreateTests.cs index 2c3c454e3..7e285ead1 100644 --- a/TestHelpers.Tests/MockFileCreateTests.cs +++ b/TestHelpers.Tests/MockFileCreateTests.cs @@ -18,7 +18,7 @@ public void Mockfile_Create_ShouldCreateNewStream() { string fullPath = XFS.Path(@"c:\something\demo.txt"); var fileSystem = new MockFileSystem(); - fileSystem.AddDirectory(@"c:\something"); + fileSystem.AddDirectory(XFS.Path(@"c:\something")); var sut = new MockFile(fileSystem); @@ -34,7 +34,7 @@ public void Mockfile_Create_CanWriteToNewStream() { string fullPath = XFS.Path(@"c:\something\demo.txt"); var fileSystem = new MockFileSystem(); - fileSystem.AddDirectory(@"c:\something"); + fileSystem.AddDirectory(XFS.Path(@"c:\something")); var data = new UTF8Encoding(false).GetBytes("Test string"); var sut = new MockFile(fileSystem); @@ -54,7 +54,7 @@ public void Mockfile_Create_OverwritesExistingFile() { string path = XFS.Path(@"c:\some\file.txt"); var fileSystem = new MockFileSystem(); - fileSystem.AddDirectory(@"c:\some"); + fileSystem.AddDirectory(XFS.Path(@"c:\some")); var mockFile = new MockFile(fileSystem); @@ -112,6 +112,11 @@ public void Mockfile_Create_ShouldThrowArgumentExceptionIfPathIsZeroLength() [TestCase("|")] 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/MockFileGetAccessControlTests.cs b/TestHelpers.Tests/MockFileGetAccessControlTests.cs index 876bd259c..0ebfe8b7b 100644 --- a/TestHelpers.Tests/MockFileGetAccessControlTests.cs +++ b/TestHelpers.Tests/MockFileGetAccessControlTests.cs @@ -16,6 +16,11 @@ public class MockFileGetAccessControlTests [TestCase(" ")] public void MockFile_GetAccessControl_ShouldThrowArgumentExceptionIfPathContainsOnlyWhitespaces(string path) { + if (MockUnixSupport.IsUnixPlatform()) + { + Assert.Inconclusive("Unix does not support ACLs."); + } + // Arrange var fileSystem = new MockFileSystem(); @@ -30,6 +35,11 @@ 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"); @@ -45,6 +55,11 @@ 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/MockFileInfoTests.cs b/TestHelpers.Tests/MockFileInfoTests.cs index 7cf136bb1..10e9b600f 100644 --- a/TestHelpers.Tests/MockFileInfoTests.cs +++ b/TestHelpers.Tests/MockFileInfoTests.cs @@ -217,7 +217,7 @@ public void MockFileInfo_AppendText_ShouldAddTextToFileInMemoryFileSystem() newcontents = newfile.ReadToEnd(); // Assert - Assert.AreEqual("Demo text contentThis should be at the end\r\n", newcontents); + Assert.AreEqual($"Demo text contentThis should be at the end{Environment.NewLine}", newcontents); } [Test] diff --git a/TestHelpers.Tests/MockFileOpenTests.cs b/TestHelpers.Tests/MockFileOpenTests.cs index 3b76c6fbf..5e7a065a1 100644 --- a/TestHelpers.Tests/MockFileOpenTests.cs +++ b/TestHelpers.Tests/MockFileOpenTests.cs @@ -42,7 +42,7 @@ public void MockFile_Open_CreatesNewFileFileOnCreate() { string filepath = XFS.Path(@"c:\something\doesnt\exist.txt"); var filesystem = new MockFileSystem(new Dictionary()); - filesystem.AddDirectory(@"c:\something\doesnt"); + filesystem.AddDirectory(XFS.Path(@"c:\something\doesnt")); var stream = filesystem.File.Open(filepath, FileMode.Create); @@ -56,7 +56,7 @@ public void MockFile_Open_CreatesNewFileFileOnCreateNew() { string filepath = XFS.Path(@"c:\something\doesnt\exist.txt"); var filesystem = new MockFileSystem(new Dictionary()); - filesystem.AddDirectory(@"c:\something\doesnt"); + filesystem.AddDirectory(XFS.Path(@"c:\something\doesnt")); var stream = filesystem.File.Open(filepath, FileMode.CreateNew); @@ -155,7 +155,7 @@ public void MockFile_Open_CreatesNewFileOnOpenOrCreate() { string filepath = XFS.Path(@"c:\something\doesnt\exist.txt"); var filesystem = new MockFileSystem(new Dictionary()); - filesystem.AddDirectory(@"c:\something\doesnt"); + filesystem.AddDirectory(XFS.Path(@"c:\something\doesnt")); var stream = filesystem.File.Open(filepath, FileMode.OpenOrCreate); diff --git a/TestHelpers.Tests/MockFileSetAccessControlTests.cs b/TestHelpers.Tests/MockFileSetAccessControlTests.cs index 19a99c8b4..aca9fab1c 100644 --- a/TestHelpers.Tests/MockFileSetAccessControlTests.cs +++ b/TestHelpers.Tests/MockFileSetAccessControlTests.cs @@ -16,6 +16,11 @@ public class MockFileSetAccessControlTests [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(); @@ -31,6 +36,11 @@ 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"); @@ -47,6 +57,11 @@ 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/MockFileSystemTests.cs b/TestHelpers.Tests/MockFileSystemTests.cs index ba4b5252f..97998935a 100644 --- a/TestHelpers.Tests/MockFileSystemTests.cs +++ b/TestHelpers.Tests/MockFileSystemTests.cs @@ -153,16 +153,16 @@ public void MockFileSystem_AddFile_ShouldMatchCapitalization_PerfectMatch() fileSystem.AddDirectory(MockUnixSupport.Path(@"C:\LOUD")); // Act - fileSystem.AddFile(@"C:\test\file.txt", "foo"); - fileSystem.AddFile(@"C:\LOUD\file.txt", "foo"); - fileSystem.AddDirectory(@"C:\test\SUBDirectory"); - fileSystem.AddDirectory(@"C:\LOUD\SUBDirectory"); + fileSystem.AddFile(MockUnixSupport.Path(@"C:\test\file.txt"), "foo"); + fileSystem.AddFile(MockUnixSupport.Path(@"C:\LOUD\file.txt"), "foo"); + fileSystem.AddDirectory(MockUnixSupport.Path(@"C:\test\SUBDirectory")); + fileSystem.AddDirectory(MockUnixSupport.Path(@"C:\LOUD\SUBDirectory")); // Assert - Assert.Contains(@"C:\test\file.txt", fileSystem.AllFiles.ToList()); - Assert.Contains(@"C:\LOUD\file.txt", fileSystem.AllFiles.ToList()); - Assert.Contains(@"C:\test\SUBDirectory\", fileSystem.AllDirectories.ToList()); - Assert.Contains(@"C:\LOUD\SUBDirectory\", fileSystem.AllDirectories.ToList()); + Assert.Contains(MockUnixSupport.Path(@"C:\test\file.txt"), fileSystem.AllFiles.ToList()); + Assert.Contains(MockUnixSupport.Path(@"C:\LOUD\file.txt"), fileSystem.AllFiles.ToList()); + Assert.Contains(MockUnixSupport.Path(@"C:\test\SUBDirectory\"), fileSystem.AllDirectories.ToList()); + Assert.Contains(MockUnixSupport.Path(@"C:\LOUD\SUBDirectory\"), fileSystem.AllDirectories.ToList()); } [Test] @@ -174,16 +174,16 @@ public void MockFileSystem_AddFile_ShouldMatchCapitalization_PartialMatch() fileSystem.AddDirectory(MockUnixSupport.Path(@"C:\LOUD\SUBLOUD")); // Act - fileSystem.AddFile(@"C:\test\SUBTEST\file.txt", "foo"); - fileSystem.AddFile(@"C:\LOUD\subloud\file.txt", "foo"); - fileSystem.AddDirectory(@"C:\test\SUBTEST\SUBDirectory"); - fileSystem.AddDirectory(@"C:\LOUD\subloud\SUBDirectory"); + fileSystem.AddFile(MockUnixSupport.Path(@"C:\test\SUBTEST\file.txt"), "foo"); + fileSystem.AddFile(MockUnixSupport.Path(@"C:\LOUD\subloud\file.txt"), "foo"); + fileSystem.AddDirectory(MockUnixSupport.Path(@"C:\test\SUBTEST\SUBDirectory")); + fileSystem.AddDirectory(MockUnixSupport.Path(@"C:\LOUD\subloud\SUBDirectory")); // Assert - Assert.Contains(@"C:\test\subtest\file.txt", fileSystem.AllFiles.ToList()); - Assert.Contains(@"C:\LOUD\SUBLOUD\file.txt", fileSystem.AllFiles.ToList()); - Assert.Contains(@"C:\test\subtest\SUBDirectory\", fileSystem.AllDirectories.ToList()); - Assert.Contains(@"C:\LOUD\SUBLOUD\SUBDirectory\", fileSystem.AllDirectories.ToList()); + Assert.Contains(MockUnixSupport.Path(@"C:\test\subtest\file.txt"), fileSystem.AllFiles.ToList()); + Assert.Contains(MockUnixSupport.Path(@"C:\LOUD\SUBLOUD\file.txt"), fileSystem.AllFiles.ToList()); + Assert.Contains(MockUnixSupport.Path(@"C:\test\subtest\SUBDirectory\"), fileSystem.AllDirectories.ToList()); + Assert.Contains(MockUnixSupport.Path(@"C:\LOUD\SUBLOUD\SUBDirectory\"), fileSystem.AllDirectories.ToList()); } [Test] @@ -195,16 +195,16 @@ public void MockFileSystem_AddFile_ShouldMatchCapitalization_PartialMatch_Furthe fileSystem.AddDirectory(MockUnixSupport.Path(@"C:\LOUD\SUBLOUD")); // Act - fileSystem.AddFile(@"C:\test\SUBTEST\new\file.txt", "foo"); - fileSystem.AddFile(@"C:\LOUD\subloud\new\file.txt", "foo"); - fileSystem.AddDirectory(@"C:\test\SUBTEST\new\SUBDirectory"); - fileSystem.AddDirectory(@"C:\LOUD\subloud\new\SUBDirectory"); + fileSystem.AddFile(MockUnixSupport.Path(@"C:\test\SUBTEST\new\file.txt"), "foo"); + fileSystem.AddFile(MockUnixSupport.Path(@"C:\LOUD\subloud\new\file.txt"), "foo"); + fileSystem.AddDirectory(MockUnixSupport.Path(@"C:\test\SUBTEST\new\SUBDirectory")); + fileSystem.AddDirectory(MockUnixSupport.Path(@"C:\LOUD\subloud\new\SUBDirectory")); // Assert - Assert.Contains(@"C:\test\subtest\new\file.txt", fileSystem.AllFiles.ToList()); - Assert.Contains(@"C:\LOUD\SUBLOUD\new\file.txt", fileSystem.AllFiles.ToList()); - Assert.Contains(@"C:\test\subtest\new\SUBDirectory\", fileSystem.AllDirectories.ToList()); - Assert.Contains(@"C:\LOUD\SUBLOUD\new\SUBDirectory\", fileSystem.AllDirectories.ToList()); + Assert.Contains(MockUnixSupport.Path(@"C:\test\subtest\new\file.txt"), fileSystem.AllFiles.ToList()); + Assert.Contains(MockUnixSupport.Path(@"C:\LOUD\SUBLOUD\new\file.txt"), fileSystem.AllFiles.ToList()); + Assert.Contains(MockUnixSupport.Path(@"C:\test\subtest\new\SUBDirectory\"), fileSystem.AllDirectories.ToList()); + Assert.Contains(MockUnixSupport.Path(@"C:\LOUD\SUBLOUD\new\SUBDirectory\"), fileSystem.AllDirectories.ToList()); } [Test] @@ -214,8 +214,8 @@ public void MockFileSystem_AddFileFromEmbeddedResource_ShouldAddTheFile() var fileSystem = new MockFileSystem(); // Act - fileSystem.AddFileFromEmbeddedResource(@"C:\TestFile.txt", Assembly.GetExecutingAssembly(), "System.IO.Abstractions.TestingHelpers.Tests.TestFiles.TestFile.txt"); - var result = fileSystem.GetFile(@"C:\TestFile.txt"); + fileSystem.AddFileFromEmbeddedResource(MockUnixSupport.Path(@"C:\TestFile.txt"), Assembly.GetExecutingAssembly(), "System.IO.Abstractions.TestingHelpers.Tests.TestFiles.TestFile.txt"); + var result = fileSystem.GetFile(MockUnixSupport.Path(@"C:\TestFile.txt")); // Assert Assert.AreEqual(new UTF8Encoding().GetBytes("This is a test file."), result.Contents); @@ -228,10 +228,10 @@ public void MockFileSystem_AddFilesFromEmbeddedResource_ShouldAddAllTheFiles() var fileSystem = new MockFileSystem(); //Act - fileSystem.AddFilesFromEmbeddedNamespace(@"C:\", Assembly.GetExecutingAssembly(), "System.IO.Abstractions.TestingHelpers.Tests.TestFiles"); + fileSystem.AddFilesFromEmbeddedNamespace(MockUnixSupport.Path(@"C:\"), Assembly.GetExecutingAssembly(), "System.IO.Abstractions.TestingHelpers.Tests.TestFiles"); - Assert.Contains(@"C:\TestFile.txt", fileSystem.AllFiles.ToList()); - Assert.Contains(@"C:\SecondTestFile.txt", fileSystem.AllFiles.ToList()); + Assert.Contains(MockUnixSupport.Path(@"C:\TestFile.txt"), fileSystem.AllFiles.ToList()); + Assert.Contains(MockUnixSupport.Path(@"C:\SecondTestFile.txt"), fileSystem.AllFiles.ToList()); } } } diff --git a/TestHelpers.Tests/MockFileTests.cs b/TestHelpers.Tests/MockFileTests.cs index 896c333fa..73deecffe 100644 --- a/TestHelpers.Tests/MockFileTests.cs +++ b/TestHelpers.Tests/MockFileTests.cs @@ -246,6 +246,11 @@ public void MockFile_GetAttributeOfExistingFile_ShouldReturnCorrectValue() [Test] 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 { @@ -435,7 +440,7 @@ public void MockFile_ReadAllBytes_ShouldReturnDataSavedByWriteAllBytes() string path = XFS.Path(@"c:\something\demo.txt"); var fileSystem = new MockFileSystem(); var fileContent = new byte[] { 1, 2, 3, 4 }; - fileSystem.AddDirectory(@"c:\something"); + fileSystem.AddDirectory(XFS.Path(@"c:\something")); // Act fileSystem.File.WriteAllBytes(path, fileContent); @@ -540,7 +545,7 @@ public void MockFile_AppendText_CreatesNewFileForAppendToNonExistingFile() { string filepath = XFS.Path(@"c:\something\doesnt\exist.txt"); var filesystem = new MockFileSystem(new Dictionary()); - filesystem.AddDirectory(@"c:\something\doesnt"); + filesystem.AddDirectory(XFS.Path(@"c:\something\doesnt")); var stream = filesystem.File.AppendText(filepath); diff --git a/TestHelpers.Tests/MockFileWriteAllBytesTests.cs b/TestHelpers.Tests/MockFileWriteAllBytesTests.cs index 700feeec0..c5e035923 100644 --- a/TestHelpers.Tests/MockFileWriteAllBytesTests.cs +++ b/TestHelpers.Tests/MockFileWriteAllBytesTests.cs @@ -29,7 +29,7 @@ public void MockFile_WriteAllBytes_ShouldWriteDataToMemoryFileSystem() string path = XFS.Path(@"c:\something\demo.txt"); var fileSystem = new MockFileSystem(); var fileContent = new byte[] { 1, 2, 3, 4 }; - fileSystem.AddDirectory(@"c:\something"); + fileSystem.AddDirectory(XFS.Path(@"c:\something")); // Act fileSystem.File.WriteAllBytes(path, fileContent); diff --git a/TestHelpers.Tests/MockFileWriteAllLinesTests.cs b/TestHelpers.Tests/MockFileWriteAllLinesTests.cs index b18654427..170562c43 100644 --- a/TestHelpers.Tests/MockFileWriteAllLinesTests.cs +++ b/TestHelpers.Tests/MockFileWriteAllLinesTests.cs @@ -18,7 +18,7 @@ public static IEnumerable ForDifferentEncoding get { var fileSystem = new MockFileSystem(); - fileSystem.AddDirectory(@"c:\something"); + fileSystem.AddDirectory(XFS.Path(@"c:\something")); var fileContentEnumerable = new List { "first line", "second line", "third line", "fourth and last line" }; var fileContentArray = fileContentEnumerable.ToArray(); Action writeEnumberable = () => fileSystem.File.WriteAllLines(Path, fileContentEnumerable); @@ -169,7 +169,7 @@ public static IEnumerable ForContentsIsNull var path = XFS.Path(@"c:\something\file.txt"); var mockFileData = new MockFileData(string.Empty); mockFileData.Attributes = FileAttributes.ReadOnly; - fileSystem.AddDirectory(@"c:\something"); + fileSystem.AddDirectory(XFS.Path(@"c:\something")); fileSystem.AddFile(path, mockFileData); List fileContentEnumerable = null; string[] fileContentArray = null; @@ -243,6 +243,11 @@ public void MockFile_WriteAllLinesGeneric_ShouldThrowAnArgumentNullExceptionIfEn [TestCaseSource(typeof(TestDataForWriteAllLines), "ForIllegalPath")] 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/MockFileWriteAllTextTests.cs b/TestHelpers.Tests/MockFileWriteAllTextTests.cs index f1a71600e..c93cb4dc1 100644 --- a/TestHelpers.Tests/MockFileWriteAllTextTests.cs +++ b/TestHelpers.Tests/MockFileWriteAllTextTests.cs @@ -16,7 +16,7 @@ public void MockFile_WriteAllText_ShouldWriteTextFileToMemoryFileSystem() string path = XFS.Path(@"c:\something\demo.txt"); string fileContent = "Hello there!"; var fileSystem = new MockFileSystem(); - fileSystem.AddDirectory(@"c:\something"); + fileSystem.AddDirectory(XFS.Path(@"c:\something")); // Act fileSystem.File.WriteAllText(path, fileContent); @@ -35,7 +35,7 @@ public void MockFile_WriteAllText_ShouldOverriteAnExistingFile() // Arrange string path = XFS.Path(@"c:\something\demo.txt"); var fileSystem = new MockFileSystem(); - fileSystem.AddDirectory(@"c:\something"); + fileSystem.AddDirectory(XFS.Path(@"c:\something")); // Act fileSystem.File.WriteAllText(path, "foo"); @@ -192,7 +192,7 @@ public void MockFile_WriteAllText_Encoding_ShouldWriteTextFileToMemoryFileSystem byte[] expectedBytes = encodingsWithContents.Value; Encoding encoding = encodingsWithContents.Key; var fileSystem = new MockFileSystem(); - fileSystem.AddDirectory(@"c:\something"); + fileSystem.AddDirectory(XFS.Path(@"c:\something")); // Act fileSystem.File.WriteAllText(path, FileContent, encoding); @@ -212,7 +212,7 @@ public void MockFile_WriteAllTextMultipleLines_ShouldWriteTextFileToMemoryFileSy var expected = "Hello there!" + Environment.NewLine + "Second line!" + Environment.NewLine; var fileSystem = new MockFileSystem(); - fileSystem.AddDirectory(@"c:\something"); + fileSystem.AddDirectory(XFS.Path(@"c:\something")); // Act fileSystem.File.WriteAllLines(path, fileContent); diff --git a/TestingHelpers/MockDirectory.cs b/TestingHelpers/MockDirectory.cs index 3e972750c..9a468edc9 100644 --- a/TestingHelpers/MockDirectory.cs +++ b/TestingHelpers/MockDirectory.cs @@ -61,6 +61,7 @@ private DirectoryInfoBase CreateDirectoryInternal(string path, DirectorySecurity } var created = new MockDirectoryInfo(mockFileDataAccessor, path); + if (directorySecurity != null) { created.SetAccessControl(directorySecurity); @@ -95,8 +96,14 @@ public override void Delete(string path, bool recursive) public override bool Exists(string path) { + if (path == "/" && XFS.IsUnixPlatform()) + { + return true; + } + try { + path = EnsurePathEndsWithDirectorySeparator(path); path = mockFileDataAccessor.Path.GetFullPath(path); return mockFileDataAccessor.AllDirectories.Any(p => p.Equals(path, StringComparison.OrdinalIgnoreCase)); diff --git a/TestingHelpers/MockDirectoryInfo.cs b/TestingHelpers/MockDirectoryInfo.cs index 20818aff8..cfcbf1a38 100644 --- a/TestingHelpers/MockDirectoryInfo.cs +++ b/TestingHelpers/MockDirectoryInfo.cs @@ -123,7 +123,7 @@ public override DateTime LastWriteTimeUtc public override string Name { - get { return new MockPath(mockFileDataAccessor).GetFileName(directoryPath.TrimEnd('\\')); } + get { return new MockPath(mockFileDataAccessor).GetFileName(directoryPath.TrimEnd(mockFileDataAccessor.Path.DirectorySeparatorChar)); } } public override void Create()