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
8 changes: 6 additions & 2 deletions TestingHelpers/MockDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public MockDirectory(IMockFileDataAccessor mockFileDataAccessor, FileBase fileBa

public override DirectoryInfoBase CreateDirectory(string path)
{
return CreateDirectoryInternal(path, new DirectorySecurity());
return CreateDirectoryInternal(path, null);
}

#if NET40
Expand Down Expand Up @@ -61,7 +61,11 @@ private DirectoryInfoBase CreateDirectoryInternal(string path, DirectorySecurity
}

var created = new MockDirectoryInfo(mockFileDataAccessor, path);
created.SetAccessControl(directorySecurity);
if (directorySecurity != null)
{
created.SetAccessControl(directorySecurity);
}

return created;
}

Expand Down
11 changes: 8 additions & 3 deletions TestingHelpers/MockDirectoryData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,23 @@ namespace System.IO.Abstractions.TestingHelpers
public class MockDirectoryData : MockFileData
{
[NonSerialized]
private DirectorySecurity accessControl = new DirectorySecurity();
private DirectorySecurity accessControl;

public override bool IsDirectory { get { return true; } }

public MockDirectoryData() : base(string.Empty)
{
Attributes = FileAttributes.Directory;
}

public new DirectorySecurity AccessControl
{
get { return accessControl; }
get
{
// DirectorySecurity's constructor will throw PlatformNotSupportedException on non-Windows platform, so we initialize it in lazy way.
// This let's us use this class as long as we don't use AccessControl property.
return accessControl ?? (accessControl = new DirectorySecurity());
}
set { accessControl = value; }
}
}
Expand Down
9 changes: 7 additions & 2 deletions TestingHelpers/MockFileData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class MockFileData
/// The access control of the <see cref="MockFileData"/>.
/// </summary>
[NonSerialized]
private FileSecurity accessControl = new FileSecurity();
private FileSecurity accessControl;

/// <summary>
/// Gets a value indicating whether the <see cref="MockFileData"/> is a directory or not.
Expand Down Expand Up @@ -181,7 +181,12 @@ public FileAttributes Attributes
/// </summary>
public FileSecurity AccessControl
{
get { return accessControl; }
get
{
// FileSecurity's constructor will throw PlatformNotSupportedException on non-Windows platform, so we initialize it in lazy way.
// This let's us use this class as long as we don't use AccessControl property.
return accessControl ?? (accessControl = new FileSecurity());
}
set { accessControl = value; }
}
}
Expand Down