Skip to content

Commit fe15c80

Browse files
committed
Removed unnecessary unit test and introduced MaxContentComparisonSize constant for cleaner comparison logic in MockFileStream.
1 parent 96baf92 commit fe15c80

File tree

2 files changed

+4
-36
lines changed

2 files changed

+4
-36
lines changed

src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileStream.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ public NullFileSystemStream() : base(Null, ".", true)
4545
// This prevents us from overwriting shared content unnecessarily and helps preserve unflushed changes during refresh
4646
private bool hasUnflushedWrites;
4747

48+
// Maximum file size for content comparison optimization
49+
private const int MaxContentComparisonSize = 4096;
50+
4851

4952
/// <inheritdoc />
5053
public MockFileStream(
@@ -454,7 +457,7 @@ private bool IsContentIdentical(byte[] sharedContent)
454457
}
455458

456459
// Quick content comparison for common case where only metadata changed
457-
if (sharedContent.Length > 0 && sharedContent.Length <= 4096) // Only check small files
460+
if (sharedContent.Length > 0 && sharedContent.Length <= MaxContentComparisonSize) // Only check small files
458461
{
459462
var currentPos = Position;
460463
Position = 0;

tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamTests.cs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -451,41 +451,6 @@ await That(readData[cycle]).IsEqualTo((byte)(cycle + 100))
451451
}
452452
}
453453

454-
[Test]
455-
public async Task MockFileStream_SharedContent_VersionOverflowHandling()
456-
{
457-
var fileSystem = new MockFileSystem();
458-
var filename = fileSystem.Path.Combine(fileSystem.Path.GetTempPath(), fileSystem.Path.GetRandomFileName());
459-
460-
try
461-
{
462-
using var file1 = fileSystem.FileStream.New(filename, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
463-
using var file2 = fileSystem.FileStream.New(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
464-
465-
// Get reference to file data to manipulate version directly
466-
var fileData = fileSystem.GetFile(filename);
467-
468-
// Simulate near-overflow condition
469-
var reflection = typeof(MockFileData).GetField("contentVersion",
470-
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
471-
reflection?.SetValue(fileData, long.MaxValue - 1);
472-
473-
// Write data that will cause version to overflow
474-
file1.Write(new byte[] { 1, 2, 3, 4 });
475-
file1.Flush();
476-
477-
// file2 should still be able to read the data despite version overflow
478-
file2.Position = 0;
479-
var buffer = new byte[4];
480-
var bytesRead = file2.Read(buffer);
481-
await That(bytesRead).IsEqualTo(4);
482-
await That(buffer).IsEquivalentTo(new byte[] { 1, 2, 3, 4 });
483-
}
484-
finally
485-
{
486-
fileSystem.File.Delete(filename);
487-
}
488-
}
489454

490455
[Test]
491456
public async Task MockFileStream_Constructor_ReadTypeNotWritable()

0 commit comments

Comments
 (0)