Skip to content

Commit 0494719

Browse files
committed
Merge pull request #85 from bacathey/Fix_Directory_GetFiles_NullReferenceException_behavior
Fixed NullReferenceException behavior in MockDirectory.GetFiles
2 parents 1dc6372 + 892d157 commit 0494719

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

TestHelpers.Tests/MockDirectoryTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,15 @@ public void MockDirectory_GetFileSystemEntries_Returns_Files_And_Directories()
504504
Assert.AreEqual(testPath, entries.First());
505505
}
506506

507+
[Test]
508+
public void MockDirectory_GetFiles_ShouldThrowArgumentNullException_IfPathParamIsNull()
509+
{
510+
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>());
511+
512+
TestDelegate action = () => fileSystem.Directory.GetFiles(null);
513+
Assert.Throws<ArgumentNullException>(action);
514+
}
515+
507516
[Test]
508517
public void MockDirectory_GetFiles_ShouldThrowDirectoryNotFoundException_IfPathDoesNotExists()
509518
{

TestingHelpers/MockDirectory.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ public override string[] GetFiles(string path, string searchPattern)
156156

157157
public override string[] GetFiles(string path, string searchPattern, SearchOption searchOption)
158158
{
159+
if(path == null)
160+
throw new ArgumentNullException();
161+
159162
if (!Exists(path))
160163
{
161164
throw new DirectoryNotFoundException(string.Format(CultureInfo.InvariantCulture, "Could not find a part of the path '{0}'.", path));

0 commit comments

Comments
 (0)