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
2 changes: 2 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<Authors>Tatham Oddie &amp; friends</Authors>
<SignAssembly Condition="'$(Configuration)' == 'Release'">True</SignAssembly>
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)StrongName.snk</AssemblyOriginatorKeyFile>
<DefineConstants Condition="'$(TargetFramework)' == 'netcoreapp3.0' OR '$(TargetFramework)' == 'netstandard2.1'">$(DefineConstants);FEATURE_ASYNC_FILE;FEATURE_ENUMERATION_OPTIONS;FEATURE_ADVANCED_PATH_OPERATIONS</DefineConstants>

</PropertyGroup>
<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" Version="3.0.50">
Expand Down
98 changes: 77 additions & 21 deletions System.IO.Abstractions.TestingHelpers.Tests/MockPathTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,13 @@ public static IEnumerable<string[]> GetFullPath_RelativePaths_Cases
{
get
{
yield return new [] { XFS.Path(@"c:\a"), "b", XFS.Path(@"c:\a\b") };
yield return new [] { XFS.Path(@"c:\a\b"), "c", XFS.Path(@"c:\a\b\c") };
yield return new [] { XFS.Path(@"c:\a\b"), XFS.Path(@"c\"), XFS.Path(@"c:\a\b\c\") };
yield return new [] { XFS.Path(@"c:\a\b"), XFS.Path(@"..\c"), XFS.Path(@"c:\a\c") };
yield return new [] { XFS.Path(@"c:\a\b\c"), XFS.Path(@"..\c\..\"), XFS.Path(@"c:\a\b\") };
yield return new [] { XFS.Path(@"c:\a\b\c"), XFS.Path(@"..\..\..\..\..\d"), XFS.Path(@"c:\d") };
yield return new [] { XFS.Path(@"c:\a\b\c"), XFS.Path(@"..\..\..\..\..\d\"), XFS.Path(@"c:\d\") };
yield return new[] { XFS.Path(@"c:\a"), "b", XFS.Path(@"c:\a\b") };
yield return new[] { XFS.Path(@"c:\a\b"), "c", XFS.Path(@"c:\a\b\c") };
yield return new[] { XFS.Path(@"c:\a\b"), XFS.Path(@"c\"), XFS.Path(@"c:\a\b\c\") };
yield return new[] { XFS.Path(@"c:\a\b"), XFS.Path(@"..\c"), XFS.Path(@"c:\a\c") };
yield return new[] { XFS.Path(@"c:\a\b\c"), XFS.Path(@"..\c\..\"), XFS.Path(@"c:\a\b\") };
yield return new[] { XFS.Path(@"c:\a\b\c"), XFS.Path(@"..\..\..\..\..\d"), XFS.Path(@"c:\d") };
yield return new[] { XFS.Path(@"c:\a\b\c"), XFS.Path(@"..\..\..\..\..\d\"), XFS.Path(@"c:\d\") };
}
}

Expand All @@ -172,11 +172,11 @@ public static IEnumerable<string[]> GetFullPath_RootedPathWithRelativeSegments_C
{
get
{
yield return new [] { XFS.Path(@"c:\a\b\..\c"), XFS.Path(@"c:\a\c") };
yield return new [] { XFS.Path(@"c:\a\b\.\.\..\.\c"), XFS.Path(@"c:\a\c") };
yield return new [] { XFS.Path(@"c:\a\b\.\c"), XFS.Path(@"c:\a\b\c") };
yield return new [] { XFS.Path(@"c:\a\b\.\.\.\.\c"), XFS.Path(@"c:\a\b\c") };
yield return new [] { XFS.Path(@"c:\a\..\..\c"), XFS.Path(@"c:\c") };
yield return new[] { XFS.Path(@"c:\a\b\..\c"), XFS.Path(@"c:\a\c") };
yield return new[] { XFS.Path(@"c:\a\b\.\.\..\.\c"), XFS.Path(@"c:\a\c") };
yield return new[] { XFS.Path(@"c:\a\b\.\c"), XFS.Path(@"c:\a\b\c") };
yield return new[] { XFS.Path(@"c:\a\b\.\.\.\.\c"), XFS.Path(@"c:\a\b\c") };
yield return new[] { XFS.Path(@"c:\a\..\..\c"), XFS.Path(@"c:\c") };
}
}

Expand All @@ -198,14 +198,14 @@ public static IEnumerable<string[]> GetFullPath_AbsolutePaths_Cases
{
get
{
yield return new [] { XFS.Path(@"c:\a"), XFS.Path(@"/b"), XFS.Path(@"c:\b") };
yield return new [] { XFS.Path(@"c:\a"), XFS.Path(@"/b\"), XFS.Path(@"c:\b\") };
yield return new [] { XFS.Path(@"c:\a"), XFS.Path(@"\b"), XFS.Path(@"c:\b") };
yield return new [] { XFS.Path(@"c:\a"), XFS.Path(@"\b\..\c"), XFS.Path(@"c:\c") };
yield return new [] { XFS.Path(@"z:\a"), XFS.Path(@"\b\..\c"), XFS.Path(@"z:\c") };
yield return new [] { XFS.Path(@"z:\a"), XFS.Path(@"\\computer\share\c"), XFS.Path(@"\\computer\share\c") };
yield return new [] { XFS.Path(@"z:\a"), XFS.Path(@"\\computer\share\c\..\d"), XFS.Path(@"\\computer\share\d") };
yield return new [] { XFS.Path(@"z:\a"), XFS.Path(@"\\computer\share\c\..\..\d"), XFS.Path(@"\\computer\share\d") };
yield return new[] { XFS.Path(@"c:\a"), XFS.Path(@"/b"), XFS.Path(@"c:\b") };
yield return new[] { XFS.Path(@"c:\a"), XFS.Path(@"/b\"), XFS.Path(@"c:\b\") };
yield return new[] { XFS.Path(@"c:\a"), XFS.Path(@"\b"), XFS.Path(@"c:\b") };
yield return new[] { XFS.Path(@"c:\a"), XFS.Path(@"\b\..\c"), XFS.Path(@"c:\c") };
yield return new[] { XFS.Path(@"z:\a"), XFS.Path(@"\b\..\c"), XFS.Path(@"z:\c") };
yield return new[] { XFS.Path(@"z:\a"), XFS.Path(@"\\computer\share\c"), XFS.Path(@"\\computer\share\c") };
yield return new[] { XFS.Path(@"z:\a"), XFS.Path(@"\\computer\share\c\..\d"), XFS.Path(@"\\computer\share\d") };
yield return new[] { XFS.Path(@"z:\a"), XFS.Path(@"\\computer\share\c\..\..\d"), XFS.Path(@"\\computer\share\d") };
}
}

Expand Down Expand Up @@ -274,7 +274,7 @@ public void GetFullPath_WithMultipleDirectorySeparators_ShouldReturnTheNormalize
var mockPath = new MockPath(mockFileSystem);

//Act
var actualFullPath = mockPath.GetFullPath(XFS.Path(@"c:\foo\\//bar\file.dat"));
var actualFullPath = mockPath.GetFullPath(XFS.Path(@"c:\foo\\//bar\file.dat"));

//Assert
Assert.AreEqual(XFS.Path(@"c:\foo\bar\file.dat"), actualFullPath);
Expand Down Expand Up @@ -397,5 +397,61 @@ public void IsPathRooted_PathSentIn_DeterminesPathExists()
//Assert
Assert.AreEqual(true, result);
}

#if FEATURE_ADVANCED_PATH_OPERATIONS
[Test]
public void IsPathFullyQualified_WithAbsolutePath_ReturnsTrue()
{
//Arrange
var mockPath = new MockPath(new MockFileSystem());

//Act
var result = mockPath.IsPathFullyQualified(XFS.Path("C:\\directory\\file.txt"));

//Assert
Assert.IsTrue(result);
}

[Test]
public void IsPathFullyQualified_WithRelativePath_ReturnsFalse()
{
//Arrange
var mockPath = new MockPath(new MockFileSystem());

//Act
var result = mockPath.IsPathRooted(XFS.Path("directory\\file.txt"));

//Assert
Assert.IsFalse(result);
}

[Test]
public void IsPathFullyQualified_WithRelativePathParts_ReturnsFalse()
{
//Arrange
var mockPath = new MockPath(new MockFileSystem());

//Act
var result = mockPath.IsPathRooted(XFS.Path("directory\\..\\file.txt"));

//Assert
Assert.IsFalse(result);
}



[Test]
public void GetRelativePath_Works()
{
//Arrange
var mockPath = new MockPath(new MockFileSystem());

//Act
var result = mockPath.GetRelativePath(XFS.Path("c:\\d"), XFS.Path("c:\\d\\e\\f.txt"));

//Assert
Assert.AreEqual(XFS.Path("e\\f.txt"), result);
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<RootNamespace>System.IO.Abstractions.TestingHelpers.Tests</RootNamespace>
<IsPackable>false</IsPackable>
<IsTestable>true</IsTestable>
<DefineConstants Condition="'$(TargetFramework)' == 'netcoreapp3.0'">$(DefineConstants);FEATURE_ASYNC_FILE;FEATURE_ENUMERATION_OPTIONS</DefineConstants>
</PropertyGroup>
<ItemGroup>
<None Remove="TestFiles\SecondTestFile.txt" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<PackageProjectUrl>https://github.com/System-IO-Abstractions/System.IO.Abstractions</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageTags>testing</PackageTags>
<DefineConstants Condition="'$(TargetFramework)' == 'netstandard2.1'">$(DefineConstants);FEATURE_ASYNC_FILE;FEATURE_ENUMERATION_OPTIONS</DefineConstants>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\System.IO.Abstractions\System.IO.Abstractions.csproj" />
Expand Down
8 changes: 8 additions & 0 deletions System.IO.Abstractions/IPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,13 @@ public interface IPath
bool HasExtension(string path);
/// <inheritdoc cref="Path.IsPathRooted(string)"/>
bool IsPathRooted(string path);

#if FEATURE_ADVANCED_PATH_OPERATIONS
/// <inheritdoc cref="Path.IsPathFullyQualified(string)"/>
bool IsPathFullyQualified(string path);

/// <inheritdoc cref="Path.GetRelativePath(string,string)"/>
string GetRelativePath(string relativeTo, string path);
#endif
}
}
8 changes: 8 additions & 0 deletions System.IO.Abstractions/PathBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,13 @@ internal PathBase() { }

/// <inheritdoc cref="Path.IsPathRooted(string)"/>
public abstract bool IsPathRooted(string path);

#if FEATURE_ADVANCED_PATH_OPERATIONS
/// <inheritdoc />
public abstract bool IsPathFullyQualified(string path);

/// <inheritdoc />
public abstract string GetRelativePath(string relativeTo, string path);
#endif
}
}
12 changes: 12 additions & 0 deletions System.IO.Abstractions/PathWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ public override bool HasExtension(string path)
return Path.HasExtension(path);
}

#if FEATURE_ADVANCED_PATH_OPERATIONS
public override bool IsPathFullyQualified(string path)
{
return Path.IsPathFullyQualified(path);
}

public override string GetRelativePath(string relativeTo, string path)
{
return Path.GetRelativePath(relativeTo, path);
}
#endif

public override bool IsPathRooted(string path)
{
return Path.IsPathRooted(path);
Expand Down
2 changes: 1 addition & 1 deletion System.IO.Abstractions/System.IO.Abstractions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<PackageProjectUrl>https://github.com/System-IO-Abstractions/System.IO.Abstractions</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageTags>testing</PackageTags>
<DefineConstants Condition="'$(TargetFramework)' == 'netstandard2.1'">$(DefineConstants);FEATURE_ASYNC_FILE;FEATURE_ENUMERATION_OPTIONS</DefineConstants>
<DefineConstants Condition="'$(TargetFramework)' == 'netstandard2.1'">$(DefineConstants);FEATURE_ASYNC_FILE;FEATURE_ENUMERATION_OPTIONS;FEATURE_ADVANCED_PATH_OPERATIONS</DefineConstants>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'net461'">
<PackageReference Include="System.IO.FileSystem.AccessControl" Version="4.7.0"/>
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "8.1",
"version": "9.0",
"assemblyVersion": {
"precision": "major"
},
Expand Down