Example #1
0
        public object Read(PackStreamReader reader, long size)
        {
            var urn     = reader.ReadLong();
            var relType = reader.ReadString();
            var props   = reader.ReadMap();

            return(new Relationship(urn, -1, -1, relType, props));
        }
Example #2
0
            public void ShouldThrowExceptionIfMarkerByteNotString()
            {
                var mockInput = IOExtensions.CreateMockStream(PackStream.False);
                var reader    = new PackStreamReader(mockInput.Object, BoltReader.StructHandlers);

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

                ex.Should().BeOfType <ProtocolException>();
                mockInput.Verify(x => x.Read(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int>()), Times.Once);
            }
Example #3
0
            public void ShouldThrowExceptionWhenReadString32ReturnsStringSizeLonggerThanIntMax()
            {
                var mockInput = IOExtensions.CreateMockStream(PackStream.String32, PackStreamBitConverter.GetBytes((int)-1));
                var reader    = new PackStreamReader(mockInput.Object, BoltReader.StructHandlers);

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

                ex.Should().BeOfType <ProtocolException>();
                mockInput.Verify(x => x.Read(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int>()), Times.Exactly(2));
            }
Example #4
0
            public void ShouldReadString8()
            {
                var mockInput = IOExtensions.CreateMockStream(PackStream.String8, (byte)1, 0x61);
                var reader    = new PackStreamReader(mockInput.Object, BoltReader.StructHandlers);

                var real = reader.ReadString();

                real.Should().Be("a");
                mockInput.Verify(x => x.Read(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int>()), Times.Exactly(3));
            }
Example #5
0
            public void ShouldReadTinyStringAsEmptyString()
            {
                var mockInput = IOExtensions.CreateMockStream(PackStream.TinyString);
                var reader    = new PackStreamReader(mockInput.Object, BoltReader.StructHandlers);

                var real = reader.ReadString();

                real.Should().BeEmpty(); //.Equals(String.Empty);
                mockInput.Verify(x => x.Read(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int>()), Times.Once);
            }
Example #6
0
            public void ShouldReadString32()
            {
                var mockInput = IOExtensions.CreateMockStream(new byte[] { PackStream.String32 },
                                                              PackStreamBitConverter.GetBytes((int)1), new byte[] { 0x61 });
                var reader = new PackStreamReader(mockInput.Object, BoltReader.StructHandlers);

                var real = reader.ReadString();

                real.Should().Be("a");
                mockInput.Verify(x => x.Read(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int>()), Times.Exactly(3));
            }
        public object Read(PackStreamReader reader, long size)
        {
            var urn = reader.ReadLong();

            var numLabels = (int)reader.ReadListHeader();
            var labels    = new List <string>(numLabels);

            for (var i = 0; i < numLabels; i++)
            {
                labels.Add(reader.ReadString());
            }
            var numProps = (int)reader.ReadMapHeader();
            var props    = new Dictionary <string, object>(numProps);

            for (var j = 0; j < numProps; j++)
            {
                var key = reader.ReadString();
                props.Add(key, reader.Read());
            }

            return(new Node(urn, labels, props));
        }