-
Notifications
You must be signed in to change notification settings - Fork 267
Description
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)