public void WriteShortStringThrowsWhenArgIsNull() { using (MemoryStream ms = new MemoryStream()) { using (BinaryWriterEx writer = new BinaryWriterEx(ms, true, true)) { Assert.ThrowsException <ArgumentNullException>(() => { writer.WriteShortString(null); }); //Make sure nothing was written to the stream Assert.AreEqual(0, ms.Length); } } }
public void WriteShortStringWorks(string value) { for (int i = 0; i < 2; i++) { bool littleEndian = i != 0; using (MemoryStream ms = new MemoryStream()) { using (BinaryWriterEx writer = new BinaryWriterEx(ms, true, littleEndian)) { writer.WriteShortString(value); ms.Position = 0; using (BinaryReaderEx reader = new BinaryReaderEx(ms, true, littleEndian)) { Assert.AreEqual(value, reader.ReadShortString()); } } } } }
public void WriteShortStringThrowsWhenThereAreTooManyBytes() { string tooLong = ""; Char append = '猫';//Takes 3 bytes in UTF-8 for (int i = 0; i < (UInt16.MaxValue / 3) + 1; i++) { tooLong += append; } using (MemoryStream ms = new MemoryStream()) { using (BinaryWriterEx writer = new BinaryWriterEx(ms, true, true)) { Assert.ThrowsException <ArgumentException>(() => { writer.WriteShortString(tooLong); }); //Make sure nothing was written to the stream Assert.AreEqual(0, ms.Length); } } }