Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions TestHelpers.Tests/MockDirectoryGetAccessControlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public class MockDirectoryGetAccessControlTests
[TestCase(" ")]
public void MockDirectory_GetAccessControl_ShouldThrowArgumentExceptionIfPathContainsOnlyWhitespaces(string path)
{
if (MockUnixSupport.IsUnixPlatform())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of this block of code throughout the test project, what do we think about categorizing Windows tests?

I think this would declutter the test runner a bit more (no need for inconclusives) and would also clearly show that the feature we're testing is intended for Windows.

{
Assert.Inconclusive("Unix does not support ACLs.");
}

// Arrange
var fileSystem = new MockFileSystem();

Expand All @@ -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");
Expand All @@ -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);
Expand Down
11 changes: 7 additions & 4 deletions TestHelpers.Tests/MockDirectoryInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,11 @@ public static IEnumerable<object[]> 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())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be a little better if we just removed these values from the test data, and then made a new Windows test that checked just the two unc paths. This way we're testing drive paths and unc paths in two different tests. What do you think?

{
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") };
}
}
}

Expand Down Expand Up @@ -263,8 +266,8 @@ public void MockDirectoryInfo_Constructor_ShouldThrowArgumentException_IfArgumen
// Assert
var exception = Assert.Throws<ArgumentException>(action);
Assert.That(exception.Message, Does.StartWith("The path is not of a legal form."));
}
}

[Test]
public void MockDirectoryInfo_ToString_ShouldReturnDirectoryName()
{
Expand Down
15 changes: 15 additions & 0 deletions TestHelpers.Tests/MockDirectorySetAccessControlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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\");
Expand All @@ -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();
Expand Down
79 changes: 57 additions & 22 deletions TestHelpers.Tests/MockDirectoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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();

Expand All @@ -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();

Expand Down Expand Up @@ -745,11 +760,16 @@ public void MockDirectory_GetFiles_ShouldThrowAnArgumentException_IfSearchPatter

public static IEnumerable<string> GetSearchPatternForTwoDotsExceptions()
{
yield return @"a..\b";
yield return @"a../b";
yield return @"../";
yield return @"..\";
yield return @"aaa\vv..\";

if (!MockUnixSupport.IsUnixPlatform())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a little confusing to me. If we're not on a Unix platform, go ahead and add these values to the test data.. but the comment says that these aren't a problem on Unix, so why would we exclude these? If they do need to be excluded, I would go with a similar approach as outlined above where we'd just go ahead and remove these and leverage a Windows test.

{
// These are no problem on Unix platforms
yield return @"..\";
yield return @"aaa\vv..\";
yield return @"a..\b";
}
}

[TestCaseSource(typeof(MockDirectoryTests), "GetSearchPatternForTwoDotsExceptions")]
Expand Down Expand Up @@ -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 }));
Expand All @@ -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();
Expand Down Expand Up @@ -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
);
}
Expand Down Expand Up @@ -1067,28 +1092,28 @@ public void MockDirectory_EnumerateDirectories_ShouldThrowWhenPathIsNotMocked()

public static IEnumerable<object[]> 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]
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")]
Expand All @@ -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<string, MockFileData>
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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\"));
Expand Down
15 changes: 15 additions & 0 deletions TestHelpers.Tests/MockDriveInfoFactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand All @@ -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"));
Expand All @@ -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"));
Expand Down
15 changes: 15 additions & 0 deletions TestHelpers.Tests/MockDriveInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down Expand Up @@ -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();

Expand All @@ -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"));
Expand Down
5 changes: 5 additions & 0 deletions TestHelpers.Tests/MockFileAppendAllLinesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
15 changes: 2 additions & 13 deletions TestHelpers.Tests/MockFileAppendAllTextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public void MockFile_AppendAllText_ShouldCreateIfNotExistWithBom()
{
// Arrange
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>());
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);
Expand Down Expand Up @@ -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));
Expand Down
Loading