diff --git a/src/System.IO.Abstractions.TestingHelpers/MockFileInfo.cs b/src/System.IO.Abstractions.TestingHelpers/MockFileInfo.cs
index 840accb1e..4f6f7f577 100644
--- a/src/System.IO.Abstractions.TestingHelpers/MockFileInfo.cs
+++ b/src/System.IO.Abstractions.TestingHelpers/MockFileInfo.cs
@@ -28,6 +28,7 @@ public MockFileInfo(IMockFileDataAccessor mockFileSystem, string path) : base(mo
///
public override void Delete()
{
+ refreshOnNextRead = true;
mockFile.Delete(path);
}
@@ -221,13 +222,17 @@ public override IFileInfo CopyTo(string destFileName, bool overwrite)
///
public override Stream Create()
{
- return mockFile.Create(FullName);
+ var result = mockFile.Create(FullName);
+ refreshOnNextRead = true;
+ return result;
}
///
public override StreamWriter CreateText()
{
- return mockFile.CreateText(FullName);
+ var result = mockFile.CreateText(FullName);
+ refreshOnNextRead = true;
+ return result;
}
///
diff --git a/tests/System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoTests.cs b/tests/System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoTests.cs
index 860615eeb..10034aab5 100644
--- a/tests/System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoTests.cs
+++ b/tests/System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoTests.cs
@@ -750,6 +750,49 @@ public void MockFileInfo_Exists_ShouldUpdateCachedDataOnRefresh()
Assert.IsTrue(fileInfo.Exists);
}
+ [Test]
+ public void MockFileInfo_Create_ShouldUpdateCachedDataAndReturnTrueForExists()
+ {
+ IFileSystem fileSystem = new MockFileSystem();
+ var path = XFS.Path(@"c:\temp\file1.txt");
+ IFileInfo fileInfo = fileSystem.FileInfo.FromFileName(path);
+
+ // Act
+ fileInfo.Create().Dispose();
+
+ // Assert
+ var result = fileInfo.Exists;
+ Assert.IsTrue(result);
+ }
+
+ [Test]
+ public void MockFileInfo_CreateText_ShouldUpdateCachedDataAndReturnTrueForExists()
+ {
+ IFileSystem fileSystem = new MockFileSystem();
+ var path = XFS.Path(@"c:\temp\file1.txt");
+ IFileInfo fileInfo = fileSystem.FileInfo.FromFileName(path);
+
+ // Act
+ fileInfo.CreateText().Dispose();
+
+ // Assert
+ Assert.IsTrue(fileInfo.Exists);
+ }
+
+ [Test]
+ public void MockFileInfo_Delete_ShouldUpdateCachedDataAndReturnFalseForExists()
+ {
+ var fileSystem = new MockFileSystem();
+ var path = XFS.Path(@"c:\temp\file1.txt");
+ IFileInfo fileInfo = fileSystem.FileInfo.FromFileName(path);
+
+ // Act
+ fileInfo.Delete();
+
+ // Assert
+ Assert.IsFalse(fileInfo.Exists);
+ }
+
[Test]
public void MockFileInfo_Delete_ShouldThrowIfFileAccessShareHasNoWriteOrDeleteAccess()
{