public void BadSection()
        {
            var badSectionFormatter = new Mock <ISectionFormatter>(MockBehavior.Strict);

            badSectionFormatter.Setup(sf => sf.Id).Returns(0x1000);
            badSectionFormatter.Setup(sf => sf.Read(It.IsAny <ReadContext>())).Callback((ReadContext rc) => rc.Reader.SkipBytes(16));
            HeaderManager hm = new HeaderManager();

            hm.AddSectionFormatter(badSectionFormatter.Object);

            var ms = new MemoryStream();
            var bw = new BinaryWriter(ms);

            bw.Write(0x0d0e0a0402080500);
            bw.Write(200L);
            bw.Write(0L);
            bw.Write(1L); // 1 section
            bw.Write(badSectionFormatter.Object.Id);
            bw.Write(2);

            20.Times(() => bw.Write(0L));

            ms.Position = 0;

            Executing.This(() => hm.ReadHeader(new FormattedReader(new FileIO(ms)))).Should().Throw <FileFormatException>()
            .Exception.Message.Should().Contain("Section read too many bytes");
        }
Exemplo n.º 2
0
        public void BadSection()
        {
            var badSectionFormatter = new Mock<ISectionFormatter>(MockBehavior.Strict);
            badSectionFormatter.Setup(sf => sf.Id).Returns(0x1000);
            badSectionFormatter.Setup(sf => sf.Read(It.IsAny<ReadContext>())).Callback((ReadContext rc) => rc.Reader.SkipBytes(16));
            HeaderManager hm = new HeaderManager();
            hm.AddSectionFormatter(badSectionFormatter.Object);

            var ms = new MemoryStream();
            var bw = new BinaryWriter(ms);
            bw.Write(0x0d0e0a0402080500);
            bw.Write(200L);
            bw.Write(0L);
            bw.Write(1L); // 1 section
            bw.Write(badSectionFormatter.Object.Id);
            bw.Write(2);

            20.Times(() => bw.Write(0L));

            ms.Position = 0;

            Executing.This(() => hm.ReadHeader(new FormattedReader(new FileIO(ms)))).Should().Throw<FileFormatException>()
                .Exception.Message.Should().Contain("Section read too many bytes");
        }