public void WriteRawArgumentTest() { var fio = new Mock <IFileIO>(MockBehavior.Strict); FormattedWriter fw = new FormattedWriter(fio.Object); Executing.This(() => fw.WriteRaw(null)).Should().Throw <ArgumentNullException>(); }
public void WriteRawTest() { byte[] bytes = new byte[] {1, 3, 7, 8, 9}; var fio = new Mock<IFileIO>(MockBehavior.Strict); fio.Setup(io => io.WriteBytes(It.IsAny<byte[]>())); FormattedWriter fw = new FormattedWriter(fio.Object); fw.WriteRaw(bytes); fio.Verify(f => f.WriteBytes(It.Is<byte[]>(bs => bs.SequenceEqual(bytes))), Times.Once()); }
public void WriteRawTest() { byte[] bytes = new byte[] { 1, 3, 7, 8, 9 }; var fio = new Mock <IFileIO>(MockBehavior.Strict); fio.Setup(io => io.WriteBytes(It.IsAny <byte[]>())); FormattedWriter fw = new FormattedWriter(fio.Object); fw.WriteRaw(bytes); fio.Verify(f => f.WriteBytes(It.Is <byte[]>(bs => bs.SequenceEqual(bytes))), Times.Once()); }
/// <summary> /// Creates the header's sections from the descriptions found in the context. Computes their positions /// and sets the FirstItemPosition property in the context. /// </summary> internal byte[] CreateSections(WriteContext wc) { var saved = wc.Writer; using (var sectionStream = new MemoryStream()) // see noop-Dispose comment below { var sectionWriter = new FormattedWriter(new FileIO(sectionStream)); int pos = 32; // sections start at byte position 32 foreach (var formatter in this.sectionFormatters) { // payload using (var payloadStream = new MemoryStream()) // actually MemoryStream.Dispose() is a noop here, but for the code analysers pleasure we wrap these usings around { wc.Writer = new FormattedWriter(new FileIO(payloadStream)); formatter.Write(wc); var size = (int)payloadStream.Length; if (size > 0) { // section id sectionWriter.WriteInt32(formatter.Id); pos += 4; // nextSectionOffset sectionWriter.WriteInt32(size); pos += 4; // payload sectionWriter.WriteRaw(payloadStream.ToArray()); pos += size; // no padding or spacing done here wc.SectionCount++; } } } // padding int paddingBytes = (8 - pos % 8); if (paddingBytes == 8) paddingBytes = 0; sectionWriter.WriteRaw(new byte[paddingBytes]); wc.ItemAreaStart = pos + paddingBytes; // first item starts padded on 8 byte boundary. wc.Writer = saved; return sectionStream.ToArray(); } }
public void WriteRawArgumentTest() { var fio = new Mock<IFileIO>(MockBehavior.Strict); FormattedWriter fw = new FormattedWriter(fio.Object); Executing.This(() => fw.WriteRaw(null)).Should().Throw<ArgumentNullException>(); }