Skip to content

Version 2.1.0.233 and onwards seem to break files with binary content #375

@potomato

Description

@potomato

I've been using SIAT in unit tests with mock files containing binary content for a while (and loving it).
Binary content used to be fine but a recent update is causing my units to fail because it seems now this content is attempting to be read as Unicode.

The following code works fine in v232, but throws exception in subsequent versions:
var binaryData = new byte[] { 0xC0 }; var fs = new MockFileSystem(new Dictionary<string, MockFileData>() { { @"c:\source\file.jpg", new MockFileData(binaryData) } } ); fs.AddDirectory(@"c:\source"); fs.AddDirectory(@"c:\dest"); fs.File.Copy(@"c:\source\file.jpg", @"c:\dest\file.jpg");

Is this expected behaviour? I can change my tests to ensure the binary content can be read as Unicode - but there's a MockFileData taking byte[], and it seems reasonable for a mock file system to be able to handle binary files. I can help knock up better tests if that would help.

Exception is:
System.Text.DecoderFallbackException
HResult=0x80070057
Message=Unable to translate bytes [C0] at index 0 from specified code page to Unicode.
Source=System.Private.CoreLib
StackTrace:
at System.Text.DecoderExceptionFallbackBuffer.Throw(Byte[] bytesUnknown, Int32 index)
at System.Text.DecoderExceptionFallbackBuffer.Fallback(Byte[] bytesUnknown, Int32 index)
at System.Text.DecoderFallbackBuffer.InternalFallback(Byte[] bytes, Byte* pBytes, Char*& chars)
at System.Text.UTF8Encoding.GetChars(Byte* bytes, Int32 byteCount, Char* chars, Int32 charCount, DecoderNLS baseDecoder)
at System.Text.DecoderNLS.GetChars(Byte[] bytes, Int32 byteIndex, Int32 byteCount, Char[] chars, Int32 charIndex, Boolean flush)
at System.Text.DecoderNLS.GetChars(Byte[] bytes, Int32 byteIndex, Int32 byteCount, Char[] chars, Int32 charIndex)
at System.IO.StreamReader.ReadBuffer()
at System.IO.StreamReader.ReadToEnd()
at System.IO.Abstractions.TestingHelpers.MockFile.ReadAllBytes(Byte[] contents, Encoding encoding)
at System.IO.Abstractions.TestingHelpers.MockFileData..ctor(MockFileData template)
at System.IO.Abstractions.TestingHelpers.MockFile.Copy(String sourceFileName, String destFileName, Boolean overwrite)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions