Skip to content
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 @@ -90,9 +90,12 @@ public override int GetHashCode()
/// <inheritdoc cref="IStorageLocation.GetParent()" />
public IStorageLocation? GetParent()
{
string? parentPath = _fileSystem.Execute.Path.GetDirectoryName(FullPath);
string fullPathWithoutTrailingSeparator = FullPath
.TrimEnd(_fileSystem.Path.DirectorySeparatorChar);
string? parentPath =
_fileSystem.Execute.Path.GetDirectoryName(fullPathWithoutTrailingSeparator);
if (string.Equals(
_fileSystem.Execute.Path.GetPathRoot(FullPath),
_fileSystem.Execute.Path.GetPathRoot(fullPathWithoutTrailingSeparator),
FullPath,
_fileSystem.Execute.StringComparisonMode)
|| parentPath == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,8 @@ public async Task Parent_ArbitraryPaths_ShouldNotBeNull(string path1,
IDirectoryInfo sut = FileSystem.DirectoryInfo.New(path);

await That(sut.Parent).IsNotNull();
await That(sut?.Exists).IsFalse();
await That(sut?.Parent).IsNotNull();
await That(sut?.Parent?.Exists).IsFalse();
await That(sut.Exists).IsFalse();
await That(sut.Parent!.Exists).IsFalse();
}

[Fact]
Expand Down Expand Up @@ -343,6 +342,21 @@ public async Task Parent_ToString_ShouldBeDirectoryNameOnNetFramework(
}
}

[Theory]
[AutoData]
public async Task Parent_WithTrailingDirectorySeparator_ShouldReturnCorrectParent(string path1,
string path2)
{
string path = FileSystem.Path.Combine(path1, path2);
string expectedParent = FileSystem.Path.GetFullPath(path1);

IDirectoryInfo sut =
FileSystem.DirectoryInfo.New(path + FileSystem.Path.DirectorySeparatorChar);

await That(sut.Parent).IsNotNull();
await That(sut.Parent!.FullName).IsEqualTo(expectedParent);
}

[Fact]
public async Task Root_Name_ShouldBeCorrect()
{
Expand Down
Loading