public void ShouldReturnAttachedRelationshipReference()
        {
            using (var testHarness = new RestTestHarness
            {
                {
                    MockRequest.PostJson("/node/81/relationships",
                                         @"{
                            'to': 'http://foo/db/data/node/81',
                            'type': 'TEST_RELATIONSHIP'
                        }"),
                    MockResponse.Json(HttpStatusCode.Created,
                                      @"{
                            'extensions' : {
                            },
                            'start' : 'http://foo/db/data/node/81',
                            'property' : 'http://foo/db/data/relationship/38/properties/{key}',
                            'self' : 'http://foo/db/data/relationship/38',
                            'properties' : 'http://foo/db/data/relationship/38/properties',
                            'type' : 'TEST_RELATIONSHIP',
                            'end' : 'http://foo/db/data/node/80',
                            'data' : {
                            }
                        }")
                }
            })
            {
                var graphClient = testHarness.CreateAndConnectGraphClient();

                var testRelationship      = new TestRelationship(81);
                var relationshipReference = graphClient.CreateRelationship(new NodeReference <TestNode>(81), testRelationship);

                Assert.AreEqual(graphClient, ((IAttachedReference)relationshipReference).Client);
            }
        }
예제 #2
0
        public void DetermineRelationshipDirectionShouldThrowExceptionWhenBothNodesAreValidAsSourceAndTargetNodes()
        {
            var baseNodeType = typeof(Bar);
            var relationship = new TestRelationship(new NodeReference <Bar>(123));

            Assert.That(() => Relationship.DetermineRelationshipDirection(baseNodeType, relationship), Throws.TypeOf <AmbiguousRelationshipDirectionException>());
        }
예제 #3
0
        public void DetermineRelationshipDirectionShouldThrowExceptionWhenNeitherNodeIsValidAtEitherEnd()
        {
            var baseNodeType = typeof(Zip);
            var relationship = new TestRelationship(new NodeReference <Qak>(123));

            Assert.That(() => Relationship.DetermineRelationshipDirection(baseNodeType, relationship), Throws.TypeOf <AmbiguousRelationshipDirectionException>());
        }
예제 #4
0
        public void DetermineRelationshipDirectionShouldReturnIncomingWhenBaseNodeOnlyValidAsTargetAndSourceNodeNotDefinedAsEither()
        {
            var baseNodeType = typeof(Baz);
            var relationship = new TestRelationship(new NodeReference <Qak>(123));

            Assert.That(() => Assert.AreEqual(RelationshipDirection.Incoming, Relationship.DetermineRelationshipDirection(baseNodeType, relationship)), Throws.TypeOf <AmbiguousRelationshipDirectionException>());
        }
예제 #5
0
        public void DetermineRelationshipDirectionShouldThrowExceptionWhenBothNodesAreValidAsSourceAndTargetNodes()
        {
            var baseNodeType = typeof(Bar);
            var relationship = new TestRelationship(new NodeReference <Bar>(123));

            Relationship.DetermineRelationshipDirection(baseNodeType, relationship);
        }
예제 #6
0
        public void DetermineRelationshipDirectionShouldThrowExceptionWhenNeitherNodeIsValidAtEitherEnd()
        {
            var baseNodeType = typeof(Zip);
            var relationship = new TestRelationship(new NodeReference <Qak>(123));

            Relationship.DetermineRelationshipDirection(baseNodeType, relationship);
        }
예제 #7
0
        public void DetermineRelationshipDirectionShouldReturnIncomingWhenBaseNodeIsOnlyValidAsATargetNodeEvenIfOtherNodeIsAlsoValidAsATargetNode()
        {
            var baseNodeType        = typeof(Baz);
            var relationship        = new TestRelationship(new NodeReference <Bar>(123));
            var calculatedDirection = Relationship.DetermineRelationshipDirection(baseNodeType, relationship);

            Assert.AreEqual(RelationshipDirection.Incoming, calculatedDirection);
        }
예제 #8
0
        public void DetermineRelationshipDirectionShouldReturnOutgoingWhenBaseNodeIsOnlyValidAsASourceNodeAndOtherNodeIsOnlyValidAsATargetNode()
        {
            var baseNodeType        = typeof(Foo);
            var relationship        = new TestRelationship(new NodeReference <Baz>(123));
            var calculatedDirection = Relationship.DetermineRelationshipDirection(baseNodeType, relationship);

            Assert.AreEqual(RelationshipDirection.Outgoing, calculatedDirection);
        }
예제 #9
0
        public void DetermineRelationshipDirectionShouldReturnOutgoingWhenBaseNodeIsValidAsASourceNodeAndOtherNodeIsAnUntypedReference()
        {
            var baseNodeType        = typeof(Bar);
            var relationship        = new TestRelationship(new NodeReference(123));
            var calculatedDirection = Relationship.DetermineRelationshipDirection(baseNodeType, relationship);

            Assert.Equal(RelationshipDirection.Outgoing, calculatedDirection);
        }
예제 #10
0
        public void DetermineRelationshipDirectionShouldReturnExplicitDirection(RelationshipDirection direction)
        {
            // Arrange
            var relationship = new TestRelationship(new NodeReference(0))
            {
                Direction = direction
            };
            var calculatedDirection = Relationship.DetermineRelationshipDirection(null, relationship);

            Assert.AreEqual(direction, calculatedDirection);
        }
예제 #11
0
            public void DeserilizesProjectedListCorrectly()
            {
                var expectedContent = "{ \"columns\":[\"a\",\"b\"], \"data\":[[ {\"data\":{ \"Value\":\"foo\" }},[{\"nested_b1\":{\"data\":{ \"Value\":\"bar\" }}},{\"nested_b2\":{\"data\":{ \"Value\":\"foobar\" }}}] ]] }";

                var nodeA = new TestNode(new Dictionary <string, object> {
                    { "Value", "foo" }
                });
                var nodeB1 = new TestRelationship(new Dictionary <string, object> {
                    { "Value", "bar" }
                });
                var nodeB2 = new TestNode(new Dictionary <string, object> {
                    { "Value", "foobar" }
                });

                var listB = new List <object>
                {
                    new Dictionary <string, object> {
                        { "nested_b1", nodeB1 }
                    },
                    new Dictionary <string, object> {
                        { "nested_b2", nodeB2 }
                    }
                };

                var record = Substitute.For <IRecord>();

                record.Keys.Returns(new List <string> {
                    "a", "b"
                });
                record["a"].Returns(nodeA);
                record["b"].Returns(listB);

                var mockDeserializer = new Mock <ICypherJsonDeserializer <DerivedClass> >();

                mockDeserializer
                .Setup(d => d.Deserialize(It.IsAny <string>()))
                .Returns(new List <DerivedClass>());

                record.Deserialize(mockDeserializer.Object, CypherResultMode.Projection);
                mockDeserializer.Verify(d => d.Deserialize(expectedContent), Times.Once);
            }
            public void DeserializesProjectedSetCorrectly()
            {
                var expectedContent = "{ \"columns\":[\"a\"], \"data\":[[ { \"b\":[{\"c\":[\"d\"]},{\"e\":[\"f\"]}],\"g\":42 } ]] }";

                var relation1 = new TestRelationship(new Dictionary <string, object> {
                    { "c", new List <object> {
                          "d"
                      } }
                });
                var relation2 = new TestRelationship(new Dictionary <string, object> {
                    { "e", new List <object> {
                          "f"
                      } }
                });
                var nodeA = new Dictionary <string, object>
                {
                    { "b", new List <IRelationship> {
                          relation1, relation2
                      } },
                    { "g", 42 }
                };

                var record = Substitute.For <IRecord>();

                record.Keys.Returns(new List <string> {
                    "a"
                });
                record["a"].Returns(nodeA);

                var mockDeserializer = new Mock <ICypherJsonDeserializer <DerivedClass> >();

                mockDeserializer
                .Setup(d => d.Deserialize(It.IsAny <string>(), false))
                .Returns(new List <DerivedClass>());

                record.Deserialize(mockDeserializer.Object, CypherResultMode.Projection);
                mockDeserializer.Verify(d => d.Deserialize(expectedContent, false), Times.Once);
            }