How do I read values in a predicateExpression?

Posts   
 
    
URSC-EST
User
Posts: 8
Joined: 26-Sep-2007
# Posted on: 18-Jan-2008 20:52:56   

I have some methods that return PredicateExpressions built according to a few parameters.

I want to make unit tests for them and for that purpose I would like to make sure the PredicateExpression returned by the method contains exactly what I want.

I want to make sure the PredicateExpression contains 3 PredicateElements. 1- A FieldLikePredicate with specific values. 2- A Or operator 3- A FieldLikePredicate with specific values.

I tried the following but it dosent work.


           IPredicateExpressionElement elem = predicateExpression[0];
            if (elem.Type == PredicateExpressionElementType.Predicate)
            {
                FieldLikePredicate flp = elem as FieldLikePredicate;
            }

flp is always null.... I guess I'm not doing this right.

Thank you. Dave.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 19-Jan-2008 03:55:02   

Hi Dave,

Could you debug and inspect the object at runtime to see what values and types are presented?

(Edit) I checked the manual. I forgot the property Contenst of a given IPredicateExpressionElement. Your code should look like:

foreach (IPredicateExpressionElement element in filter)
{
    switch (element.Type)
    {
        case PredicateExpressionElementType.Predicate:
            FieldLikePredicate flp = (FieldLikePredicate)element.Contents;
            Assert.AreEquals(expectedFieldName, flp.Field.Name);
            Assert.AreEquals(expectedPattern, flp.Pattern);
            break;

        case PredicateExpressionElementType.Operator:
            PredicateExpressionOperator oper = (PredicateExpressionOperator) element.Contents;
            Assert.AreEquals("Or", oper.ToString());
            break;
    }
}

Hope helpful

David Elizondo | LLBLGen Support Team
URSC-EST
User
Posts: 8
Joined: 26-Sep-2007
# Posted on: 21-Jan-2008 19:46:07   

Thx for the reply. I had tried this but I was getting an System.InvalidCastException It turned out I had an other level of predicateExpression that I had to cast through first. The problem is now corrected.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 21-Jan-2008 19:52:35   

Good simple_smile

David Elizondo | LLBLGen Support Team