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
31 changes: 31 additions & 0 deletions TestHelpers.Tests/MockDirectoryInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,36 @@ public void MockDirectoryInfo_FullName_ShouldReturnFullNameIncludingTrailingPath

Assert.That(result, Is.EqualTo(@"c:\temp\folder\"));
}

[Test]
public void MockDirectoryInfo_GetFileSystemInfos_ShouldReturnBothDirectoriesAndFiles()
{
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
{
{ @"c:\temp\folder\file.txt", new MockFileData("Hello World") },
{ @"c:\temp\folder\folder", new MockDirectoryData() }
});

var directoryInfo = new MockDirectoryInfo(fileSystem, @"c:\temp\folder");
var result = directoryInfo.GetFileSystemInfos();

Assert.That(result.Length, Is.EqualTo(2));
}

[Test]
public void MockDirectoryInfo_GetFileSystemInfos_ShouldReturnDirectoriesAndNamesWithSearchPattern()
{
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
{
{ @"c:\temp\folder\file.txt", new MockFileData("Hello World") },
{ @"c:\temp\folder\folder", new MockDirectoryData() },
{ @"c:\temp\folder\older", new MockDirectoryData() }
});

var directoryInfo = new MockDirectoryInfo(fileSystem, @"c:\temp\folder");
var result = directoryInfo.GetFileSystemInfos("f*");

Assert.That(result.Length, Is.EqualTo(2));
}
}
}
9 changes: 7 additions & 2 deletions TestingHelpers/MockDirectoryInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,17 @@ FileInfoBase[] ConvertStringsToFiles(IEnumerable<string> paths)

public override FileSystemInfoBase[] GetFileSystemInfos()
{
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.");
return GetFileSystemInfos("*");
}

public override FileSystemInfoBase[] GetFileSystemInfos(string searchPattern)
{
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.");
return GetFileSystemInfos(searchPattern, SearchOption.TopDirectoryOnly);
}

internal FileSystemInfoBase[] GetFileSystemInfos(string searchPattern, SearchOption searchOption)
{
return this.GetDirectories(searchPattern, searchOption).OfType<FileSystemInfoBase>().Concat(this.GetFiles(searchPattern, searchOption)).ToArray();
}

public override void MoveTo(string destDirName)
Expand Down