Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: incorrectly thrown exception in Directory.CreateSymbolicLink #1026

Merged
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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