Skip to content

Commit ebb5476

Browse files
authored
fix: incorrectly thrown exception in Directory.CreateSymbolicLink (#1026)
Remove incorrectly thrown exception when the target does not exist in Directory.CreateSymbolicLink. The real file system does not throw an exception in this case. > [See here for a succeeding test against the real file system](https://github.com/Testably/Testably.Abstractions/blob/main/Tests/Testably.Abstractions.Tests/FileSystem/Directory/CreateSymbolicLinkTests.cs#L50).
1 parent 00fb310 commit ebb5476

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,6 @@ public override IFileSystemInfo CreateSymbolicLink(string path, string pathToTar
9898
throw CommonExceptions.FileAlreadyExists(nameof(path));
9999
}
100100

101-
var targetExists = Exists(pathToTarget);
102-
if (!targetExists)
103-
{
104-
throw CommonExceptions.FileNotFound(pathToTarget);
105-
}
106-
107101
mockFileDataAccessor.AddDirectory(path);
108102
mockFileDataAccessor.GetFile(path).LinkTarget = pathToTarget;
109103

tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectorySymlinkTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,18 +184,18 @@ public void MockDirectory_CreateSymbolicLink_ShouldFailIfPathExists()
184184
}
185185

186186
[Test]
187-
public void MockDirectory_CreateSymbolicLink_ShouldFailIfTargetDoesNotExist()
187+
public void MockDirectory_CreateSymbolicLink_ShouldNotFailIfTargetDoesNotExist()
188188
{
189189
// Arrange
190190
var fileSystem = new MockFileSystem();
191191
string path = XFS.Path(@"C:\Folder\foo");
192192
string pathToTarget = XFS.Path(@"C:\Target");
193193

194194
// Act
195-
var ex = Assert.Throws<FileNotFoundException>(() => fileSystem.Directory.CreateSymbolicLink(path, pathToTarget));
195+
var fileSystemInfo = fileSystem.Directory.CreateSymbolicLink(path, pathToTarget);
196196

197197
// Assert
198-
Assert.That(ex.Message.Contains(pathToTarget));
198+
Assert.IsTrue(fileSystemInfo.Exists);
199199
}
200200

201201
[Test]

0 commit comments

Comments
 (0)