Skip to content

Commit 70cb67f

Browse files
committed
Implement MockDirectoryInfo.GetFileSystemInfos methods
1 parent b060737 commit 70cb67f

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

TestHelpers.Tests/MockDirectoryInfoTests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,36 @@ public void MockDirectoryInfo_FullName_ShouldReturnFullNameIncludingTrailingPath
6565

6666
Assert.That(result, Is.EqualTo(@"c:\temp\folder\"));
6767
}
68+
69+
[Test]
70+
public void MockDirectoryInfo_GetFileSystemInfos_ShouldReturnBothDirectoriesAndFiles()
71+
{
72+
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
73+
{
74+
{ @"c:\temp\folder\file.txt", new MockFileData("Hello World") },
75+
{ @"c:\temp\folder\folder", new MockDirectoryData() }
76+
});
77+
78+
var directoryInfo = new MockDirectoryInfo(fileSystem, @"c:\temp\folder");
79+
var result = directoryInfo.GetFileSystemInfos();
80+
81+
Assert.That(result.Length, Is.EqualTo(2));
82+
}
83+
84+
[Test]
85+
public void MockDirectoryInfo_GetFileSystemInfos_ShouldReturnDirectoriesAndNamesWithSearchPattern()
86+
{
87+
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
88+
{
89+
{ @"c:\temp\folder\file.txt", new MockFileData("Hello World") },
90+
{ @"c:\temp\folder\folder", new MockDirectoryData() },
91+
{ @"c:\temp\folder\older", new MockDirectoryData() }
92+
});
93+
94+
var directoryInfo = new MockDirectoryInfo(fileSystem, @"c:\temp\folder");
95+
var result = directoryInfo.GetFileSystemInfos("f*");
96+
97+
Assert.That(result.Length, Is.EqualTo(2));
98+
}
6899
}
69100
}

TestingHelpers/MockDirectoryInfo.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,17 @@ FileInfoBase[] ConvertStringsToFiles(IEnumerable<string> paths)
189189

190190
public override FileSystemInfoBase[] GetFileSystemInfos()
191191
{
192-
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.");
192+
return GetFileSystemInfos("*");
193193
}
194194

195195
public override FileSystemInfoBase[] GetFileSystemInfos(string searchPattern)
196196
{
197-
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.");
197+
return GetFileSystemInfos(searchPattern, SearchOption.TopDirectoryOnly);
198+
}
199+
200+
internal FileSystemInfoBase[] GetFileSystemInfos(string searchPattern, SearchOption searchOption)
201+
{
202+
return this.GetDirectories(searchPattern, searchOption).OfType<FileSystemInfoBase>().Concat(this.GetFiles(searchPattern, searchOption)).ToArray();
198203
}
199204

200205
public override void MoveTo(string destDirName)

0 commit comments

Comments
 (0)