public void testCreateWithSIF_Query() { SIF_Query q = new SIF_Query( new SIF_QueryObject( ReportingDTD.STUDENTLOCATOR.Name ) ); SIF_ConditionGroup scg = new SIF_ConditionGroup(); scg.SetType( ConditionType.NONE ); SIF_Condition sifCondition = new SIF_Condition( "RequestingAgencyId[@Type=\"School\"]", Operators.EQ, "2001" ); SIF_Conditions conds = new SIF_Conditions( ConditionType.NONE ); conds.AddChild( sifCondition ); scg.AddSIF_Conditions( conds ); q.SIF_ConditionGroup = scg; Query query = new Query( q ); Assert.IsTrue( query.HasConditions ); ConditionGroup[] conditions = query.Conditions; Assert.AreEqual( 1, conditions.Length, "One Condition Group" ); Assert.AreEqual( GroupOperator.None, conditions[0].Operator, "None" ); Condition condition = conditions[0].Conditions[0]; Assert.AreEqual( "2001", condition.Value, "RequestingAgencyId" ); Assert.AreEqual( ComparisonOperators.EQ, condition.Operators, "RequestingAgencyId" ); Assert.AreEqual( ReportingDTD.STUDENTLOCATOR_REQUESTINGAGENCYID, condition.Field, "RequestingAgencyId" ); }
private static SIF_ConditionGroup createConditionGroup(Query query, SifVersion effectiveVersion) { // Create the hierarchy SIF_ConditionGroup // > SIF_Conditons // > SIF_Condition // From // ConditionGroup // > [ConditionGroup (Optional)] // > Condition SIF_ConditionGroup returnGroup = new SIF_ConditionGroup(); returnGroup.Type = ConditionType.NONE.ToString(); ConditionGroup cg = query.RootConditionGroup; ConditionGroup[] groups = cg.Groups; if (groups != null && groups.Length > 0) { // // There's one or more ConditionGroups... // These get translated to SIF_Conditions elements // if (cg.Operator == GroupOperator.Or) { returnGroup.Type = ConditionType.OR.ToString(); } else if (cg.Operator == GroupOperator.And) { returnGroup.Type = ConditionType.AND.ToString(); } foreach (ConditionGroup group in groups) { returnGroup.AddSIF_Conditions(createConditions(query, group, effectiveVersion)); } } else { // // There are no SIF_Conditions groups, so build one... // returnGroup.AddSIF_Conditions(createConditions(query, cg, effectiveVersion)); } return returnGroup; }