Beispiel #1
0
            public void ShouldThrowExceptionIfMarkerByteNotStruct()
            {
                var mockInput = IOExtensions.CreateMockStream(PackStream.False);
                var reader    = new PackStreamReader(mockInput.Object, BoltReader.StructHandlers);

                var ex = Xunit.Record.Exception(() => reader.ReadStructHeader());

                ex.Should().BeOfType <ProtocolException>();
                mockInput.Verify(x => x.ReadByte(), Times.Once);
            }
Beispiel #2
0
            public void ShouldReadTinyStruct()
            {
                var mockInput = IOExtensions.CreateMockStream(0xB2);
                var reader    = new PackStreamReader(mockInput.Object, BoltReader.StructHandlers);

                var header = reader.ReadStructHeader();

                header.Should().Be(2);
                mockInput.Verify(x => x.ReadByte(), Times.Once);
            }
Beispiel #3
0
            public void ShouldReadStruct16()
            {
                var mockInput = IOExtensions.CreateMockStream(PackStream.Struct16, PackStreamBitConverter.GetBytes((short)1));
                var reader    = new PackStreamReader(mockInput.Object, BoltReader.StructHandlers);

                var header = reader.ReadStructHeader();

                header.Should().Be(1);
                mockInput.Verify(x => x.ReadByte(), Times.Once);
                mockInput.Verify(x => x.Read(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int>()), Times.Once);
            }
Beispiel #4
0
            public void ShouldReadEmptyStruct16Correctly()
            {
                var mockInput =
                    IOExtensions.CreateMockStream("DD 00 00 01".ToByteArray());
                var reader = new PackStreamReader(mockInput.Object, BoltReader.StructHandlers);

                var header    = reader.ReadStructHeader();
                var signature = reader.ReadStructSignature();
                var fields    = new List <object>();

                for (var i = 0; i < header; i++)
                {
                    fields.Add(reader.Read());
                }

                signature.Should().Be(0x01);
                fields.Count.Should().Be(0);
            }
Beispiel #5
0
            public void ShouldReadTinyStructCorrectly()
            {
                var mockInput =
                    IOExtensions.CreateMockStream("B3 01 01 02 03".ToByteArray());
                var reader = new PackStreamReader(mockInput.Object, BoltReader.StructHandlers);

                var header    = reader.ReadStructHeader();
                var signature = reader.ReadStructSignature();
                var fields    = new List <object>();

                for (var i = 0; i < header; i++)
                {
                    fields.Add(reader.Read());
                }

                signature.Should().Be(0x01);
                fields.Count.Should().Be(3);
                fields.Should().Contain(1L);
                fields.Should().Contain(2L);
                fields.Should().Contain(3L);
            }