public void Join_BuildsJoinExpressionWithAdditionalExpressionCriteriaWhereCorrectly() { var criteria = new JsonCriteriaNode { Operator = Operator.And, Operands = new List<JsonCriteriaNode> { new JsonCriteriaNode { Key = "LinqToObjectsOneField", Operator = Operator.Equal, Value = "OneOne" } } }; var result = Join.Using(_joinConfiguration) .StartWith<LinqToObjectsOne>() .Join<LinqToObjectsOne>().To<LinqToObjectsTwo>().On(p => p.LinqToObjectsOneId, c => c.LinqToObjectsOneParentId) .Join<LinqToObjectsOne>().To<LinqToObjectsThree>().On(p => p.LinqToObjectsOneId, t => t.LinqToObjectsOneParentId) .Where(criteria) .Where<LinqToObjectsTwo>(x => x.LinqToObjectsTwoField == "TwoTwo") .Query<LinqToObjectsOne>() .Distinct() .ToList(); Assert.That(result.Count(), Is.EqualTo(1)); }
public void Join_BuildsJoinExpressionWithWhereCorrectly() { var criteria = new JsonCriteriaNode { Operator = Operator.And, Operands = new List<JsonCriteriaNode> { new JsonCriteriaNode { Key = "RootEntityField", Operator = Operator.NotEqual, Value = "TestFieldValue" } } }; var result = Join.Using(_joinConfiguration) .StartWith<RootEntity>() .Join<RootEntity>().To<OneLevelEntity>().On(p => p.RootEntityId, c => c.RootEntityParent.RootEntityId) .Join<RootEntity>().To<TwoLevelEntity>().On(p => p.RootEntityId, c => c.RootEntityParent.RootEntityId) .Where(criteria) .Query<RootEntity>() .Distinct() .ToList(); Assert.That(result.Count(), Is.EqualTo(1)); }
public void SolveFor_EmptyJoinPathRegistryAndNoJoins_CorrectlyQueryies() { _joinPathSolver = JoinPathSolver.With(new JoinConfiguration { ExpressionBuilder = new ExpressionBuilder(new MockCriteriaTypeRegistry()), QueryableProvider = new LinqToObjectsQueryableProvider(), JoinPathRegistry = new EmptyJoinPathRegistry() }); var criteria = new JsonCriteriaNode { Operator = Operator.And, Operands = new List<JsonCriteriaNode> { new JsonCriteriaNode { Key = "LinqToObjectsOneField", Operator = Operator.NotEqual, Value = "OneOne" } } }; var result = _joinPathSolver .SolveFor<LinqToObjectsOne>(criteria) .Query<LinqToObjectsOne>() .Distinct() .ToList(); Assert.That(result.Count, Is.EqualTo(5)); }
public void ToString_OperatorAndWithOperands_OutputsString() { const string key = "TestKey"; const string value = "TestValue"; var node = new JsonCriteriaNode { Operator = Operator.And, Operands = new List<JsonCriteriaNode> { new JsonCriteriaNode { Operator = Operator.Equal, Key = key, Value = value }, new JsonCriteriaNode { Operator = Operator.NotEqual, Key = key, Value = value }, } }; Assert.That(node.ToString(), Is.EqualTo("((TestKey == TestValue) && (TestKey != TestValue))")); }
public Expression Build(JsonCriteriaNode jsonCriteriaNode) { var result = (jsonCriteriaNode.Operator.IsCompositeOperator()) ? BuildCompositeExpression(jsonCriteriaNode) : BuildLeafExpression(jsonCriteriaNode); return result; }
public void ToString_OperatorAndWithoutOperands_OutputsString() { var node = new JsonCriteriaNode { Operator = Operator.And, Operands = new List<JsonCriteriaNode>() }; Assert.That(node.ToString(), Is.EqualTo("()")); }
public void ToString_OperatorBetween_OutputsString() { const string key = "TestKey"; const string value = "TestValue"; var node = new JsonCriteriaNode { Operator = Operator.Between, Key = key, Value = value }; Assert.That(node.ToString(), Is.EqualTo(String.Format("({0} Between {1})", key, value))); }
public void SolveFor_MissingTypeRegistryInJoinPathRegistry_ThrowsMissingTypeException() { var criteria = new JsonCriteriaNode { Operator = Operator.And, Operands = new List<JsonCriteriaNode> { new JsonCriteriaNode { Key = "TestStringProperty", Operator = Operator.NotEqual, Value = "OneOne" } } }; Assert.That(() => { _joinPathSolver .SolveFor<LinqToObjectsOne>(criteria); }, Throws.ArgumentException); }
public void Join_NoJoinsWithWhereBuildsCorrectly() { var criteria = new JsonCriteriaNode { Operator = Operator.And, Operands = new List<JsonCriteriaNode> { new JsonCriteriaNode { Key = "LinqToObjectsOneField", Operator = Operator.Equal, Value = "OneOne" } } }; var result = Join.Using(_joinConfiguration) .StartWith<LinqToObjectsOne>() .Where(criteria) .Query<LinqToObjectsOne>() .ToList(); Assert.That(result.Count(), Is.EqualTo(1)); }
public void SolveFor_SingleType_CorrectlyQueries() { var criteria = new JsonCriteriaNode { Operator = Operator.And, Operands = new List<JsonCriteriaNode> { new JsonCriteriaNode { Key = "LinqToObjectsOneField", Operator = Operator.NotEqual, Value = "OneOne" } } }; var result = _joinPathSolver .SolveFor<LinqToObjectsOne>(criteria) .Query<LinqToObjectsOne>() .Distinct() .ToList(); Assert.That(result.Count, Is.EqualTo(5)); }
public void SolveFor_TypeNotRegisteredInJoinPathRegistry_ThrowsException() { var criteria = new JsonCriteriaNode { Operator = Operator.And, Operands = new List<JsonCriteriaNode> { new JsonCriteriaNode { Key = "UnregisteredLinqToObjects", Operator = Operator.NotEqual, Value = "OneOne" } } }; Assert.That(() => { _joinPathSolver .SolveFor<LinqToObjectsOne>(criteria); }, Throws.ArgumentException); }
public void SolveFor_TwoDisjointTypes_CorrectlyQueries() { var criteria = new JsonCriteriaNode { Operator = Operator.And, Operands = new List<JsonCriteriaNode> { new JsonCriteriaNode { Key = "LinqToObjectsTwoField", Operator = Operator.NotEqual, Value = "TwoOne" }, new JsonCriteriaNode { Key = "LinqToObjectsThreeField", Operator = Operator.NotEqual, Value = "ThreeTwo" } } }; var result = _joinPathSolver .SolveFor<LinqToObjectsTwo>(criteria) .Query<LinqToObjectsTwo>() .Distinct() .ToList(); Assert.That(result.Count, Is.EqualTo(1)); }
public void Query_AllJoinsWhereAtEachLevel_ShouldReturnRootEntity() { var criteria = new JsonCriteriaNode { Operator = Operator.And, Operands = new List<JsonCriteriaNode> { new JsonCriteriaNode { Key = "RootEntityField", Operator = Operator.Equal, Value = "RootEntityFieldValue" }, new JsonCriteriaNode { Key = "OneLevelEntityField", Operator = Operator.Equal, Value = "OneLevelEntityFieldValue" }, new JsonCriteriaNode { Key = "TwoLevelEntityField", Operator = Operator.Equal, Value = "TwoLevelEntityFieldValue" }, new JsonCriteriaNode { Key = "TwoLevelEntityChildField", Operator = Operator.Equal, Value = "TwoLevelEntityChildFieldValue" }, new JsonCriteriaNode { Key = "ThreeLevelEntityField", Operator = Operator.Equal, Value = "ThreeLevelEntityFieldValue" }, new JsonCriteriaNode { Key = "ThreeLevelEntityChildField", Operator = Operator.Equal, Value = "ThreeLevelEntityChildFieldValue" }, new JsonCriteriaNode { Key = "ThreeLevelEntityGrandchildField", Operator = Operator.Equal, Value = "ThreeLevelEntityGrandchildFieldValue" } } }; var result = Join.Using(_joinConfiguration) .StartWith<RootEntity>() .Join<RootEntity>().To<OneLevelEntity>().On(x => x.RootEntityId, x => x.RootEntityParent.RootEntityId) .Join<RootEntity>().To<TwoLevelEntity>().On(x => x.RootEntityId, x => x.RootEntityParent.RootEntityId) .Join<TwoLevelEntity>().To<TwoLevelEntityChild>().On(x => x.TwoLevelEntityId, x => x.TwoLevelEntityParent.TwoLevelEntityId) .Join<RootEntity>().To<ThreeLevelEntity>().On(x => x.RootEntityId, x => x.RootEntityParent.RootEntityId) .Join<ThreeLevelEntity>().To<ThreeLevelEntityChild>().On(x => x.ThreeLevelEntityId, x => x.ThreeLevelEntityParent.ThreeLevelEntityId) .Join<ThreeLevelEntityChild>().To<ThreeLevelEntityGrandchild>().On(x => x.ThreeLevelEntityChildId, x => x.ThreeLevelEntityChildParent.ThreeLevelEntityChildId) .Where(criteria) .Query<RootEntity>() .Distinct() .ToList(); Assert.That(result.Count(), Is.EqualTo(1)); }
public void ToString_OperatorIsSpecified_OutputsString() { const string key = "TestKey"; const string value = "TestValue"; var node = new JsonCriteriaNode { Operator = Operator.IsSpecified, Key = key, Value = value }; Assert.That(node.ToString(), Is.EqualTo(String.Format("({0} IsSpecified)", key))); }
public void ToString_OperatorIsNotIn_OutputsString() { const string key = "TestKey"; var value = new[] { "TestValue", "OtherTestValue" }; var node = new JsonCriteriaNode { Operator = Operator.IsNotIn, Key = key, Value = value }; Assert.That(node.ToString(), Is.EqualTo(String.Format("({0} IsNotIn [{1}, {2}])", key, value[0], value[1]))); }
public void ToString_OperatorDoesNotStartWith_OutputsString() { const string key = "TestKey"; const string value = "TestValue"; var node = new JsonCriteriaNode { Operator = Operator.DoesNotStartWith, Key = key, Value = value }; Assert.That(node.ToString(), Is.EqualTo(String.Format("({0} DoesNotStartWith {1})", key, value))); }