You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Issue 458 WithParam: throw exception if parameter starts with '$' (or… (#460)
* Issue 458 WithParam: throw exception if parameter starts with '$' (or any other not allowed character).
Issue 459 WithParam: exeption when using already existing param name outputs "key" instead of param name
* Added WithParams test method to ThrowsExceptionForDuplicateManualKey
* fixes usage of params in ArgumentExceptions
* added output of multiple invalid/duplicate parameters with tests
* missing space
Copy file name to clipboardExpand all lines: Neo4jClient.Tests/Cypher/CypherFluentQueryWithParamTests.cs
+50-3Lines changed: 50 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,9 @@
1
1
usingSystem;
2
+
usingFluentAssertions;
2
3
usingNeo4jClient.Cypher;
3
4
usingNewtonsoft.Json.Serialization;
4
5
usingNSubstitute;
6
+
usingNSubstitute.ExceptionExtensions;
5
7
usingXunit;
6
8
7
9
namespaceNeo4jClient.Tests.Cypher
@@ -53,14 +55,27 @@ public void ThrowsExceptionForDuplicateManualKey()
53
55
varclient=Substitute.For<IRawGraphClient>();
54
56
varquery=newCypherFluentQuery(client)
55
57
.Match("n")
56
-
.WithParam("foo",123);
58
+
.WithParam("foo",123)
59
+
.WithParam("bar",123);
57
60
58
61
// Assert
59
62
varex=Assert.Throws<ArgumentException>(
60
63
()=>query.WithParam("foo",456)
61
64
);
62
65
Assert.Equal("key",ex.ParamName);
63
-
Assert.Equal("A parameter with the given key is already defined in the query."+Environment.NewLine+"Parameter name: key",ex.Message);
66
+
Assert.Equal("A parameter with the given key 'foo' is already defined in the query."+Environment.NewLine+"Parameter name: key",ex.Message);
67
+
68
+
ex=Assert.Throws<ArgumentException>(
69
+
()=>query.WithParams(new{foo=456})
70
+
);
71
+
Assert.Equal("parameters",ex.ParamName);
72
+
Assert.Equal("A parameter with the given key 'foo' is already defined in the query."+Environment.NewLine+"Parameter name: parameters",ex.Message);
73
+
74
+
ex=Assert.Throws<ArgumentException>(
75
+
()=>query.WithParams(new{foo=456,bar=456})
76
+
);
77
+
Assert.Equal("parameters",ex.ParamName);
78
+
Assert.Equal("Parameters with the given keys 'foo, bar' are already defined in the query."+Environment.NewLine+"Parameter name: parameters",ex.Message);
64
79
}
65
80
66
81
[Fact]
@@ -77,7 +92,39 @@ public void ThrowsExceptionForDuplicateOfAutoKey()
77
92
()=>query.WithParam("p0",456)
78
93
);
79
94
Assert.Equal("key",ex.ParamName);
80
-
Assert.Equal("A parameter with the given key is already defined in the query."+Environment.NewLine+"Parameter name: key",ex.Message);
95
+
Assert.Equal("A parameter with the given key 'p0' is already defined in the query."+Environment.NewLine+"Parameter name: key",ex.Message);
ex.Message.Should().Be("The parameter with the given key '$uuid' is not valid. Parameters may consist of letters and numbers, and any combination of these, but cannot start with a number or a currency symbol.\r\nParameter name: key");
ex.Message.Should().Be("The parameter with the given key '0uuid' is not valid. Parameters may consist of letters and numbers, and any combination of these, but cannot start with a number or a currency symbol.\r\nParameter name: key");
ex.Message.Should().Be("The parameter with the given key '{uuid}' is not valid. Parameters may consist of letters and numbers, and any combination of these, but cannot start with a number or a currency symbol.\r\nParameter name: key");
thrownewArgumentException($"The parameter with the given key '{key}' is not valid. Parameters may consist of letters and numbers, and any combination of these, but cannot start with a number or a currency symbol.",nameof(key));
153
+
151
154
if(QueryWriter.ContainsParameterWithKey(key))
152
-
thrownewArgumentException("A parameter with the given key is already defined in the query.",nameof(key));
155
+
thrownewArgumentException($"A parameter with the given key '{key}' is already defined in the query.",nameof(key));
?$"The parameter with the given key '{invalidParameters.First()}' is not valid."
169
+
:$"The parameters with the given keys '{string.Join(", ",invalidParameters)}' are not valid.")+
170
+
" Parameters may consist of letters and numbers, and any combination of these, but cannot start with a number or a currency symbol.",nameof(parameters));
returnMutate(w =>w.AppendClause($"{periodicCommitText} LOAD CSV{withHeadersEnabledText} FROM '{fileUri.AbsoluteUri}' AS {identifier}{fieldSeperatorEnabledText}".Trim()));
418
+
returnMutate(w =>w.AppendClause($"{periodicCommitText} LOAD CSV{withHeadersEnabledText} FROM '{fileUri.AbsoluteUri}' AS {identifier}{fieldSeparatorEnabledText}".Trim()));
0 commit comments