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: use correct paramName in Path.GetRelativePath #1035

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,6 @@ public void IsPathFullyQualified_WithRelativePathParts_ReturnsFalse()
Assert.IsFalse(result);
}



[Test]
public void GetRelativePath_Works()
{
Expand All @@ -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<ArgumentNullException>(() =>
{
mockPath.GetRelativePath("foo", null);
});

Assert.AreEqual("path", exception.ParamName);
}

[Test]
public void GetRelativePath_WhenPathIsWhitespace_ShouldThrowArgumentException()
{
var mockPath = new MockFileSystem().Path;

var exception = Assert.Throws<ArgumentException>(() =>
{
mockPath.GetRelativePath("foo", " ");
});

Assert.AreEqual("path", exception.ParamName);
}

[Test]
public void GetRelativePath_WhenRelativeToNull_ShouldThrowArgumentNullException()
{
var mockPath = new MockFileSystem().Path;

var exception = Assert.Throws<ArgumentNullException>(() =>
{
mockPath.GetRelativePath(null, "foo");
});

Assert.AreEqual("relativeTo", exception.ParamName);
}

[Test]
public void GetRelativePath_WhenRelativeToIsWhitespace_ShouldThrowArgumentException()
{
var mockPath = new MockFileSystem().Path;

var exception = Assert.Throws<ArgumentException>(() =>
{
mockPath.GetRelativePath(" ", "foo");
});

Assert.AreEqual("relativeTo", exception.ParamName);
}
#endif

#if FEATURE_PATH_EXISTS
Expand Down