public void ShouldUnpackZeroLenghPathCorrectly()
                    {
                        // A
                        var bytes =
                            "00 2C B3 50 91 B3 4E C9 03 E9    92 86 50 65 72 73 6F 6E    88 45 6D 70 6C 6F 79 65    65 A2 84 6E 61 6D 65 85 41 6C 69 63 65 83 61 67    65 21 90 90 00 00"
                            .ToByteArray();
                        var mockTcpSocketClient = new Mock <ITcpSocketClient>();

                        SetupClientReadStream(mockTcpSocketClient, bytes);

                        PackStreamMessageFormatV1.ReaderV1 reader = (PackStreamMessageFormatV1.ReaderV1)
                                                                    new PackStreamMessageFormatV1(mockTcpSocketClient.Object, null).Reader;
                        var   path = reader.UnpackValue();
                        IPath p    = path as IPath;

                        p.Should().NotBeNull();

                        p.Start.Should().NotBeNull();
                        p.End.Should().NotBeNull();
                        p.Start.Equals(TestNodes.Alice).Should().BeTrue();
                        p.End.Equals(TestNodes.Alice).Should().BeTrue();

                        p.Nodes.Should().HaveCount(1);
                        p.Relationships.Should().HaveCount(0);
                    }
                    public void ShouldUnpackPathWithLenghOneCorrectly()
                    {
                        // A->B
                        var bytes =
                            "00 66 B3 50 92 B3 4E C9 03 E9    92 86 50 65 72 73 6F 6E    88 45 6D 70 6C 6F 79 65    65 A2 84 6E 61 6D 65 85 41 6C 69 63 65 83 61 67    65 21 B3 4E C9 03 EA 92    86 50 65 72 73 6F 6E 88    45 6D 70 6C 6F 79 65 65 A2 84 6E 61 6D 65 83 42    6F 62 83 61 67 65 2C 91    B3 72 0C 85 4B 4E 4F 57    53 A1 85 73 69 6E 63 65 C9 07 CF 92 01 01 00 00"
                            .ToByteArray();
                        var mockTcpSocketClient = new Mock <ITcpSocketClient>();

                        SetupClientReadStream(mockTcpSocketClient, bytes);

                        PackStreamMessageFormatV1.ReaderV1 reader = (PackStreamMessageFormatV1.ReaderV1)
                                                                    new PackStreamMessageFormatV1(mockTcpSocketClient.Object, null).Reader;
                        var   path = reader.UnpackValue();
                        IPath p    = path as IPath;

                        p.Should().NotBeNull();

                        p.Nodes.Should().HaveCount(2);
                        p.Relationships.Should().HaveCount(1);

                        p.Start.Should().NotBeNull();
                        p.End.Should().NotBeNull();
                        p.Start.Equals(TestNodes.Alice).Should().BeTrue();
                        p.End.Equals(TestNodes.Bob).Should().BeTrue();

                        p.Relationships[0].Equals(TestRelationships.AliceKnowsBob).Should().BeTrue();
                    }
                public void ShouldPackBytes()
                {
                    var inputStreamMock = new Mock <IChunkedInputStream>();

                    inputStreamMock.SetupSequence(x => x.ReadByte()).Returns(PackStream.BYTES_8).Returns((byte)0x00);
                    var reader = new PackStreamMessageFormatV1.ReaderV1(inputStreamMock.Object);

                    var unpackValue = reader.UnpackValue(PackStream.PackType.Bytes).ValueAs <byte[]>();

                    unpackValue.Length.Should().Be(0);
                }
Esempio n. 4
0
                    public void ShouldUnpackPathWithRelTraversedMulTimesInSameDirectionCorrectly()
                    {
                        // A->C->B<-A->C->D
                        var bytes =
                            "00 BE B35094B34EC903E99286506572736F6E88456D706C6F796565A2846E616D6585416C6963658361676521B34EC903EB9186506572736F6EA1846E616D65854361726F6CB34EC903EA9286506572736F6E88456D706C6F796565A2846E616D6583426F62836167652CB34EC903EC90A1846E616D65844461766594B3720D854C494B4553A0B37220884449534C494B4553A0B3720C854B4E4F5753A18573696E6365C907CFB372228A4D4152524945445F544FA09A01010202FD0001010403 00 00"
                            .ToByteArray();
                        var mockTcpSocketClient = new Mock <ITcpSocketClient>();

                        TestHelper.TcpSocketClientSetup.SetupClientReadStream(mockTcpSocketClient, bytes);

                        PackStreamMessageFormatV1.ReaderV1 reader = (PackStreamMessageFormatV1.ReaderV1)
                                                                    new PackStreamMessageFormatV1(mockTcpSocketClient.Object, new BigEndianTargetBitConverter(),
                                                                                                  null)
                                                                    .Reader;
                        var   path = reader.UnpackValue();
                        IPath p    = path as IPath;

                        p.Should().NotBeNull();

                        p.Nodes.Should().HaveCount(6);
                        p.Relationships.Should().HaveCount(5);

                        p.Start.Should().NotBeNull();
                        p.End.Should().NotBeNull();
                        p.Start.Equals(TestNodes.Alice).Should().BeTrue();
                        p.End.Equals(TestNodes.Dave).Should().BeTrue($"Got {p.End.Id}");

                        List <INode> correctOrder = new List <INode>
                        {
                            TestNodes.Alice,
                            TestNodes.Carol,
                            TestNodes.Bob,
                            TestNodes.Alice,
                            TestNodes.Carol,
                            TestNodes.Dave
                        };

                        p.Nodes.Should().ContainInOrder(correctOrder);

                        List <IRelationship> expectedRelOrder = new List <IRelationship>
                        {
                            TestRelationships.AliceLikesCarol,
                            TestRelationships.CarolDislikesBob,
                            TestRelationships.AliceKnowsBob,
                            TestRelationships.AliceLikesCarol,
                            TestRelationships.CarolMarriedToDave
                        };

                        p.Relationships.Should().ContainInOrder(expectedRelOrder);
                        p.Relationships[0].Equals(TestRelationships.AliceLikesCarol).Should().BeTrue();
                    }
                    public void ShouldUnpackPathWithNodeVisitedMulTimesCorrectly()
                    {
                        // A->B<-A->C->B<-C
                        var bytes =
                            "00 9E B35093B34EC903E99286506572736F6E88456D706C6F796565A2846E616D6585416C6963658361676521B34EC903EA9286506572736F6E88456D706C6F796565A2846E616D6583426F62836167652CB34EC903EB9186506572736F6EA1846E616D65854361726F6C93B3720C854B4E4F5753A18573696E6365C907CFB3720D854C494B4553A0B37220884449534C494B4553A09A0101FF0002020301FD02 00 00"
                            .ToByteArray();
                        var mockTcpSocketClient = new Mock <ITcpSocketClient>();

                        SetupClientReadStream(mockTcpSocketClient, bytes);

                        PackStreamMessageFormatV1.ReaderV1 reader = (PackStreamMessageFormatV1.ReaderV1)
                                                                    new PackStreamMessageFormatV1(mockTcpSocketClient.Object, null).Reader;
                        var   path = reader.UnpackValue();
                        IPath p    = path as IPath;

                        p.Should().NotBeNull();

                        p.Nodes.Should().HaveCount(6);
                        p.Relationships.Should().HaveCount(5);

                        p.Start.Should().NotBeNull();
                        p.End.Should().NotBeNull();
                        p.Start.Equals(TestNodes.Alice).Should().BeTrue();
                        p.End.Equals(TestNodes.Carol).Should().BeTrue($"Got {p.End.Id}");

                        List <INode> correctOrder = new List <INode>
                        {
                            TestNodes.Alice,
                            TestNodes.Bob,
                            TestNodes.Alice,
                            TestNodes.Carol,
                            TestNodes.Bob,
                            TestNodes.Carol
                        };

                        p.Nodes.Should().ContainInOrder(correctOrder);

                        List <IRelationship> expectedRelOrder = new List <IRelationship>
                        {
                            TestRelationships.AliceKnowsBob,
                            TestRelationships.AliceKnowsBob,
                            TestRelationships.AliceLikesCarol,
                            TestRelationships.CarolDislikesBob,
                            TestRelationships.CarolDislikesBob
                        };

                        p.Relationships.Should().ContainInOrder(expectedRelOrder);
                        p.Relationships[0].Equals(TestRelationships.AliceKnowsBob).Should().BeTrue();
                    }
Esempio n. 6
0
                    public void ShouldUnpackPathWithLoopCorrectly()
                    {
                        // C->D->D
                        var bytes =
                            "00 50 B35092B34EC903EB9186506572736F6EA1846E616D65854361726F6CB34EC903EC90A1846E616D65844461766592B372228A4D4152524945445F544FA0B3722C89574F524B535F464F52A09401010201 00 00"
                            .ToByteArray();
                        var mockTcpSocketClient = new Mock <ITcpSocketClient>();

                        TestHelper.TcpSocketClientSetup.SetupClientReadStream(mockTcpSocketClient, bytes);

                        PackStreamMessageFormatV1.ReaderV1 reader = (PackStreamMessageFormatV1.ReaderV1)
                                                                    new PackStreamMessageFormatV1(mockTcpSocketClient.Object, new BigEndianTargetBitConverter(),
                                                                                                  null)
                                                                    .Reader;
                        var   path = reader.UnpackValue();
                        IPath p    = path as IPath;

                        p.Should().NotBeNull();

                        p.Nodes.Should().HaveCount(3);
                        p.Relationships.Should().HaveCount(2);

                        p.Start.Should().NotBeNull();
                        p.End.Should().NotBeNull();
                        p.Start.Equals(TestNodes.Carol).Should().BeTrue();
                        p.End.Equals(TestNodes.Dave).Should().BeTrue($"Got {p.End.Id}");

                        List <INode> correctOrder = new List <INode>
                        {
                            TestNodes.Carol,
                            TestNodes.Dave,
                            TestNodes.Dave
                        };

                        p.Nodes.Should().ContainInOrder(correctOrder);

                        List <IRelationship> expectedRelOrder = new List <IRelationship>
                        {
                            TestRelationships.CarolMarriedToDave,
                            TestRelationships.DaveWorksForDave,
                        };

                        p.Relationships.Should().ContainInOrder(expectedRelOrder);
                        p.Relationships[0].Equals(TestRelationships.CarolMarriedToDave).Should().BeTrue();
                    }
                    public void ShouldUnpackNodeCorrectly()
                    {
                        var bytes = "00 06 B3 4E 01 90 A0 00 00".ToByteArray();
                        var mockTcpSocketClient = new Mock <ITcpSocketClient>();

                        SetupClientReadStream(mockTcpSocketClient, bytes);

                        PackStreamMessageFormatV1.ReaderV1 reader = (PackStreamMessageFormatV1.ReaderV1)
                                                                    new PackStreamMessageFormatV1(mockTcpSocketClient.Object, null).Reader;
                        var   node = reader.UnpackValue();
                        INode n    = node as INode;

                        n.Should().NotBeNull();

                        n.Id.Should().Be(1);
                        n.Properties.Should().BeEmpty();
                        n.Labels.Should().BeEmpty();
                    }
                    public void ShouldUnpackRelationshipCorrectly()
                    {
                        var bytes = "00 07 B5 52 01 02 03 80 a0 00 00".ToByteArray();
                        var mockTcpSocketClient = new Mock <ITcpSocketClient>();

                        SetupClientReadStream(mockTcpSocketClient, bytes);

                        PackStreamMessageFormatV1.ReaderV1 reader = (PackStreamMessageFormatV1.ReaderV1)
                                                                    new PackStreamMessageFormatV1(mockTcpSocketClient.Object, null).Reader;
                        var           real = reader.UnpackValue();
                        IRelationship rel  = real as IRelationship;

                        rel.Should().NotBeNull();

                        rel.Id.Should().Be(1);
                        rel.StartNodeId.Should().Be(2);
                        rel.EndNodeId.Should().Be(3);
                        rel.Type.Should().BeEmpty();
                        rel.Properties.Should().BeEmpty();
                    }
                private void UnpackNumCorrectly(long expected, byte[] data)
                {
                    var mockTcpSocketClient = new Mock <ITcpSocketClient>();

                    List <byte> bytes = new List <byte>
                    {
                        0x00,
                        (byte)data.Length
                    };

                    bytes.AddRange(data);

                    SetupClientReadStream(mockTcpSocketClient, bytes.ToArray());

                    PackStreamMessageFormatV1.ReaderV1 reader = (PackStreamMessageFormatV1.ReaderV1)
                                                                new PackStreamMessageFormatV1(mockTcpSocketClient.Object, null).Reader;
                    var real = reader.UnpackValue();

                    Assert.Equal(expected, real);
                }
                    public void ShouldUnpackPathWithLenghTwoCorrectly()
                    {
                        // A->C->D
                        var bytes =
                            "00 73 B35093B34EC903E99286506572736F6E88456D706C6F796565A2846E616D6585416C6963658361676521B34EC903EB9186506572736F6EA1846E616D65854361726F6CB34EC903EC90A1846E616D65844461766592B3720D854C494B4553A0B372228A4D4152524945445F544FA09401010202 00 00"
                            .ToByteArray();
                        var mockTcpSocketClient = new Mock <ITcpSocketClient>();

                        SetupClientReadStream(mockTcpSocketClient, bytes);

                        PackStreamMessageFormatV1.ReaderV1 reader = (PackStreamMessageFormatV1.ReaderV1)
                                                                    new PackStreamMessageFormatV1(mockTcpSocketClient.Object, null)
                                                                    .Reader;
                        var   path = reader.UnpackValue();
                        IPath p    = path as IPath;

                        p.Should().NotBeNull();

                        p.Nodes.Should().HaveCount(3);
                        p.Relationships.Should().HaveCount(2);

                        p.Start.Should().NotBeNull();
                        p.End.Should().NotBeNull();
                        p.Start.Equals(TestNodes.Alice).Should().BeTrue();
                        p.End.Equals(TestNodes.Dave).Should().BeTrue($"Got {p.End.Id}");

                        List <INode> correctOrder = new List <INode> {
                            TestNodes.Alice, TestNodes.Carol, TestNodes.Dave
                        };

                        p.Nodes.Should().ContainInOrder(correctOrder);

                        p.Relationships[0].Equals(TestRelationships.AliceLikesCarol).Should().BeTrue();
                        List <IRelationship> expectedRelOrder = new List <IRelationship>
                        {
                            TestRelationships.AliceLikesCarol,
                            TestRelationships.CarolMarriedToDave
                        };

                        p.Relationships.Should().ContainInOrder(expectedRelOrder);
                    }
                    public void ShouldUnpackPathCorrectly()
                    {
                        var bytes = "00 0A B3 50 91 B3 4E 01 90 A0 90 90 A0 00 00".ToByteArray();
                        var mockTcpSocketClient = new Mock <ITcpSocketClient>();

                        SetupClientReadStream(mockTcpSocketClient, bytes);

                        PackStreamMessageFormatV1.ReaderV1 reader = (PackStreamMessageFormatV1.ReaderV1)
                                                                    new PackStreamMessageFormatV1(mockTcpSocketClient.Object, null).Reader;
                        var   path = reader.UnpackValue();
                        IPath p    = path as IPath;

                        p.Should().NotBeNull();

                        p.Start.Should().NotBeNull();
                        p.End.Should().NotBeNull();
                        p.Start.Id.Should().Be(1);
                        p.Start.Properties.Should().BeEmpty();
                        p.Start.Labels.Should().BeEmpty();
                        p.Nodes.Should().HaveCount(1);
                        p.Relationships.Should().HaveCount(0);
                    }