Skip to content

Commit

Permalink
fix: incorrectly thrown exception in Directory.CreateSymbolicLink (#…
Browse files Browse the repository at this point in the history
…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).
  • Loading branch information
vbreuss committed Aug 25, 2023
1 parent 00fb310 commit ebb5476
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
Expand Up @@ -98,12 +98,6 @@ public override IFileSystemInfo CreateSymbolicLink(string path, string pathToTar
throw CommonExceptions.FileAlreadyExists(nameof(path));
}

var targetExists = Exists(pathToTarget);
if (!targetExists)
{
throw CommonExceptions.FileNotFound(pathToTarget);
}

mockFileDataAccessor.AddDirectory(path);
mockFileDataAccessor.GetFile(path).LinkTarget = pathToTarget;

Expand Down
Expand Up @@ -184,18 +184,18 @@ public void MockDirectory_CreateSymbolicLink_ShouldFailIfPathExists()
}

[Test]
public void MockDirectory_CreateSymbolicLink_ShouldFailIfTargetDoesNotExist()
public void MockDirectory_CreateSymbolicLink_ShouldNotFailIfTargetDoesNotExist()
{
// Arrange
var fileSystem = new MockFileSystem();
string path = XFS.Path(@"C:\Folder\foo");
string pathToTarget = XFS.Path(@"C:\Target");

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

// Assert
Assert.That(ex.Message.Contains(pathToTarget));
Assert.IsTrue(fileSystemInfo.Exists);
}

[Test]
Expand Down

0 comments on commit ebb5476

Please sign in to comment.