Skip to content
16 changes: 1 addition & 15 deletions TestHelpers.Tests/MockDirectoryGetAccessControlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@ namespace System.IO.Abstractions.TestingHelpers.Tests
using XFS = MockUnixSupport;

[TestFixture]
[WindowsOnly(WindowsSpecifics.AccessControlLists)]
public class MockDirectoryGetAccessControlTests
{
[TestCase(" ")]
[TestCase(" ")]
public void MockDirectory_GetAccessControl_ShouldThrowArgumentExceptionIfPathContainsOnlyWhitespaces(string path)
{
if (XFS.IsUnixPlatform())
{
Assert.Inconclusive("Unix does not support ACLs.");
}

// Arrange
var fileSystem = new MockFileSystem();

Expand All @@ -35,11 +31,6 @@ public void MockDirectory_GetAccessControl_ShouldThrowArgumentExceptionIfPathCon
[Test]
public void MockDirectory_GetAccessControl_ShouldThrowDirectoryNotFoundExceptionIfDirectoryDoesNotExistInMockData()
{
if (XFS.IsUnixPlatform())
{
Assert.Inconclusive("Unix does not support ACLs.");
}

// Arrange
var fileSystem = new MockFileSystem();
var expectedDirectoryName = XFS.Path(@"c:\a");
Expand All @@ -54,11 +45,6 @@ public void MockDirectory_GetAccessControl_ShouldThrowDirectoryNotFoundException
[Test]
public void MockDirectory_GetAccessControl_ShouldReturnAccessControlOfDirectoryData()
{
if (XFS.IsUnixPlatform())
{
Assert.Inconclusive("Unix does not support ACLs.");
}

// Arrange
var expectedDirectorySecurity = new DirectorySecurity();
expectedDirectorySecurity.SetAccessRuleProtection(false, false);
Expand Down
38 changes: 21 additions & 17 deletions TestHelpers.Tests/MockDirectoryInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,29 +195,33 @@ public void MockDirectoryInfo_EnumerateDirectories_ShouldReturnAllDirectories()
Assert.AreEqual(new[] { "b", "c" }, directories);
}

public static IEnumerable<object[]> MockDirectoryInfo_FullName_Data
[TestCase(@"\\unc\folder", @"\\unc\folder")]
[TestCase(@"\\unc/folder\\foo", @"\\unc\folder\foo")]
[WindowsOnly(WindowsSpecifics.UNCPaths)]
public void MockDirectoryInfo_FullName_ShouldReturnNormalizedUNCPath(string directoryPath, string expectedFullName)
{
get
{
yield return new object[] { XFS.Path(@"c:\temp\\folder"), XFS.Path(@"c:\temp\folder") };
yield return new object[] { XFS.Path(@"c:\temp//folder"), XFS.Path(@"c:\temp\folder") };
yield return new object[] { XFS.Path(@"c:\temp//\\///folder"), XFS.Path(@"c:\temp\folder") };
if (!MockUnixSupport.IsUnixPlatform())
{
yield return new object[] { XFS.Path(@"\\unc\folder"), XFS.Path(@"\\unc\folder") };
yield return new object[] { XFS.Path(@"\\unc/folder\\foo"), XFS.Path(@"\\unc\folder\foo") };
}
}
// Arrange
directoryPath = XFS.Path(directoryPath);
expectedFullName = XFS.Path(expectedFullName);
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>());
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<string, MockFileData>
{
{ XFS.Path(@"c:\temp\folder\a.txt"), "" }
});
directoryPath = XFS.Path(directoryPath);
expectedFullName = XFS.Path(expectedFullName);
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>());
var directoryInfo = new MockDirectoryInfo(fileSystem, directoryPath);

// Act
Expand Down
16 changes: 1 addition & 15 deletions TestHelpers.Tests/MockDirectorySetAccessControlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@ namespace System.IO.Abstractions.TestingHelpers.Tests
using XFS = MockUnixSupport;

[TestFixture]
[WindowsOnly(WindowsSpecifics.AccessControlLists)]
public class MockDirectorySetAccessControlTests
{
[TestCase(" ")]
[TestCase(" ")]
public void MockDirectory_SetAccessControl_ShouldThrowArgumentExceptionIfPathContainsOnlyWhitespaces(string path)
{
if (MockUnixSupport.IsUnixPlatform())
{
Assert.Inconclusive("Unix does not support ACLs.");
}

// Arrange
var fileSystem = new MockFileSystem();
var directorySecurity = new DirectorySecurity();
Expand All @@ -36,11 +32,6 @@ public void MockDirectory_SetAccessControl_ShouldThrowArgumentExceptionIfPathCon
[Test]
public void MockDirectory_SetAccessControl_ShouldThrowDirectoryNotFoundExceptionIfDirectoryDoesNotExistInMockData()
{
if (XFS.IsUnixPlatform())
{
Assert.Inconclusive("Unix does not support ACLs.");
}

// Arrange
var fileSystem = new MockFileSystem();
var expectedFileName = XFS.Path(@"c:\a\");
Expand All @@ -56,11 +47,6 @@ public void MockDirectory_SetAccessControl_ShouldThrowDirectoryNotFoundException
[Test]
public void MockDirectory_SetAccessControl_ShouldReturnAccessControlOfDirectoryData()
{
if (XFS.IsUnixPlatform())
{
Assert.Inconclusive("Unix does not support ACLs.");
}

// Arrange
var filePath = XFS.Path(@"c:\a\");
var fileData = new MockDirectoryData();
Expand Down
65 changes: 23 additions & 42 deletions TestHelpers.Tests/MockDirectoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -540,13 +540,9 @@ public void MockDirectory_CreMockDirectory_CreateDirectory_ShouldReturnDirectory
}

Copy link
Member

Choose a reason for hiding this comment

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

This is one example, I think there was at least one more.

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

I think I'd rather see this in another test and we could add this skip attribute

Copy link
Contributor Author

Choose a reason for hiding this comment

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

6d58566 splits this to separate tests. I'm not sure (but also not very emotional) on what I like better 🤣

Copy link
Member

@jpreese jpreese Jul 9, 2018

Choose a reason for hiding this comment

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

haha I think the idea is better, anyway. You typically want to avoid any sort of logic within a test.

For the approach, I don't think I'd have a test that calls another test with different input. I was more thinking just explicitly put the input in the test and run the test, even if the arrange/act are similar or exact.

So you'd have something like

[Skip on Linux]
public void MockDirectoryInfo_FullName_UNCPaths_ShouldReturnNormalizedPath()
{
  var input = object array of uncpaths {} // arrange
  // act
  // assert
}

There really isn't a reason, that I can see anyway, to have that test data outside of the test itself (especially public ❤️ )

Copy link
Member

Choose a reason for hiding this comment

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

If that's still a little bit confusing, let me know and I could whip up an example. I just think its better to be a little be repetitive in tests vs. trying to avoid repeating yourself. When it comes to tests, I think it's generally better to show as much intent/be expressive as possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that's what I also didn't like. b6a744c tries to improve on this.

Copy link
Member

Choose a reason for hiding this comment

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

Woo! I just saw one more, and then I think we're good. Thanks for this! 🎉

[Test]
[WindowsOnly(WindowsSpecifics.UNCPaths)]
public void MockDirectory_CreateDirectory_ShouldWorkWithUNCPath()
{
if (XFS.IsUnixPlatform())
{
Assert.Inconclusive("Unix does not support ACLs.");
}

// Arrange
var fileSystem = new MockFileSystem();

Expand All @@ -558,13 +554,9 @@ public void MockDirectory_CreateDirectory_ShouldWorkWithUNCPath()
}

[Test]
[WindowsOnly(WindowsSpecifics.UNCPaths)]
public void MockDirectory_CreateDirectory_ShouldFailIfTryingToCreateUNCPathOnlyServer()
{
if (XFS.IsUnixPlatform())
{
Assert.Inconclusive("Unix does not have the concept of UNC paths.");
}

// Arrange
var fileSystem = new MockFileSystem();

Expand All @@ -577,13 +569,9 @@ public void MockDirectory_CreateDirectory_ShouldFailIfTryingToCreateUNCPathOnlyS
}

[Test]
[WindowsOnly(WindowsSpecifics.UNCPaths)]
public void MockDirectory_CreateDirectory_ShouldSucceedIfTryingToCreateUNCPathShare()
{
if (XFS.IsUnixPlatform())
{
Assert.Inconclusive("Unix does not have the concept of UNC paths.");
}

// Arrange
var fileSystem = new MockFileSystem();

Expand Down Expand Up @@ -758,22 +746,27 @@ public void MockDirectory_GetFiles_ShouldThrowAnArgumentException_IfSearchPatter
Assert.Throws<ArgumentException>(action);
}

public static IEnumerable<string> GetSearchPatternForTwoDotsExceptions()
[TestCase(@"..\")]
[TestCase(@"aaa\vv..\")]
[TestCase(@"a..\b")]
[WindowsOnly(WindowsSpecifics.StrictPathRules)]
public void MockDirectory_GetFiles_ShouldThrowAnArgumentException_IfSearchPatternContainsTwoDotsFollowedByOneBackslash(string searchPattern)
{
yield return @"a../b";
yield return @"../";
// Arrange
var directoryPath = XFS.Path(@"c:\Foo");
var fileSystem = new MockFileSystem();
fileSystem.AddDirectory(directoryPath);

if (!XFS.IsUnixPlatform())
{
// These are no problems on Unix platforms
yield return @"..\";
yield return @"aaa\vv..\";
yield return @"a..\b";
}
// Act
TestDelegate action = () => fileSystem.Directory.GetFiles(directoryPath, searchPattern);

// Assert
Assert.Throws<ArgumentException>(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");
Expand Down Expand Up @@ -808,13 +801,9 @@ public void MockDirectory_GetFiles_ShouldFindFilesContainingTwoOrMoreDots()
[TestCase(@"""")]
#endif
[TestCase("aa\t")]
[WindowsOnly(WindowsSpecifics.StrictPathRules)]
public void MockDirectory_GetFiles_ShouldThrowAnArgumentException_IfSearchPatternHasIllegalCharacters(string searchPattern)
{
if (XFS.IsUnixPlatform())
{
Assert.Inconclusive("Unix does not have this limitation.");
}

// Arrange
var directoryPath = XFS.Path(@"c:\Foo");
var fileSystem = new MockFileSystem();
Expand Down Expand Up @@ -1305,13 +1294,9 @@ public void MockDirectory_Move_ShouldThrowAnIOExceptionIfBothPathAreIdentical()
}

[Test]
[WindowsOnly(WindowsSpecifics.Drives)]
public void MockDirectory_Move_ShouldThrowAnIOExceptionIfDirectoriesAreOnDifferentVolumes()
{
if(XFS.IsUnixPlatform())
{
Assert.Inconclusive("Unix does not have the concept of volumes");
}

// Arrange
string sourcePath = XFS.Path(@"c:\a");
string destPath = XFS.Path(@"d:\v");
Expand Down Expand Up @@ -1470,13 +1455,9 @@ public void MockDirectory_GetAccessControl_ShouldThrowExceptionOnDirectoryNotFou
}

[Test]
[WindowsOnly(WindowsSpecifics.AccessControlLists)]
public void MockDirectory_GetAccessControl_ShouldReturnNewDirectorySecurity()
{
if (XFS.IsUnixPlatform())
{
Assert.Inconclusive("Unix does not have the concept of UNC paths.");
}

// Arrange
var fileSystem = new MockFileSystem();
fileSystem.Directory.CreateDirectory(XFS.Path(@"c:\foo\"));
Expand Down
29 changes: 3 additions & 26 deletions TestHelpers.Tests/MockDriveInfoFactoryTests.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
using System.Linq;
using System;
using System.Linq;
using NUnit.Framework;

namespace System.IO.Abstractions.TestingHelpers.Tests
{
using XFS = MockUnixSupport;

[TestFixture]
[WindowsOnly(WindowsSpecifics.Drives)]
public class MockDriveInfoFactoryTests
{
[Test]
public void MockDriveInfoFactory_GetDrives_ShouldReturnDrives()
{
if (XFS.IsUnixPlatform())
{
Assert.Inconclusive("Unix does not have the concept of drives.");
}

// Arrange
var fileSystem = new MockFileSystem();
fileSystem.AddDirectory(XFS.Path(@"C:\Test"));
Expand All @@ -35,11 +32,6 @@ public void MockDriveInfoFactory_GetDrives_ShouldReturnDrives()
[Test]
public void MockDriveInfoFactory_GetDrives_ShouldReturnDrivesWithNoDuplicates()
{
if (XFS.IsUnixPlatform())
{
Assert.Inconclusive("Unix does not have the concept of drives.");
}

// Arrange
var fileSystem = new MockFileSystem();
fileSystem.AddDirectory(XFS.Path(@"C:\Test"));
Expand All @@ -61,11 +53,6 @@ public void MockDriveInfoFactory_GetDrives_ShouldReturnDrivesWithNoDuplicates()
[Test]
public void MockDriveInfoFactory_GetDrives_ShouldReturnOnlyLocalDrives()
{
if (XFS.IsUnixPlatform())
{
Assert.Inconclusive("Unix does not have the concept of drives.");
}

// Arrange
var fileSystem = new MockFileSystem();
fileSystem.AddDirectory(XFS.Path(@"C:\Test"));
Expand All @@ -86,11 +73,6 @@ public void MockDriveInfoFactory_GetDrives_ShouldReturnOnlyLocalDrives()
[Test]
public void MockDriveInfoFactory_FromDriveName_WithDriveShouldReturnDrive()
{
if (XFS.IsUnixPlatform())
{
Assert.Inconclusive("Unix does not have the concept of drives.");
}

// Arrange
var fileSystem = new MockFileSystem();
var factory = new MockDriveInfoFactory(fileSystem);
Expand All @@ -105,11 +87,6 @@ public void MockDriveInfoFactory_FromDriveName_WithDriveShouldReturnDrive()
[Test]
public void MockDriveInfoFactory_FromDriveName_WithPathShouldReturnDrive()
{
if (XFS.IsUnixPlatform())
{
Assert.Inconclusive("Unix does not have the concept of drives.");
}

// Arrange
var fileSystem = new MockFileSystem();
var factory = new MockDriveInfoFactory(fileSystem);
Expand Down
21 changes: 1 addition & 20 deletions TestHelpers.Tests/MockDriveInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@ namespace System.IO.Abstractions.TestingHelpers.Tests
using XFS = MockUnixSupport;

[TestFixture]
[WindowsOnly(WindowsSpecifics.Drives)]
public class MockDriveInfoTests
{
[TestCase(@"c:")]
[TestCase(@"c:\")]
public void MockDriveInfo_Constructor_ShouldInitializeLocalWindowsDrives(string driveName)
{
if (XFS.IsUnixPlatform())
{
Assert.Inconclusive("Unix does not have the concept of drives.");
}

// Arrange
var fileSystem = new MockFileSystem();
fileSystem.AddDirectory(XFS.Path(@"c:\Test"));
Expand All @@ -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"));
Expand All @@ -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();

Expand All @@ -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"));
Expand Down
Loading