Skip to content

Commit

Permalink
Merge pull request #419 from System-IO-Abstractions/master
Browse files Browse the repository at this point in the history
Release v3.0
  • Loading branch information
fgreinacher authored Dec 7, 2018
2 parents cd4d0ea + 98f15a1 commit 5366dcf
Show file tree
Hide file tree
Showing 49 changed files with 862 additions and 467 deletions.
7 changes: 0 additions & 7 deletions .travis.yml

This file was deleted.

28 changes: 28 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/System.IO.Abstractions.TestingHelpers.Tests/bin/Debug/netcoreapp2.0/System.IO.Abstractions.TestingHelpers.Tests.dll",
"args": [],
"cwd": "${workspaceFolder}/System.IO.Abstractions.TestingHelpers.Tests",
// For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window
"console": "internalConsole",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
,]
}
15 changes: 15 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/System.IO.Abstractions.TestingHelpers.Tests/System.IO.Abstractions.TestingHelpers.Tests.csproj"
],
"problemMatcher": "$msCompile"
}
]
}
22 changes: 22 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Contributor guide

## Versioning

This library uses [Nerdbank.GitVersioning](https://github.com/AArnott/Nerdbank.GitVersioning) for generating stable and reproducible version numbers.

The base version is manually maintained in [the version config](version.json). Every build calculates its final version number based on the base version and the number of changes that occured since the last change to the version config.

The base version represents the MAJOR and MINOR parts of [SemVer](https://semver.org). If a PR contains breaking changes or new features the base version has to be changed accordingly. If a PR solely contains minor changes (bug fixes, code improvements) nothing needs to be done as the PATCH number will automatically increment with each commit.

## Branches / tags

* `master` contains the latest sources - this is where we develop.
* `release` contains the sources for the latest version on `nuget.org` - this is where we deploy from.
* All versions on `nuget.org` have a matching GitHub release/tag

### Release workflow

1. Create a [PR from `master` to `release`](https://github.com/System-IO-Abstractions/System.IO.Abstractions/compare/release...master?expand=1) and wait for CI to finish.
1. Inspect CI run (test results, version number)
1. Merge PR and wait for deployment
1. Inspect newly created package versions on NuGet.org and newly created GitHub release
5 changes: 5 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project>
<Target Name="VSTestIfTestProject">
<CallTarget Targets="VSTest" Condition="'$(IsTestable)' == 'true'" />
</Target>
</Project>
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
[![NuGet](https://img.shields.io/nuget/v/System.IO.Abstractions.svg)](https://www.nuget.org/packages/System.IO.Abstractions)

[![Windows build status](https://ci.appveyor.com/api/projects/status/em172apw1v5k70vq/branch/master?svg=true)](https://ci.appveyor.com/project/tathamoddie/system-io-abstractions/branch/master) on Windows

[![Linux build status](https://travis-ci.org/System-IO-Abstractions/System.IO.Abstractions.svg?branch=master)](https://travis-ci.org/System-IO-Abstractions/System.IO.Abstractions) on Linux
[![Build status](https://ci.appveyor.com/api/projects/status/em172apw1v5k70vq/branch/master?svg=true)](https://ci.appveyor.com/project/tathamoddie/system-io-abstractions/branch/master) [![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=System-IO-Abstractions/System.IO.Abstractions)](https://dependabot.com)

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public static IEnumerable<object[]> MockDirectoryInfo_Exists_Cases
{
get
{
yield return new object[]{ XFS.Path(@"c:\temp\folder"), true };
yield return new object[]{ XFS.Path(@"c:\temp\folder\notExistant"), false };
yield return new object[] { XFS.Path(@"c:\temp\folder"), true };
yield return new object[] { XFS.Path(@"c:\temp\folder\notExistant"), false };
}
}

Expand Down Expand Up @@ -152,8 +152,8 @@ public void MockDirectoryInfo_GetParent_ShouldReturnDirectoriesAndNamesWithSearc
[Test]
public void MockDirectoryInfo_EnumerateFiles_ShouldReturnAllFiles()
{
// Arrange
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
// Arrange
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
{
//Files "above" in folder we're querying
{ XFS.Path(@"c:\temp\a.txt"), "" },
Expand All @@ -166,11 +166,11 @@ public void MockDirectoryInfo_EnumerateFiles_ShouldReturnAllFiles()
{ XFS.Path(@"c:\temp\folder\deeper\d.txt"), "" }
});

// Act
var directoryInfo = new MockDirectoryInfo(fileSystem, XFS.Path(@"c:\temp\folder"));
// Act
var directoryInfo = new MockDirectoryInfo(fileSystem, XFS.Path(@"c:\temp\folder"));

// Assert
Assert.AreEqual(new[]{"b.txt", "c.txt"}, directoryInfo.EnumerateFiles().ToList().Select(x => x.Name).ToArray());
// Assert
Assert.AreEqual(new[] { "b.txt", "c.txt" }, directoryInfo.EnumerateFiles().ToList().Select(x => x.Name).ToArray());
}

[Test]
Expand Down Expand Up @@ -238,7 +238,7 @@ public void MockDirectoryInfo_Constructor_ShouldThrowArgumentNullException_IfArg
var fileSystem = new MockFileSystem();

// Act
TestDelegate action = () => new MockDirectoryInfo(fileSystem, null);
TestDelegate action = () => new MockDirectoryInfo(fileSystem, null);

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

[Test]
public void MockDirectoryInfo_ToString_ShouldReturnDirectoryName()
[TestCase(@"c:\temp\folder\folder")]
[TestCase(@"..\..\..\Desktop")]
public void MockDirectoryInfo_ToString_ShouldReturnDirectoryName(string directoryName)
{
var directoryPath = XFS.Path(@"c:\temp\folder\folder");

// Arrange
var fileSystem = new MockFileSystem();
var directoryInfo = new MockDirectoryInfo(fileSystem, directoryPath);
var directoryPath = XFS.Path(directoryName);

// Act
var str = directoryInfo.ToString();
var mockDirectoryInfo = new MockDirectoryInfo(new MockFileSystem(), directoryPath);

// Assert
Assert.AreEqual(directoryPath, str);
Assert.AreEqual(directoryPath, mockDirectoryInfo.ToString());
}
}
}
80 changes: 63 additions & 17 deletions System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -547,10 +547,10 @@ public void MockDirectory_CreateDirectory_ShouldWorkWithUNCPath()
var fileSystem = new MockFileSystem();

// Act
fileSystem.Directory.CreateDirectory(XFS.Path(@"\\server\share\path\to\create", () => false));
fileSystem.Directory.CreateDirectory(@"\\server\share\path\to\create");

// Assert
Assert.IsTrue(fileSystem.Directory.Exists(XFS.Path(@"\\server\share\path\to\create\", () => false)));
Assert.IsTrue(fileSystem.Directory.Exists(@"\\server\share\path\to\create\"));
}

[Test]
Expand All @@ -561,7 +561,7 @@ public void MockDirectory_CreateDirectory_ShouldFailIfTryingToCreateUNCPathOnlyS
var fileSystem = new MockFileSystem();

// Act
var ex = Assert.Throws<ArgumentException>(() => fileSystem.Directory.CreateDirectory(XFS.Path(@"\\server", () => false)));
var ex = Assert.Throws<ArgumentException>(() => fileSystem.Directory.CreateDirectory(@"\\server"));

// Assert
StringAssert.StartsWith("The UNC path should be of the form \\\\server\\share.", ex.Message);
Expand All @@ -576,10 +576,10 @@ public void MockDirectory_CreateDirectory_ShouldSucceedIfTryingToCreateUNCPathSh
var fileSystem = new MockFileSystem();

// Act
fileSystem.Directory.CreateDirectory(XFS.Path(@"\\server\share", () => false));
fileSystem.Directory.CreateDirectory(@"\\server\share");

// Assert
Assert.IsTrue(fileSystem.Directory.Exists(XFS.Path(@"\\server\share\", () => false)));
Assert.IsTrue(fileSystem.Directory.Exists(@"\\server\share\"));
}

[Test]
Expand All @@ -599,6 +599,7 @@ public void MockDirectory_Delete_ShouldDeleteDirectory()
}

[Test]
[WindowsOnly(WindowsSpecifics.CaseInsensitivity)]
public void MockDirectory_Delete_ShouldDeleteDirectoryCaseInsensitively()
{
// Arrange
Expand All @@ -614,6 +615,40 @@ public void MockDirectory_Delete_ShouldDeleteDirectoryCaseInsensitively()
Assert.IsFalse(fileSystem.Directory.Exists(XFS.Path(@"c:\bar")));
}

[Test]
[UnixOnly(UnixSpecifics.CaseSensitivity)]
public void MockDirectory_Delete_ShouldThrowDirectoryNotFoundException_WhenSpecifiedWithInDifferentCase()
{
// Arrange
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
{
{ "/bar/foo.txt", new MockFileData("Demo text content") }
});

// Act
TestDelegate action = () => fileSystem.Directory.Delete("/BAR", true);

// Assert
Assert.Throws<DirectoryNotFoundException>(action);
}

[Test]
[UnixOnly(UnixSpecifics.CaseSensitivity)]
public void MockDirectory_Delete_ShouldDeleteDirectoryCaseSensitively()
{
// Arrange
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
{
{ "/bar/foo.txt", new MockFileData("Demo text content") }
});

// Act
fileSystem.Directory.Delete("/bar", true);

// Assert
Assert.IsFalse(fileSystem.Directory.Exists("/bar"));
}

[Test]
public void MockDirectory_Delete_ShouldThrowDirectoryNotFoundException()
{
Expand Down Expand Up @@ -849,8 +884,8 @@ public void MockDirectory_GetLogicalDrives_Returns_LogicalDrives()
else
{
Assert.AreEqual(2, drives.Length);
Assert.IsTrue(drives.Contains("c:\\"));
Assert.IsTrue(drives.Contains("d:\\"));
Assert.IsTrue(drives.Contains(@"C:\"));
Assert.IsTrue(drives.Contains(@"D:\"));
}
}
#endif
Expand Down Expand Up @@ -1184,11 +1219,12 @@ public void MockDirectory_GetCurrentDirectory_ShouldReturnValueFromFileSystemCon

Assert.AreEqual(directory, actual);
}



[Test]
public void MockDirectory_GetCurrentDirectory_ShouldReturnDefaultPathWhenNotSet() {
string directory = Path.GetTempPath();
public void MockDirectory_GetCurrentDirectory_ShouldReturnDefaultPathWhenNotSet()
{
string directory = XFS.Path(@"C:\");

var fileSystem = new MockFileSystem();

var actual = fileSystem.Directory.GetCurrentDirectory();
Expand Down Expand Up @@ -1249,14 +1285,9 @@ public void MockDirectory_GetParent_ShouldReturnADirectoryInfoIfPathDoesNotExist
}

[Test]
[WindowsOnly(WindowsSpecifics.StrictPathRules)]
public void MockDirectory_GetParent_ShouldThrowArgumentExceptionIfPathHasIllegalCharacters()
{
if (XFS.IsUnixPlatform())
{
Assert.Pass("Path.GetInvalidChars() does not return anything on Mono");
return;
}

// Arrange
var fileSystem = new MockFileSystem();

Expand All @@ -1281,6 +1312,21 @@ public void MockDirectory_GetParent_ShouldReturnNullIfPathIsRoot()
Assert.IsNull(actualResult);
}

[Test]
[UnixOnly(UnixSpecifics.SlashRoot)]
public void MockDirectory_GetParent_ShouldReturnRootIfDirectoryIsInRoot()
{
// Arrange
var fileSystem = new MockFileSystem();
fileSystem.AddDirectory("/bar");

// Act
var parent = fileSystem.Directory.GetParent("/bar");

// Assert
Assert.AreEqual("/", parent.FullName);
}

public static IEnumerable<string[]> MockDirectory_GetParent_Cases
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void MockDriveInfoFactory_GetDrives_ShouldReturnDrives()
var actualNames = actualResults.Select(d => d.Name);

// Assert
Assert.That(actualNames, Is.EquivalentTo(new[] { @"C:\", @"Z:\", @"D:\" }));
Assert.That(actualNames, Is.EquivalentTo(new[] { @"C:\", @"Z:\", @"d:\" }));
}

[Test]
Expand All @@ -47,7 +47,7 @@ public void MockDriveInfoFactory_GetDrives_ShouldReturnDrivesWithNoDuplicates()
var actualNames = actualResults.Select(d => d.Name);

// Assert
Assert.That(actualNames, Is.EquivalentTo(new[] { @"C:\", @"Z:\", @"D:\" }));
Assert.That(actualNames, Is.EquivalentTo(new[] { @"C:\", @"Z:\", @"d:\" }));
}

[Test]
Expand All @@ -67,7 +67,7 @@ public void MockDriveInfoFactory_GetDrives_ShouldReturnOnlyLocalDrives()
var actualNames = actualResults.Select(d => d.Name);

// Assert
Assert.That(actualNames, Is.EquivalentTo(new[] { @"C:\", @"Z:\", @"D:\" }));
Assert.That(actualNames, Is.EquivalentTo(new[] { @"C:\", @"Z:\", @"d:\" }));
}

[Test]
Expand Down
23 changes: 20 additions & 3 deletions System.IO.Abstractions.TestingHelpers.Tests/MockDriveInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void MockDriveInfo_Constructor_ShouldInitializeLocalWindowsDrives(string
var driveInfo = new MockDriveInfo(fileSystem, path);

// Assert
Assert.AreEqual(@"C:\", driveInfo.Name);
Assert.AreEqual(@"c:\", driveInfo.Name);
}

[Test]
Expand All @@ -35,7 +35,7 @@ public void MockDriveInfo_Constructor_ShouldInitializeLocalWindowsDrives_Special
var driveInfo = new MockDriveInfo(fileSystem, "c");

// Assert
Assert.AreEqual(@"C:\", driveInfo.Name);
Assert.AreEqual(@"c:\", driveInfo.Name);
}

[TestCase(@"\\unc\share")]
Expand All @@ -59,13 +59,30 @@ public void MockDriveInfo_RootDirectory_ShouldReturnTheDirectoryBase()
var fileSystem = new MockFileSystem();
fileSystem.AddDirectory(XFS.Path(@"c:\Test"));
var driveInfo = new MockDriveInfo(fileSystem, "c:");
var expectedDirectory = XFS.Path(@"C:\");
var expectedDirectory = XFS.Path(@"c:\");

// Act
var actualDirectory = driveInfo.RootDirectory;

// Assert
Assert.AreEqual(expectedDirectory, actualDirectory.FullName);
}

[TestCase("c:","c:\\")]
[TestCase("C:","C:\\")]
[TestCase("d:","d:\\")]
[TestCase("e:","e:\\")]
[TestCase("f:","f:\\")]
public void MockDriveInfo_ToString_ShouldReturnTheDrivePath(string path, string expectedPath)
{
// Arrange
var directoryPath = XFS.Path(path);

// Act
var mockDriveInfo = new MockDriveInfo(new MockFileSystem(), directoryPath);

// Assert
Assert.AreEqual(expectedPath, mockDriveInfo.ToString());
}
}
}
Loading

0 comments on commit 5366dcf

Please sign in to comment.