Skip to content

Commit

Permalink
fix: update MockDirectoryInfo.Name to be consistent with DirectoryInf…
Browse files Browse the repository at this point in the history
…o.Name (#715)

When constructed with only the root; MockDirectoryInfo.Name now returns the the root value instead of an empty string. Making it consistent with DirectoryInfo.Name.

Fixes #697
  • Loading branch information
JordanBowker authored Mar 14, 2021
1 parent ba96069 commit c89aa09
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ public override DateTime LastWriteTimeUtc

public override string Name
{
get { return new MockPath(mockFileDataAccessor).GetFileName(directoryPath.TrimEnd(mockFileDataAccessor.Path.DirectorySeparatorChar)); }
get
{
var mockPath = new MockPath(mockFileDataAccessor);
return string.Equals(mockPath.GetPathRoot(directoryPath), directoryPath) ? directoryPath : mockPath.GetFileName(directoryPath.TrimEnd(mockFileDataAccessor.Path.DirectorySeparatorChar));
}
}

public override void Create()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,21 @@ public void MockDirectoryInfo_Name_ShouldReturnNameWithTrimmedTrailingSpaces(str
Assert.AreEqual(expectedName, actualName);
}

[TestCase(@"c:\", @"c:\")]
[WindowsOnly(WindowsSpecifics.Drives)]
public void MockDirectoryInfo_Name_ShouldReturnPathRoot_IfDirectoryPathIsPathRoot(string directoryPath, string expectedName)
{
// Arrange
var fileSystem = new MockFileSystem();
var directoryInfo = new MockDirectoryInfo(fileSystem, directoryPath);

// Act
var actualName = directoryInfo.Name;

// Assert
Assert.AreEqual(expectedName, actualName);
}

[Test]
public void MockDirectoryInfo_Constructor_ShouldThrowArgumentNullException_IfArgumentDirectoryIsNull()
{
Expand Down

0 comments on commit c89aa09

Please sign in to comment.