Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: set Creation, LastAccess and LastWrite time for files #875

Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Avoid null for dateTimeProvider when deserializing
vbreuss committed Aug 26, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 1b567e8ed44390a40d537a317a1248971f2c6767
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
{
@@ -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;
@@ -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));