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
22 changes: 22 additions & 0 deletions System.IO.Abstractions.TestingHelpers.Tests/DirectoryInfoTests.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
12 changes: 11 additions & 1 deletion System.IO.Abstractions/DirectoryInfoWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down