Skip to content

Commit

Permalink
Merge pull request #289 from pasn/xamarin-runtime-fix
Browse files Browse the repository at this point in the history
Fix runtime issues on non-Windows platforms (notable example is Xamarin)
  • Loading branch information
tathamoddie authored Jul 4, 2018
2 parents 90d6fa8 + dd1d489 commit 0ae3ed8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
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

0 comments on commit 0ae3ed8

Please sign in to comment.