Skip to content

Commit 455afb3

Browse files
author
Dirk Rombauts
committed
Implementing MockFileInfo.Directory
1 parent 8f05095 commit 455afb3

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

TestHelpers.Tests/MockFileInfoTests.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,5 +176,17 @@ public void MockFileInfo_GetDirectoryName_ShouldReturnCompleteDirectoryPath()
176176

177177
Assert.AreEqual(@"c:\temp\level1\level2", result);
178178
}
179-
}
179+
180+
[Test]
181+
public void MockFileInfo_GetDirectory_ShouldReturnDirectoryInfoWithCorrectPath()
182+
{
183+
// Arrange
184+
var fileInfo = new MockFileInfo(new MockFileSystem(), @"c:\temp\level1\level2\file.txt");
185+
186+
// Act
187+
var result = fileInfo.Directory;
188+
189+
Assert.AreEqual(@"c:\temp\level1\level2\", result.FullName);
190+
}
191+
}
180192
}

TestingHelpers/IMockFileDataAccessor.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ public interface IMockFileDataAccessor {
1414
DirectoryBase Directory { get; }
1515
IFileInfoFactory FileInfo {get; }
1616
PathBase Path { get; }
17+
IDirectoryInfoFactory DirectoryInfo { get; }
1718
}
1819
}

TestingHelpers/MockFileInfo.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,10 @@ public override void SetAccessControl(FileSecurity fileSecurity)
215215

216216
public override DirectoryInfoBase Directory
217217
{
218-
get { throw new NotImplementedException("This test helper hasn't been implemented yet. They are implemented on an as-needed basis. As it seems like you need it, now would be a great time to send us a pull request over at https://github.com/tathamoddie/System.IO.Abstractions. You know, because it's open source and all."); }
218+
get
219+
{
220+
return mockFileSystem.DirectoryInfo.FromDirectoryName(this.DirectoryName);
221+
}
219222
}
220223

221224
public override string DirectoryName

0 commit comments

Comments
 (0)