Permalink
Browse files

Added unit tests for CypherWhereExpressionVisitor.VisitConstantMember()

The unit tests from the last commit was moved from the
CypherFluentQueryWhereTests to CypherWhereExpressionBuilderTests and added
three more unit tests for all logic branches within this method.
  • Loading branch information...
1 parent 38868f3 commit 1726e714213a66bf85c5375869e4a1285cba35d3 @arturosevilla arturosevilla committed Mar 6, 2014
Showing with 60 additions and 15 deletions.
  1. +0 −15 Test/Cypher/CypherFluentQueryWhereTests.cs
  2. +60 −0 Test/Cypher/CypherWhereExpressionBuilderTests.cs
@@ -34,21 +34,6 @@ public void ComparePropertiesAcrossEntitiesEqual()
}
[Test]
- public void CompareWithNullInMemberExpression()
- {
- var client = Substitute.For<IRawGraphClient>();
- var mockWithNullField = new MockWithNullField
- {
- NullField = null
- };
- var query = new CypherFluentQuery(client)
- .Where<MockWithNullField>(a => a.NullField == mockWithNullField.NullField)
- .Query;
-
- Assert.AreEqual("WHERE (not(has(a.NullField)))", query.QueryText);
- }
-
- [Test]
public void ComparePropertiesAcrossEntitiesNotEqual()
{
var client = Substitute.For<IRawGraphClient>();
@@ -159,6 +159,66 @@ public void ForPre20VersionsEvaluateFalseWhenComparingMissingNullablePropertyLes
}
[Test]
+ public void ForPre20VersionsEvaluateTrueWhenComparingMissingNullablePropertyToNullProperty()
+ {
+ var parameters = new Dictionary<string, object>();
+ var fooWithNulls = new Foo
+ {
+ NullableBar = null
+ };
+ Expression<Func<Foo, bool>> expression = foo => foo.NullableBar == fooWithNulls.NullableBar;
+
+ var result = CypherWhereExpressionBuilder.BuildText(expression, v => CreateParameter(parameters, v), CypherCapabilities.Cypher19);
+
+ Assert.AreEqual("(foo.NullableBar? is null)", result);
+ }
+
+ [Test]
+ public void For20VersionsEvaluateTrueWhenComparingMissingNullablePropertyToNullProperty()
+ {
+ var parameters = new Dictionary<string, object>();
+ var fooWithNulls = new Foo
+ {
+ NullableBar = null
+ };
+ Expression<Func<Foo, bool>> expression = foo => foo.NullableBar == fooWithNulls.NullableBar;
+
+ var result = CypherWhereExpressionBuilder.BuildText(expression, v => CreateParameter(parameters, v), CypherCapabilities.Cypher20);
+
+ Assert.AreEqual("(not(has(foo.NullableBar)))", result);
+ }
+
+ [Test]
+ public void ForPre20VersionsEvaluateTrueWhenComparingNotMissingNullablePropertyToNullProperty()
+ {
+ var parameters = new Dictionary<string, object>();
+ var fooWithNulls = new Foo
+ {
+ NullableBar = null
+ };
+ Expression<Func<Foo, bool>> expression = foo => foo.NullableBar != fooWithNulls.NullableBar;
+
+ var result = CypherWhereExpressionBuilder.BuildText(expression, v => CreateParameter(parameters, v), CypherCapabilities.Cypher19);
+
+ Assert.AreEqual("(foo.NullableBar? is not null)", result);
+ }
+
+ [Test]
+ public void For20VersionsEvaluateTrueWhenComparingNotMissingNullablePropertyToNullProperty()
+ {
+ var parameters = new Dictionary<string, object>();
+ var fooWithNulls = new Foo
+ {
+ NullableBar = null
+ };
+ Expression<Func<Foo, bool>> expression = foo => foo.NullableBar != fooWithNulls.NullableBar;
+
+ var result = CypherWhereExpressionBuilder.BuildText(expression, v => CreateParameter(parameters, v), CypherCapabilities.Cypher20);
+
+ Assert.AreEqual("(has(foo.NullableBar))", result);
+ }
+
+ [Test]
public void ForPre20VersionsEvaluateTrueWhenComparingMissingNullablePropertyToNull()
{
var parameters = new Dictionary<string, object>();

0 comments on commit 1726e71

Please sign in to comment.