Skip to content

Commit

Permalink
Uses $ for parameters instead of {}
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Skardon committed Jun 17, 2020
1 parent fd143f8 commit 47c9a3b
Show file tree
Hide file tree
Showing 26 changed files with 189 additions and 188 deletions.
2 changes: 1 addition & 1 deletion Neo4jClient.FSharp.Tests/CypherFluentQueryTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module Neo4jClient.Tests.Cypher.Where
cfq
.Where(fun u -> u.Count = 1000).Query
Assert.NotNull query
Assert.Equal(query.QueryText, "WHERE (u.Count = {p0})")
Assert.Equal(query.QueryText, "WHERE (u.Count = $p0)")
Assert.Equal(query.QueryParameters.["p0"], 1000)

[<Fact>]
Expand Down
6 changes: 3 additions & 3 deletions Neo4jClient.Shared/Cypher/QueryWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ public CypherQuery ToCypherQuery(IContractResolver contractResolver = null, bool

public string CreateParameter(object paramValue)
{
var paramName = string.Format("p{0}", queryParameters.Count);
var paramName = $"p{queryParameters.Count}";
queryParameters.Add(paramName, paramValue);
return "{" + paramName + "}";
return $"${paramName}";
}

public void CreateParameter(string key, object value)
Expand Down Expand Up @@ -162,7 +162,7 @@ string CreateParameterAndReturnPlaceholder(object paramValue)
{
var paramName = string.Format("p{0}", queryParameters.Count);
queryParameters.Add(paramName, paramValue);
return "{" + paramName + "}";
return $"${paramName}";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ public void ShouldDeserializeCollectionsWithAnonymousReturn()
public void ShouldDeserializePathsResultAsSetBased()
{
// Arrange
const string queryText = @"MATCH (start:Node {Id:{p0}}),(end:Node {Id: {p1}}), p = shortestPath((start)-[*..5]->(end)) RETURN p";
const string queryText = @"MATCH (start:Node {Id:$p0}),(end:Node {Id: $p1}), p = shortestPath((start)-[*..5]->(end)) RETURN p";

var parameters = new Dictionary<string, object>
{
Expand Down Expand Up @@ -652,7 +652,7 @@ public void ShouldDeserializePathsResultAsSetBased()
// {
// // Arrange
// const string queryText = @"
// START x = node({p0})
// START x = node($p0)
// MATCH x-[r]->n
// RETURN type(r) AS RelationshipType, n.Name? AS Name, n.UniqueId? AS UniqueId
// LIMIT 3";
Expand Down Expand Up @@ -865,7 +865,7 @@ public void ShouldDeserializePathsResultAsSetBased()
// {
// // Arrange
// const string queryText = @"
// START x = node({p0})
// START x = node($p0)
// MATCH x-[r]->n
// RETURN x AS Fooness, type(r) AS RelationshipType, n.Name? AS Name, n.UniqueId? AS UniqueId
// LIMIT 3";
Expand Down Expand Up @@ -990,7 +990,7 @@ public void ShouldDeserializePathsResultAsSetBased()
// {
// // Arrange
// const string queryText = @"
// START x = node({p0})
// START x = node($p0)
// MATCH x-[r]->n
// RETURN x AS Fooness, type(r) AS RelationshipType, n.Name? AS Name, n.UniqueId? AS UniqueId
// LIMIT 3";
Expand Down Expand Up @@ -1112,7 +1112,7 @@ public void ShouldDeserializePathsResultAsSetBased()
// {
// // Arrange
// const string queryText = @"
// START x = node({p0})
// START x = node($p0)
// MATCH x-[r]->n
// RETURN x AS Fooness, type(r) AS RelationshipType, n.Name? AS Name, n.UniqueId? AS UniqueId
// LIMIT 3";
Expand Down Expand Up @@ -1268,7 +1268,7 @@ public void ShouldDeserializePathsResultAsSetBased()
// {
// const int expectedMaxExecutionTime = 100;
//
// const string queryText = @"START d=node({p0}), e=node({p1})
// const string queryText = @"START d=node($p0), e=node($p1)
// MATCH p = allShortestPaths( d-[*..15]-e )
// RETURN p";
//
Expand Down Expand Up @@ -1327,7 +1327,7 @@ public void ShouldDeserializePathsResultAsSetBased()
// [Fact]
// public void DoesntSendMaxExecutionTime_WhenNotAddedToQuery()
// {
// const string queryText = @"START d=node({p0}), e=node({p1})
// const string queryText = @"START d=node($p0), e=node($p1)
// MATCH p = allShortestPaths( d-[*..15]-e )
// RETURN p";
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void CreateNodeWithValuesViaCreateUnique()
.Return<object>("leaf")
.Query;

Assert.Equal("START root=node({p0})\r\nCREATE UNIQUE root-[:X]-(leaf {name:'D'} )\r\nRETURN leaf", query.QueryText);
Assert.Equal("START root=node($p0)\r\nCREATE UNIQUE root-[:X]-(leaf {name:'D'} )\r\nRETURN leaf", query.QueryText);
Assert.Equal(2l, query.QueryParameters["p0"]);
}

Expand All @@ -45,7 +45,7 @@ public void CreateNodeWithValuesViaCreateUniqueAfterMatch()
.Return<object>("leaf")
.Query;

Assert.Equal("START root=node({p0})\r\nMATCH root-[:X]-foo\r\nCREATE UNIQUE foo-[:Y]-(leaf {name:'D'} )\r\nRETURN leaf", query.QueryText);
Assert.Equal("START root=node($p0)\r\nMATCH root-[:X]-foo\r\nCREATE UNIQUE foo-[:Y]-(leaf {name:'D'} )\r\nRETURN leaf", query.QueryText);
Assert.Equal(2l, query.QueryParameters["p0"]);
}
}
Expand Down
10 changes: 5 additions & 5 deletions Neo4jClient.Tests.Shared/Cypher/CypherFluentQueryDeleteTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void DeleteMatchedIdentifier()
.Delete("n, r")
.Query;

Assert.Equal("START n=node({p0})\r\nMATCH n-[r]-()\r\nDELETE n, r", query.QueryText);
Assert.Equal("START n=node($p0)\r\nMATCH n-[r]-()\r\nDELETE n, r", query.QueryText);
Assert.Equal(3L, query.QueryParameters["p0"]);
}

Expand All @@ -43,7 +43,7 @@ public void DeleteProperty()
.Return<Node<Object>>("andres")
.Query;

Assert.Equal("START andres=node({p0})\r\nDELETE andres.age\r\nRETURN andres", query.QueryText);
Assert.Equal("START andres=node($p0)\r\nDELETE andres.age\r\nRETURN andres", query.QueryText);
Assert.Equal(3L, query.QueryParameters["p0"]);
}

Expand All @@ -56,7 +56,7 @@ public void DeleteIdentifier()
.Delete("n")
.Query;

Assert.Equal("START n=node({p0})\r\nDELETE n", query.QueryText);
Assert.Equal("START n=node($p0)\r\nDELETE n", query.QueryText);
Assert.Equal(3L, query.QueryParameters["p0"]);
}

Expand All @@ -78,7 +78,7 @@ public void DeleteWithoutReturn()

// Assert
Assert.NotNull(executedQuery);
Assert.Equal("START n=node({p0})\r\nDELETE n", executedQuery.QueryText);
Assert.Equal("START n=node($p0)\r\nDELETE n", executedQuery.QueryText);
Assert.Equal(3L, executedQuery.QueryParameters["p0"]);
}

Expand All @@ -93,7 +93,7 @@ public void AllowDeleteClauseAfterWhere()
.Query;

// Assert
Assert.Equal("START n=node({p0})\r\nWHERE (...)\r\nDELETE n", query.QueryText);
Assert.Equal("START n=node($p0)\r\nWHERE (...)\r\nDELETE n", query.QueryText);
Assert.Equal(3L, query.QueryParameters["p0"]);
}
}
Expand Down
8 changes: 4 additions & 4 deletions Neo4jClient.Tests.Shared/Cypher/CypherFluentQueryDropTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void DeleteProperty()
.Return<Node<Object>>("andres")
.Query;

Assert.Equal("START andres=node({p0})\r\nDELETE andres.age\r\nRETURN andres", query.QueryText);
Assert.Equal("START andres=node($p0)\r\nDELETE andres.age\r\nRETURN andres", query.QueryText);
Assert.Equal(3L, query.QueryParameters["p0"]);
}

Expand All @@ -52,7 +52,7 @@ public void DeleteIdentifier()
.Delete("n")
.Query;

Assert.Equal("START n=node({p0})\r\nDELETE n", query.QueryText);
Assert.Equal("START n=node($p0)\r\nDELETE n", query.QueryText);
Assert.Equal(3L, query.QueryParameters["p0"]);
}

Expand All @@ -74,7 +74,7 @@ public void DeleteWithoutReturn()

// Assert
Assert.NotNull(executedQuery);
Assert.Equal("START n=node({p0})\r\nDELETE n", executedQuery.QueryText);
Assert.Equal("START n=node($p0)\r\nDELETE n", executedQuery.QueryText);
Assert.Equal(3L, executedQuery.QueryParameters["p0"]);
}

Expand All @@ -89,7 +89,7 @@ public void AllowDeleteClauseAfterWhere()
.Query;

// Assert
Assert.Equal("START n=node({p0})\r\nWHERE (...)\r\nDELETE n", query.QueryText);
Assert.Equal("START n=node($p0)\r\nWHERE (...)\r\nDELETE n", query.QueryText);
Assert.Equal(3L, query.QueryParameters["p0"]);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void LimitClause()
.Query;

// Assert
Assert.Equal("START n=node({p0})\r\nRETURN n\r\nLIMIT {p1}", query.QueryText);
Assert.Equal("START n=node($p0)\r\nRETURN n\r\nLIMIT $p1", query.QueryText);
Assert.Equal(2, query.QueryParameters.Count);
Assert.Equal(3L, query.QueryParameters["p0"]);
Assert.Equal(2, query.QueryParameters["p1"]);
Expand Down Expand Up @@ -55,7 +55,7 @@ public void NullLimitDoesNotWriteClause()
.Query;

// Assert
Assert.Equal("START n=node({p0})\r\nRETURN n", query.QueryText);
Assert.Equal("START n=node($p0)\r\nRETURN n", query.QueryText);
Assert.Equal(1, query.QueryParameters.Count);
Assert.Equal(3L, query.QueryParameters["p0"]);
}
Expand All @@ -74,7 +74,7 @@ public void LimitClauseAfterWithClause()


// Assert
Assert.Equal("START n=node({p0})\r\nWITH foo\r\nLIMIT {p1}", query.QueryText);
Assert.Equal("START n=node($p0)\r\nWITH foo\r\nLIMIT $p1", query.QueryText);
Assert.Equal(2, query.QueryParameters.Count);
Assert.Equal(3L, query.QueryParameters["p0"]);
Assert.Equal(2, query.QueryParameters["p1"]);
Expand Down
10 changes: 5 additions & 5 deletions Neo4jClient.Tests.Shared/Cypher/CypherFluentQueryMatchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void MatchRelatedNodes()
.Return<object>("x")
.Query;

Assert.Equal("START n=node({p0})\r\nMATCH (n)--(x)\r\nRETURN x", query.QueryText);
Assert.Equal("START n=node($p0)\r\nMATCH (n)--(x)\r\nRETURN x", query.QueryText);
Assert.Equal(3L, query.QueryParameters["p0"]);
}

Expand Down Expand Up @@ -67,11 +67,11 @@ public void MultipleMatchClauses()
public void MultipleMatchClausesWithPairedWhereClauses()
{
// MATCH (n)
// WHERE n.Foo = {p0}
// WHERE n.Foo = $p0
// OPTIONAL MATCH (n)--(x)
// WHERE x.Bar = {p1}
// WHERE x.Bar = $p1
// OPTIONAL MATCH (x)--(a)
// WHERE a.Baz = {p2}
// WHERE a.Baz = $p2
// RETURN n, x

var client = Substitute.For<IRawGraphClient>();
Expand All @@ -84,7 +84,7 @@ public void MultipleMatchClausesWithPairedWhereClauses()
.Where((FooBarBaz a) => a.Baz == "ghi")
.Query;

const string expected = "MATCH (n)\r\nWHERE (n.Foo = {p0})\r\nOPTIONAL MATCH (n)--(x)\r\nWHERE (x.Bar = {p1})\r\nOPTIONAL MATCH (x)--(a)\r\nWHERE (a.Baz = {p2})";
const string expected = "MATCH (n)\r\nWHERE (n.Foo = $p0)\r\nOPTIONAL MATCH (n)--(x)\r\nWHERE (x.Bar = $p1)\r\nOPTIONAL MATCH (x)--(a)\r\nWHERE (a.Baz = $p2)";

Assert.Equal(expected, query.QueryText);
Assert.Equal(3, query.QueryParameters.Count());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void RemoveProperty()
.Query;

// Assert
Assert.Equal("START n=node({p0})\r\nREMOVE n.age\r\nRETURN n", query.QueryText);
Assert.Equal("START n=node($p0)\r\nREMOVE n.age\r\nRETURN n", query.QueryText);
Assert.Equal(3L, query.QueryParameters["p0"]);
}

Expand All @@ -37,7 +37,7 @@ public void RemoveLabel()
.Query;

// Assert
Assert.Equal("START n=node({p0})\r\nREMOVE n:Person\r\nRETURN n", query.QueryText);
Assert.Equal("START n=node($p0)\r\nREMOVE n:Person\r\nRETURN n", query.QueryText);
Assert.Equal(3L, query.QueryParameters["p0"]);
}
}
Expand Down
18 changes: 9 additions & 9 deletions Neo4jClient.Tests.Shared/Cypher/CypherFluentQueryReturnTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void ReturnDistinct()
.ReturnDistinct<object>("n")
.Query;

Assert.Equal("START n=node({p0})\r\nRETURN distinct n", query.QueryText);
Assert.Equal("START n=node($p0)\r\nRETURN distinct n", query.QueryText);
Assert.Equal(3L, query.QueryParameters["p0"]);
Assert.Equal(CypherResultFormat.DependsOnEnvironment, query.ResultFormat);
}
Expand All @@ -47,7 +47,7 @@ public void ReturnDistinctWithLimit()
.Limit(5)
.Query;

Assert.Equal("START n=node({p0})\r\nRETURN distinct n\r\nLIMIT {p1}", query.QueryText);
Assert.Equal("START n=node($p0)\r\nRETURN distinct n\r\nLIMIT $p1", query.QueryText);
Assert.Equal(3L, query.QueryParameters["p0"]);
Assert.Equal(5, query.QueryParameters["p1"]);
Assert.Equal(CypherResultFormat.DependsOnEnvironment, query.ResultFormat);
Expand All @@ -64,7 +64,7 @@ public void ReturnDistinctWithLimitAndOrderBy()
.Limit(5)
.Query;

Assert.Equal("START n=node({p0})\r\nRETURN distinct n\r\nORDER BY n.Foo\r\nLIMIT {p1}", query.QueryText);
Assert.Equal("START n=node($p0)\r\nRETURN distinct n\r\nORDER BY n.Foo\r\nLIMIT $p1", query.QueryText);
Assert.Equal(3L, query.QueryParameters["p0"]);
Assert.Equal(5, query.QueryParameters["p1"]);
Assert.Equal(CypherResultFormat.DependsOnEnvironment, query.ResultFormat);
Expand All @@ -79,7 +79,7 @@ public void ReturnIdentity()
.Return<object>("n")
.Query;

Assert.Equal("START n=node({p0})\r\nRETURN n", query.QueryText);
Assert.Equal("START n=node($p0)\r\nRETURN n", query.QueryText);
Assert.Equal(3L, query.QueryParameters["p0"]);
Assert.Equal(CypherResultFormat.DependsOnEnvironment, query.ResultFormat);
}
Expand All @@ -105,7 +105,7 @@ public void ReturnWithLimit()
.Limit(5)
.Query;

Assert.Equal("START n=node({p0})\r\nRETURN n\r\nLIMIT {p1}", query.QueryText);
Assert.Equal("START n=node($p0)\r\nRETURN n\r\nLIMIT $p1", query.QueryText);
Assert.Equal(3L, query.QueryParameters["p0"]);
Assert.Equal(5, query.QueryParameters["p1"]);
Assert.Equal(CypherResultFormat.DependsOnEnvironment, query.ResultFormat);
Expand All @@ -122,7 +122,7 @@ public void ReturnWithLimitAndOrderBy()
.Limit(5)
.Query;

Assert.Equal("START n=node({p0})\r\nRETURN n\r\nORDER BY n.Foo\r\nLIMIT {p1}", query.QueryText);
Assert.Equal("START n=node($p0)\r\nRETURN n\r\nORDER BY n.Foo\r\nLIMIT $p1", query.QueryText);
Assert.Equal(3L, query.QueryParameters["p0"]);
Assert.Equal(5, query.QueryParameters["p1"]);
Assert.Equal(CypherResultFormat.DependsOnEnvironment, query.ResultFormat);
Expand All @@ -145,7 +145,7 @@ public void ShouldCombineWithLimitAndOrderBy()
.OrderBy("common.FirstName")
.Query;

Assert.Equal(string.Format("START me=node({{p0}}), viewer=node({{p1}}){0}MATCH me-[:FRIEND]-common-[:FRIEND]-viewer{0}RETURN common{0}LIMIT {{p2}}{0}ORDER BY common.FirstName", Environment.NewLine), query.QueryText);
Assert.Equal(string.Format("START me=node($p0), viewer=node($p1){0}MATCH me-[:FRIEND]-common-[:FRIEND]-viewer{0}RETURN common{0}LIMIT $p2{0}ORDER BY common.FirstName", Environment.NewLine), query.QueryText);
Assert.Equal(123L, query.QueryParameters["p0"]);
Assert.Equal(456L, query.QueryParameters["p1"]);
Assert.Equal(5, query.QueryParameters["p2"]);
Expand Down Expand Up @@ -399,7 +399,7 @@ public void ShouldUseProjectionResultModeForNamedObjectReturnCamel()
[Fact]
public void ShouldSupportAnonymousReturnTypesEndToEnd()
{
const string queryText = "START root=node({p0})\r\nMATCH root-->other\r\nRETURN other AS Foo";
const string queryText = "START root=node($p0)\r\nMATCH root-->other\r\nRETURN other AS Foo";
var parameters = new Dictionary<string, object>
{
{"p0", 123}
Expand Down Expand Up @@ -508,7 +508,7 @@ public void ShouldSupportAnonymousReturnTypesEndToEnd()
[Fact]
public void ShouldSupportAnonymousReturnTypesEndToEndCamel()
{
const string queryText = "START root=node({p0})\r\nMATCH root-->other\r\nRETURN other AS Foo";
const string queryText = "START root=node($p0)\r\nMATCH root-->other\r\nRETURN other AS Foo";
var parameters = new Dictionary<string, object>
{
{"p0", 123}
Expand Down
4 changes: 2 additions & 2 deletions Neo4jClient.Tests.Shared/Cypher/CypherFluentQuerySetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void SetProperty()
.Query;

// Assert
Assert.Equal("START n=node({p0})\r\nSET n.age = 30\r\nRETURN n", query.QueryText);
Assert.Equal("START n=node($p0)\r\nSET n.age = 30\r\nRETURN n", query.QueryText);
Assert.Equal(3L, query.QueryParameters["p0"]);
}

Expand All @@ -36,7 +36,7 @@ public void SetWithoutReturn()
.Query;

// Assert
Assert.Equal("START n=node({p0})\r\nSET n.name = \"Ted\"", query.QueryText);
Assert.Equal("START n=node($p0)\r\nSET n.name = \"Ted\"", query.QueryText);
Assert.Equal(3L, query.QueryParameters["p0"]);
}
}
Expand Down
6 changes: 3 additions & 3 deletions Neo4jClient.Tests.Shared/Cypher/CypherFluentQuerySkipTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void SkipClause()
.Query;

// Assert
Assert.Equal("START n=node({p0})\r\nRETURN n\r\nSKIP {p1}", query.QueryText);
Assert.Equal("START n=node($p0)\r\nRETURN n\r\nSKIP $p1", query.QueryText);
Assert.Equal(2, query.QueryParameters.Count);
Assert.Equal(3L, query.QueryParameters["p0"]);
Assert.Equal(2, query.QueryParameters["p1"]);
Expand Down Expand Up @@ -55,7 +55,7 @@ public void NullSkipDoesNotWriteClause()
.Query;

// Assert
Assert.Equal("START n=node({p0})\r\nRETURN n", query.QueryText);
Assert.Equal("START n=node($p0)\r\nRETURN n", query.QueryText);
Assert.Equal(1, query.QueryParameters.Count);
Assert.Equal(3L, query.QueryParameters["p0"]);
}
Expand All @@ -74,7 +74,7 @@ public void SkipClauseAfterWithClause()


// Assert
Assert.Equal("START n=node({p0})\r\nWITH foo\r\nSKIP {p1}", query.QueryText);
Assert.Equal("START n=node($p0)\r\nWITH foo\r\nSKIP $p1", query.QueryText);
Assert.Equal(2, query.QueryParameters.Count);
Assert.Equal(3L, query.QueryParameters["p0"]);
Assert.Equal(2, query.QueryParameters["p1"]);
Expand Down
Loading

0 comments on commit 47c9a3b

Please sign in to comment.