Skip to content
Merged
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 @@ -70,6 +70,22 @@ public void MockFile_ReadAllLines_NotExistingFile_ThrowsCorrectFileNotFoundExcep
Assert.That(exception.Message, Is.EqualTo("Could not find file '" + absentFileNameFullPath + "'."));
}

[Test]
public void MockFile_ReadAllLines_ShouldNotReturnBom()
{
// Arrange
var testFilePath = XFS.Path(@"c:\a test file.txt");
const string testText = "Hello World";
var fileSystem = new MockFileSystem();
fileSystem.File.WriteAllLines(testFilePath, new[] { testText }, Encoding.UTF8);

// Act
var result = fileSystem.File.ReadAllLines(testFilePath, Encoding.UTF8);

// Assert
Assert.That(result.Length, Is.EqualTo(1));
Assert.That(result[0], Is.EqualTo(testText));
}
#if FEATURE_ASYNC_FILE
[Test]
public async Task MockFile_ReadAllLinesAsync_ShouldReturnOriginalTextData()
Expand Down
9 changes: 6 additions & 3 deletions System.IO.Abstractions.TestingHelpers/MockFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,12 @@ public override string[] ReadAllLines(string path, Encoding encoding)
}

mockFileDataAccessor.GetFile(path).CheckFileAccess(path, FileAccess.Read);
return encoding
.GetString(mockFileDataAccessor.GetFile(path).Contents)
.SplitLines();

using (var ms = new MemoryStream(mockFileDataAccessor.GetFile(path).Contents))
using (var sr = new StreamReader(ms, encoding))
{
return sr.ReadToEnd().SplitLines();
Comment thread
fgreinacher marked this conversation as resolved.
}
}

public override string ReadAllText(string path)
Expand Down