Skip to content

fix: Fixes TestableIO/System.IO.Abstractions#1131 #1312

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ private MockFileData()
LastWriteTime = now;
LastAccessTime = now;
CreationTime = now;
contents = new byte[0];
contentVersion = 0;
}

/// <summary>
Expand All @@ -76,7 +78,8 @@ public MockFileData(string textContents)
public MockFileData(string textContents, Encoding encoding)
: this()
{
Contents = encoding.GetPreamble().Concat(encoding.GetBytes(textContents)).ToArray();
contents = encoding.GetPreamble().Concat(encoding.GetBytes(textContents)).ToArray();
contentVersion = 1;
}

/// <summary>
Expand All @@ -87,7 +90,8 @@ public MockFileData(string textContents, Encoding encoding)
public MockFileData(byte[] contents)
: this()
{
Contents = contents ?? throw new ArgumentNullException(nameof(contents));
this.contents = contents ?? throw new ArgumentNullException(nameof(contents));
contentVersion = 1;
}


Expand All @@ -105,7 +109,8 @@ public MockFileData(MockFileData template)

accessControl = template.accessControl;
Attributes = template.Attributes;
Contents = template.Contents.ToArray();
contents = template.contents?.ToArray();
contentVersion = template.contentVersion;
CreationTime = template.CreationTime;
LastAccessTime = template.LastAccessTime;
LastWriteTime = template.LastWriteTime;
Expand All @@ -114,10 +119,26 @@ public MockFileData(MockFileData template)
#endif
}

private byte[] contents;
private long contentVersion;

/// <summary>
/// Gets or sets the byte contents of the <see cref="MockFileData"/>.
/// </summary>
public byte[] Contents { get; set; }
public byte[] Contents
{
get => contents;
set
{
contents = value;
contentVersion++;
}
}

/// <summary>
/// Gets the current version of the file contents. This is incremented every time Contents is modified.
/// </summary>
internal long ContentVersion => contentVersion;

/// <summary>
/// Gets or sets the file version info of the <see cref="MockFileData"/>
Expand Down
Loading
Loading