// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // namespace ImageSharp.Tests.IO { using System; using System.IO; using System.Text; using ImageSharp.IO; using Xunit; /// /// The endian binary reader tests. /// public class EndianBinaryReaderTests { /// /// The test string. /// private const string TestString = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmopqrstuvwxyz"; /// /// The test bytes. /// private static readonly byte[] TestBytes = Encoding.ASCII.GetBytes(TestString); /// /// Tests to ensure that the reader can read beyond internal buffer size. /// [Fact] public void ReadCharsBeyondInternalBufferSize() { MemoryStream stream = new MemoryStream(TestBytes); using (EndianBinaryReader subject = new EndianBinaryReader(Endianness.LittleEndian, stream)) { char[] chars = new char[TestString.Length]; subject.Read(chars, 0, chars.Length); Assert.Equal(TestString, new string(chars)); } } /// /// Tests to ensure that the reader cannot read beyond the provided buffer size. /// [Fact] public void ReadCharsBeyondProvidedBufferSize() { Assert.Throws( typeof(ArgumentException), () => { MemoryStream stream = new MemoryStream(TestBytes); using (EndianBinaryReader subject = new EndianBinaryReader(Endianness.LittleEndian, stream)) { char[] chars = new char[TestString.Length - 1]; subject.Read(chars, 0, TestString.Length); } }); } } }