public void ExecutingQueryMultipleTimesShouldResetParameters() { var client = Substitute.For<IRawGraphClient>(); client .ExecuteGetCypherResults<ReturnPropertyQueryResult>(Arg.Any<CypherQuery>()) .Returns(Enumerable.Empty<ReturnPropertyQueryResult>()); var cypher = new CypherFluentQuery(client); var query1 = cypher .Start("a", (NodeReference)1) .Return<object>("a.Name") .Query; Assert.AreEqual(1, query1.QueryParameters.Count()); Assert.AreEqual(1, query1.QueryParameters["p0"]); var query2 = cypher .Start("b", (NodeReference)2) .Return<object>("a.Name") .Query; Assert.AreEqual(1, query2.QueryParameters.Count()); Assert.AreEqual(2, query2.QueryParameters["p0"]); }
public void ExecutingQueryMultipleTimesShouldResetParameters() { var client = Substitute.For <IRawGraphClient>(); client .ExecuteGetCypherResults <ReturnPropertyQueryResult>(Arg.Any <CypherQuery>()) .Returns(Enumerable.Empty <ReturnPropertyQueryResult>()); var cypher = new CypherFluentQuery(client); var query1 = cypher .Start("a", (NodeReference)1) .Return <object>("a.Name") .Query; Assert.AreEqual(1, query1.QueryParameters.Count()); Assert.AreEqual(1, query1.QueryParameters["p0"]); var query2 = cypher .Start("b", (NodeReference)2) .Return <object>("a.Name") .Query; Assert.AreEqual(1, query2.QueryParameters.Count()); Assert.AreEqual(2, query2.QueryParameters["p0"]); }
public void ReturnColumnAlias() { // http://docs.neo4j.org/chunked/1.6/query-return.html#return-column-alias // START a=node(1) // RETURN a.Age AS SomethingTotallyDifferent var client = Substitute.For <IRawGraphClient>(); client .ExecuteGetCypherResults <ReturnPropertyQueryResult>(Arg.Any <CypherQuery>()) .Returns(Enumerable.Empty <ReturnPropertyQueryResult>()); var cypher = new CypherFluentQuery(client); var results = cypher .Start("a", (NodeReference)1) .Advanced.Return <ReturnPropertyQueryResult>(new ReturnExpression { ResultFormat = CypherResultFormat.DependsOnEnvironment, ResultMode = CypherResultMode.Projection, Text = "a.Age AS SomethingTotallyDifferent" }); Assert.Equal("START a=node(1)\r\nRETURN a.Age AS SomethingTotallyDifferent", results.Query.DebugQueryText); Assert.IsAssignableFrom <IEnumerable <ReturnPropertyQueryResult> >(results.Results); }
public void AddingStartBitsToDifferentQueriesShouldntCorruptEachOther() { var client = Substitute.For <IRawGraphClient>(); var cypher = new CypherFluentQuery(client); var query1 = cypher .Start("a", (NodeReference)1) .Query; var query2 = cypher .Start("b", (NodeReference)2) .Query; Assert.AreEqual("START a=node({p0})", query1.QueryText); Assert.AreEqual(1, query1.QueryParameters.Count); Assert.AreEqual(1, query1.QueryParameters["p0"]); Assert.AreEqual("START b=node({p0})", query2.QueryText); Assert.AreEqual(1, query2.QueryParameters.Count); Assert.AreEqual(2, query2.QueryParameters["p0"]); }
public void AddingStartBitsToDifferentQueriesShouldntCorruptEachOther() { var client = Substitute.For<IRawGraphClient>(); var cypher = new CypherFluentQuery(client); var query1 = cypher .Start("a", (NodeReference)1) .Query; var query2 = cypher .Start("b", (NodeReference)2) .Query; Assert.AreEqual("START a=node({p0})", query1.QueryText); Assert.AreEqual(1, query1.QueryParameters.Count); Assert.AreEqual(1, query1.QueryParameters["p0"]); Assert.AreEqual("START b=node({p0})", query2.QueryText); Assert.AreEqual(1, query2.QueryParameters.Count); Assert.AreEqual(2, query2.QueryParameters["p0"]); }
public void ReturnNodeAsSet() { var client = Substitute.For<IRawGraphClient>(); var set = new[] { new Node<FooNode>(new FooNode(), new NodeReference<FooNode>(123)) }; client .ExecuteGetCypherResults<Node<FooNode>>( Arg.Is<CypherQuery>(q => q.ResultMode == CypherResultMode.Set)) .Returns(set); var cypher = new CypherFluentQuery(client); var results = cypher .Start("a", (NodeReference)1) .Return<Node<FooNode>>("a") .Results; CollectionAssert.AreEqual(set, results); }
public void ReturnRelationshipWithDataAsSet() { var client = Substitute.For <IRawGraphClient>(); var set = new[] { new RelationshipInstance <FooNode>(new RelationshipReference <FooNode>(1), new NodeReference(0), new NodeReference(2), "Type", new FooNode()) }; client .ExecuteGetCypherResults <RelationshipInstance <FooNode> >( Arg.Is <CypherQuery>(q => q.ResultMode == CypherResultMode.Set)) .Returns(set); var cypher = new CypherFluentQuery(client); var results = cypher .Start("a", (RelationshipReference)1) .Return <RelationshipInstance <FooNode> >("a") .Results; CollectionAssert.AreEqual(set, results); }
public void ReturnNodeAsSet() { var client = Substitute.For <IRawGraphClient>(); var set = new[] { new Node <FooNode>(new FooNode(), new NodeReference <FooNode>(123)) }; client .ExecuteGetCypherResults <Node <FooNode> >( Arg.Is <CypherQuery>(q => q.ResultMode == CypherResultMode.Set)) .Returns(set); var cypher = new CypherFluentQuery(client); var results = cypher .Start("a", (NodeReference)1) .Return <Node <FooNode> >("a") .Results; CollectionAssert.AreEqual(set, results); }
public void ReturnColumnAliasOfTypeEnum() { // http://docs.neo4j.org/chunked/1.6/query-return.html#return-column-alias // START a=node(1) // RETURN a.Age AS SomethingTotallyDifferent var client = Substitute.For <IRawGraphClient>(); client .ExecuteGetCypherResults <ReturnPropertyQueryResult>(Arg.Any <CypherQuery>()) .Returns(Enumerable.Empty <ReturnPropertyQueryResult>()); var cypher = new CypherFluentQuery(client); var results = cypher .Start("a", (NodeReference)1) .Return(a => new FooNode { TheType = a.As <FooNode>().TheType, }) .Results; Assert.IsInstanceOf <IEnumerable <FooNode> >(results); }
public void ReturnColumnAlias() { // http://docs.neo4j.org/chunked/1.6/query-return.html#return-column-alias // START a=node(1) // RETURN a.Age AS SomethingTotallyDifferent var client = Substitute.For<IRawGraphClient>(); client .ExecuteGetCypherResults<ReturnPropertyQueryResult>(Arg.Any<CypherQuery>()) .Returns(Enumerable.Empty<ReturnPropertyQueryResult>()); var cypher = new CypherFluentQuery(client); var results = cypher .Start("a", (NodeReference)1) .Return(a => new ReturnPropertyQueryResult { SomethingTotallyDifferent = a.As<FooNode>().Age, }) .Results; Assert.IsInstanceOf<IEnumerable<ReturnPropertyQueryResult>>(results); }
public void ReturnColumnAlias() { // http://docs.neo4j.org/chunked/1.6/query-return.html#return-column-alias // START a=node(1) // RETURN a.Age AS SomethingTotallyDifferent var client = Substitute.For<IRawGraphClient>(); client .ExecuteGetCypherResults<ReturnPropertyQueryResult>(Arg.Any<CypherQuery>()) .Returns(Enumerable.Empty<ReturnPropertyQueryResult>()); var cypher = new CypherFluentQuery(client); var results = cypher .Start("a", (NodeReference) 1) .Advanced.Return<ReturnPropertyQueryResult>(new ReturnExpression { ResultFormat = CypherResultFormat.DependsOnEnvironment, ResultMode = CypherResultMode.Projection, Text = "a.Age AS SomethingTotallyDifferent" }); Assert.AreEqual("START a=node(1)\r\nRETURN a.Age AS SomethingTotallyDifferent", results.Query.DebugQueryText); Assert.IsInstanceOf<IEnumerable<ReturnPropertyQueryResult>>(results.Results); }
public void ReturnRelationshipWithDataAsSet() { var client = Substitute.For<IRawGraphClient>(); var set = new[] { new RelationshipInstance<FooNode>(new RelationshipReference<FooNode>(1), new NodeReference(0), new NodeReference(2),"Type", new FooNode()) }; client .ExecuteGetCypherResults<RelationshipInstance<FooNode>>( Arg.Is<CypherQuery>(q => q.ResultMode == CypherResultMode.Set)) .Returns(set); var cypher = new CypherFluentQuery(client); var results = cypher .Start("a", (RelationshipReference)1) .Return<RelationshipInstance<FooNode>>("a") .Results; CollectionAssert.AreEqual(set, results); }