From 20ae8f944dbb5e6e9ca07df56e1641cc022cd838 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Tue, 22 Aug 2023 07:30:49 +0200 Subject: [PATCH] Remove incorrectly thrown exception when the target does not exist in Directory.CreateSymbolicLink --- .../MockDirectory.cs | 6 ------ .../MockDirectorySymlinkTests.cs | 6 +++--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs index e3681b0a0..f3d6ee9fe 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs @@ -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; diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectorySymlinkTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectorySymlinkTests.cs index 97415a27c..90a36a19b 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectorySymlinkTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectorySymlinkTests.cs @@ -184,7 +184,7 @@ public void MockDirectory_CreateSymbolicLink_ShouldFailIfPathExists() } [Test] - public void MockDirectory_CreateSymbolicLink_ShouldFailIfTargetDoesNotExist() + public void MockDirectory_CreateSymbolicLink_ShouldNotFailIfTargetDoesNotExist() { // Arrange var fileSystem = new MockFileSystem(); @@ -192,10 +192,10 @@ public void MockDirectory_CreateSymbolicLink_ShouldFailIfTargetDoesNotExist() string pathToTarget = XFS.Path(@"C:\Target"); // Act - var ex = Assert.Throws(() => fileSystem.Directory.CreateSymbolicLink(path, pathToTarget)); + var fileSystemInfo = fileSystem.Directory.CreateSymbolicLink(path, pathToTarget); // Assert - Assert.That(ex.Message.Contains(pathToTarget)); + Assert.IsTrue(fileSystemInfo.Exists); } [Test]