diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockPath.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockPath.cs index 1ed5c01ab..b79f7c623 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockPath.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockPath.cs @@ -165,7 +165,7 @@ public override string GetRelativePath(string relativeTo, string path) throw new ArgumentNullException(nameof(relativeTo), StringResources.Manager.GetString("VALUE_CANNOT_BE_NULL")); } - if (relativeTo.Length == 0) + if (string.IsNullOrWhiteSpace(relativeTo)) { throw CommonExceptions.PathIsNotOfALegalForm(nameof(relativeTo)); } diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockPathTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockPathTests.cs index 69e8b80bb..0cdcaab1f 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockPathTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockPathTests.cs @@ -494,8 +494,6 @@ public void IsPathFullyQualified_WithRelativePathParts_ReturnsFalse() Assert.IsFalse(result); } - - [Test] public void GetRelativePath_Works() { @@ -508,6 +506,58 @@ public void GetRelativePath_Works() //Assert Assert.AreEqual(XFS.Path("e\\f.txt"), result); } + + [Test] + public void GetRelativePath_WhenPathIsNull_ShouldThrowArgumentNullException() + { + var mockPath = new MockFileSystem().Path; + + var exception = Assert.Throws(() => + { + mockPath.GetRelativePath("foo", null); + }); + + Assert.AreEqual("path", exception.ParamName); + } + + [Test] + public void GetRelativePath_WhenPathIsWhitespace_ShouldThrowArgumentException() + { + var mockPath = new MockFileSystem().Path; + + var exception = Assert.Throws(() => + { + mockPath.GetRelativePath("foo", " "); + }); + + Assert.AreEqual("path", exception.ParamName); + } + + [Test] + public void GetRelativePath_WhenRelativeToNull_ShouldThrowArgumentNullException() + { + var mockPath = new MockFileSystem().Path; + + var exception = Assert.Throws(() => + { + mockPath.GetRelativePath(null, "foo"); + }); + + Assert.AreEqual("relativeTo", exception.ParamName); + } + + [Test] + public void GetRelativePath_WhenRelativeToIsWhitespace_ShouldThrowArgumentException() + { + var mockPath = new MockFileSystem().Path; + + var exception = Assert.Throws(() => + { + mockPath.GetRelativePath(" ", "foo"); + }); + + Assert.AreEqual("relativeTo", exception.ParamName); + } #endif #if FEATURE_PATH_EXISTS