Skip to content

Commit

Permalink
Avoid null for dateTimeProvider when deserializing
Browse files Browse the repository at this point in the history
  • Loading branch information
vbreuss committed Aug 26, 2022
1 parent e60ff0b commit 1b567e8
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/System.IO.Abstractions.TestingHelpers/MockFileSystem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
 using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;

namespace System.IO.Abstractions.TestingHelpers
{
Expand Down Expand Up @@ -143,7 +144,7 @@ private string GetPathWithCorrectDirectoryCapitalization(string fullPath)
/// <inheritdoc />
public MockFileData AdjustTimes(MockFileData fileData, TimeAdjustments timeAdjustments)
{
var now = (dateTimeProvider ?? defaultDateTimeProvider)();
var now = dateTimeProvider();
if ((timeAdjustments & TimeAdjustments.CreationTime) != TimeAdjustments.None)
{
fileData.CreationTime = now;
Expand Down Expand Up @@ -414,6 +415,12 @@ public IEnumerable<string> AllDirectories
}
}

[OnDeserializing]
private void OnDeserializing(StreamingContext c)
{
dateTimeProvider = defaultDateTimeProvider;
}

private bool AnyFileIsReadOnly(string path)
{
return Directory.GetFiles(path).Any(file => FileIsReadOnly(file));
Expand Down

0 comments on commit 1b567e8

Please sign in to comment.