Skip to content

Commit 992c3a8

Browse files
author
Jens Weiermann
committed
Fix (and test) for #429
1 parent d236bd1 commit 992c3a8

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using NUnit.Framework;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
6+
namespace System.IO.Abstractions.TestingHelpers.Tests
7+
{
8+
[TestFixture]
9+
public class DirectoryInfoTests
10+
{
11+
[Test]
12+
public void Parent_ForRootDirectory_ShouldReturnNull()
13+
{
14+
var wrapperFilesystem = new FileSystem();
15+
16+
var directoryInfo = wrapperFilesystem.DirectoryInfo.FromDirectoryName("C:\\");
17+
var rootsParent = directoryInfo.Parent;
18+
Assert.IsNull(rootsParent);
19+
}
20+
}
21+
}

System.IO.Abstractions/DirectoryInfoWrapper.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,13 @@ public override void SetAccessControl(DirectorySecurity directorySecurity)
227227

228228
public override DirectoryInfoBase Parent
229229
{
230-
get { return new DirectoryInfoWrapper(FileSystem, instance.Parent); }
230+
get
231+
{
232+
if (instance.Parent == null)
233+
return null;
234+
else
235+
return new DirectoryInfoWrapper(FileSystem, instance.Parent);
236+
}
231237
}
232238

233239
public override DirectoryInfoBase Root

0 commit comments

Comments
 (0)