diff --git a/System.IO.Abstractions.TestingHelpers.Tests/DirectoryInfoTests.cs b/System.IO.Abstractions.TestingHelpers.Tests/DirectoryInfoTests.cs new file mode 100644 index 000000000..820b2d66a --- /dev/null +++ b/System.IO.Abstractions.TestingHelpers.Tests/DirectoryInfoTests.cs @@ -0,0 +1,22 @@ +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Text; + +namespace System.IO.Abstractions.TestingHelpers.Tests +{ + [TestFixture] + public class DirectoryInfoTests + { + [Test] + public void Parent_ForRootDirectory_ShouldReturnNull() + { + var wrapperFilesystem = new FileSystem(); + + var current = wrapperFilesystem.Directory.GetCurrentDirectory(); + var root = wrapperFilesystem.DirectoryInfo.FromDirectoryName(current).Root; + var rootsParent = root.Parent; + Assert.IsNull(rootsParent); + } + } +} diff --git a/System.IO.Abstractions/DirectoryInfoWrapper.cs b/System.IO.Abstractions/DirectoryInfoWrapper.cs index ec7e4d5e8..2fe120a22 100644 --- a/System.IO.Abstractions/DirectoryInfoWrapper.cs +++ b/System.IO.Abstractions/DirectoryInfoWrapper.cs @@ -227,7 +227,17 @@ public override void SetAccessControl(DirectorySecurity directorySecurity) public override DirectoryInfoBase Parent { - get { return new DirectoryInfoWrapper(FileSystem, instance.Parent); } + get + { + if (instance.Parent == null) + { + return null; + } + else + { + return new DirectoryInfoWrapper(FileSystem, instance.Parent); + } + } } public override DirectoryInfoBase Root