-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add symbolic link functionality (#965)
Implement the `CreateSymbolicLink` and `ResolveLinkTarget` methods on `Directory`, `DirectoryInfo`, `File` and `FileInfo`.
- Loading branch information
Showing
12 changed files
with
389 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...s/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoSymlinkTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.Versioning; | ||
using System.Security.AccessControl; | ||
using NUnit.Framework; | ||
|
||
namespace System.IO.Abstractions.TestingHelpers.Tests | ||
{ | ||
using XFS = MockUnixSupport; | ||
|
||
[TestFixture] | ||
public class MockDirectoryInfoSymlinkTests | ||
{ | ||
|
||
#if FEATURE_CREATE_SYMBOLIC_LINK | ||
|
||
[Test] | ||
public void MockDirectoryInfo_ResolveLinkTarget_ShouldReturnPathOfTargetLink() | ||
{ | ||
var fileSystem = new MockFileSystem(); | ||
fileSystem.Directory.CreateDirectory("bar"); | ||
fileSystem.Directory.CreateSymbolicLink("foo", "bar"); | ||
|
||
var result = fileSystem.DirectoryInfo.New("foo").ResolveLinkTarget(false); | ||
|
||
Assert.AreEqual("bar", result.Name); | ||
} | ||
|
||
[Test] | ||
public void MockDirectoryInfo_ResolveLinkTarget_WithFinalTarget_ShouldReturnPathOfTargetLink() | ||
{ | ||
var fileSystem = new MockFileSystem(); | ||
fileSystem.Directory.CreateDirectory("bar"); | ||
fileSystem.Directory.CreateSymbolicLink("foo", "bar"); | ||
fileSystem.Directory.CreateSymbolicLink("foo1", "foo"); | ||
|
||
var result = fileSystem.DirectoryInfo.New("foo1").ResolveLinkTarget(true); | ||
|
||
Assert.AreEqual("bar", result.Name); | ||
} | ||
|
||
[Test] | ||
public void MockDirectoryInfo_ResolveLinkTarget_WithoutFinalTarget_ShouldReturnFirstLink() | ||
{ | ||
var fileSystem = new MockFileSystem(); | ||
fileSystem.Directory.CreateDirectory("bar"); | ||
fileSystem.Directory.CreateSymbolicLink("foo", "bar"); | ||
fileSystem.Directory.CreateSymbolicLink("foo1", "foo"); | ||
|
||
var result = fileSystem.DirectoryInfo.New("foo1").ResolveLinkTarget(false); | ||
|
||
Assert.AreEqual("foo", result.Name); | ||
} | ||
|
||
[Test] | ||
public void MockDirectoryInfo_ResolveLinkTarget_WithoutTargetLink_ShouldThrowIOException() | ||
{ | ||
var fileSystem = new MockFileSystem(); | ||
fileSystem.Directory.CreateDirectory("bar"); | ||
fileSystem.Directory.CreateSymbolicLink("foo", "bar"); | ||
|
||
Assert.Throws<IOException>(() => | ||
{ | ||
fileSystem.DirectoryInfo.New("bar").ResolveLinkTarget(false); | ||
}); | ||
} | ||
#endif | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.