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); } }
public void DetermineRelationshipDirectionShouldThrowExceptionWhenBothNodesAreValidAsSourceAndTargetNodes() { var baseNodeType = typeof(Bar); var relationship = new TestRelationship(new NodeReference <Bar>(123)); Assert.That(() => Relationship.DetermineRelationshipDirection(baseNodeType, relationship), Throws.TypeOf <AmbiguousRelationshipDirectionException>()); }
public void DetermineRelationshipDirectionShouldThrowExceptionWhenNeitherNodeIsValidAtEitherEnd() { var baseNodeType = typeof(Zip); var relationship = new TestRelationship(new NodeReference <Qak>(123)); Assert.That(() => Relationship.DetermineRelationshipDirection(baseNodeType, relationship), Throws.TypeOf <AmbiguousRelationshipDirectionException>()); }
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>()); }
public void DetermineRelationshipDirectionShouldThrowExceptionWhenBothNodesAreValidAsSourceAndTargetNodes() { var baseNodeType = typeof(Bar); var relationship = new TestRelationship(new NodeReference <Bar>(123)); Relationship.DetermineRelationshipDirection(baseNodeType, relationship); }
public void DetermineRelationshipDirectionShouldThrowExceptionWhenNeitherNodeIsValidAtEitherEnd() { var baseNodeType = typeof(Zip); var relationship = new TestRelationship(new NodeReference <Qak>(123)); Relationship.DetermineRelationshipDirection(baseNodeType, relationship); }
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); }
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); }
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); }
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); }
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); }