Example #1
0
        public override void Build(QueryTreeInfo queryTreeInfo)
        {
            switch (queryTreeInfo.queryComponent)
            {
            case QueryComponent.Top:
            {
                queryTreeInfo.queryNodeTree = queryTreeInfo.rootQueryNodeTree.Top(takeSkipValue);
                break;
            }

            case QueryComponent.Skip:
            {
                queryTreeInfo.queryNodeTree = queryTreeInfo.rootQueryNodeTree.Skip(takeSkipValue);
                break;
            }

            case QueryComponent.OrderBy:
            {
                //ORDERBY
                List <PropertyExpression> keyProperties = new List <PropertyExpression>();
                ResourceType         resourceType       = queryTreeInfo.resourceContainer.BaseType;
                PropertyExpression[] propValues         = resourceType.Key.Properties.Select(p => p.Property()).ToArray();
                queryTreeInfo.queryNodeTree  = queryTreeInfo.rootQueryNodeTree.Sort(propValues, true);
                queryTreeInfo.queryComponent = QueryComponent.OrderBy;
                break;
            }

            default:
            {
                break;
            }
            }
        }
 public override void Build(QueryTreeInfo queryTreeInfo)
 {
     switch (queryTreeInfo.queryComponent)
     {
         case QueryComponent.Top:
             {
                 queryTreeInfo.queryNodeTree = queryTreeInfo.rootQueryNodeTree.Top(takeSkipValue);
                 break;
             }
         case QueryComponent.Skip:
             {
                 queryTreeInfo.queryNodeTree = queryTreeInfo.rootQueryNodeTree.Skip(takeSkipValue);
                 break;
             }
         case QueryComponent.OrderBy:
             {
                 //ORDERBY
                 List<PropertyExpression> keyProperties = new List<PropertyExpression>();
                 ResourceType resourceType = queryTreeInfo.resourceContainer.BaseType;
                 PropertyExpression[] propValues = resourceType.Key.Properties.Select(p => p.Property()).ToArray();
                 queryTreeInfo.queryNodeTree = queryTreeInfo.rootQueryNodeTree.Sort(propValues, true);
                 queryTreeInfo.queryComponent = QueryComponent.OrderBy;
                 break;
             }
         default:
             {
                 break;
             }
     }
 }
        protected override bool VerifyLambda(QueryTreeInfo queryTreeInfo)
        {
            List <String> outVal = null;
            bool          result = nodeValues.TryGetValue("Where", out outVal);

            //Check for the where key values
            for (int i = 0; i < refKeys.Count; i++)
            {
                bool valuePresent = false;
                foreach (String s in outVal)
                {
                    if (s.Contains("element." + refKeys[i].Name))
                    {
                        valuePresent = true;
                    }
                }
                if (!valuePresent)
                {
                    //RefKey not found in the list
                    AstoriaTestLog.WriteLine("RefKey not found in the  list");
                    return(false);
                }
            }
            return(true);
        }
Example #4
0
 public virtual bool Compare(QueryTreeInfo queryTreeInfo)
 {
     bool result = false;
     result = VerifyNodes(queryTreeInfo);
     result = VerifyMetaData(queryTreeInfo);
     result = VerifyLambda(queryTreeInfo);
     return result;
 }
Example #5
0
        public override void Build(QueryTreeInfo queryTreeInfo)
        {
            List<ResourceType> resourceTypes = queryTreeInfo.resourceContainer.ResourceTypes.ToList();
            List<ResourceProperty> validProperties = resourceTypes
                        .SelectMany(rt => rt.Properties.OfType<ResourceProperty>())
                        .ToList();

            queryTreeInfo.queryNodeTree = queryTreeInfo.rootQueryNodeTree.New(validProperties[0].Property());
        }
Example #6
0
        public virtual bool Compare(QueryTreeInfo queryTreeInfo)
        {
            bool result = false;

            result = VerifyNodes(queryTreeInfo);
            result = VerifyMetaData(queryTreeInfo);
            result = VerifyLambda(queryTreeInfo);
            return(result);
        }
Example #7
0
        protected override bool VerifyNodes(QueryTreeInfo queryTreeInfo)
        {
            //Find the list of keys for this resource set that will appear as where nodes in the tree

            foreach (ResourceType type in queryTreeInfo.resourceContainer.ResourceTypes)
            {
                foreach (ResourceProperty property in type.Properties.OfType<ResourceProperty>())
                {
                    if (property.PrimaryKey != null)
                    {
                        refKeys.Add(property);
                        AstoriaTestLog.WriteLine(property.Name);
                    }
                }
            }

            return true;
        }
Example #8
0
        protected override bool VerifyLambda(QueryTreeInfo queryTreeInfo)
        {
            XmlDocument currentTreeXml = queryTreeInfo.currentTreeXml;
            XmlNodeList projectedNodes = null;
            
            // Find the nodes that contain the projected properties
            if (queryTreeInfo.wkspc.DataLayerProviderKind == DataLayerProviderKind.Edm)
            {
                projectedNodes = currentTreeXml.SelectNodes("/Call/Arguments/Quote/Lambda/Body/MemberInit/MemberAssignment");
            }
            else if (queryTreeInfo.wkspc.DataLayerProviderKind == DataLayerProviderKind.InMemoryLinq)
            {
                projectedNodes = currentTreeXml.SelectNodes("/Call/Arguments/Quote/Lambda/Body/Conditional/False/MemberInit/MemberAssignment");
            }
            if (projectedNodes.Count == 0)
            {
                AstoriaTestLog.WriteLine("Projected nodes not found");
                return false;
            }
            
            // Verify all the projected properties in the node
            foreach (XmlNode node in projectedNodes)
            {
                if (node.Attributes[0].Value == "PropertyNameList")
                {
                    List<String> projectedProps = node.SelectSingleNode("./Constant").InnerText.Split(new char[] { ',' }).ToList();
                    if (projectedProps.Count != refKeys.Count)
                    {
                        AstoriaTestLog.WriteLine("Projected props count does not match refkeys");
                        return false;
                    }
                    foreach (ResourceProperty rp in refKeys)
                    {
                        if (!projectedProps.Contains(rp.Name))
                        {
                            AstoriaTestLog.WriteLine("Projected props is not a refkey");
                            return false;
                        }

                    }
                }
            }           
            return true;
        }
Example #9
0
        //Get the expression tree
        public static String ProcessExpressionTree(Workspace w, QueryTreeInfo queryTreeInfo)
        {
            // Retrieve expression tree.
            AstoriaResponse rs;

            RequestUtil.GetAndVerifyStatusCode(w, w.ServiceUri + "/ExpToXml", HttpStatusCode.OK, out rs);
            if (rs.ActualStatusCode != HttpStatusCode.OK && rs.ActualStatusCode != HttpStatusCode.NotFound)
            {
                AstoriaTestLog.WriteLine("/ExpToXml returned error code " + rs.ActualStatusCode.ToString() + ", payload:");
                AstoriaTestLog.FailAndThrow(rs.Payload);
            }

            // Extract XML document from response.
            XmlDocument xml = new XmlDocument();

            xml.LoadXml(rs.Payload);

            // Skip verification in retail builds as they do not contain expression capture hook.
            string embeddedDocument = xml.DocumentElement.InnerText;

            AstoriaTestLog.WriteLine(embeddedDocument);
            if (embeddedDocument.StartsWith("WARNING"))
            {
                // Warn the user.
                AstoriaTestLog.WriteLine("WARNING: missing expression tree!");
                AstoriaTestLog.Skip("Test variation skipped");
            }

            // Separate string form and XML form.
            string[] pair = embeddedDocument.Split(new string[] { "[[===]]" }, StringSplitOptions.None);
            xml.LoadXml(pair[1].Replace("utf-16", "utf-8"));
            AstoriaTestLog.WriteLine(xml.OuterXml);
            if (queryTreeInfo != null)
            {
                queryTreeInfo.currentTreeXml = xml;
            }
            //return xml;
            return(pair[0]);
        }
        //Get the expression tree
        public static String ProcessExpressionTree(Workspace w, QueryTreeInfo queryTreeInfo)
        {
            // Retrieve expression tree.
            AstoriaResponse rs;
            RequestUtil.GetAndVerifyStatusCode(w, w.ServiceUri + "/ExpToXml", HttpStatusCode.OK, out rs);
            if (rs.ActualStatusCode != HttpStatusCode.OK && rs.ActualStatusCode != HttpStatusCode.NotFound)
            {
                AstoriaTestLog.WriteLine("/ExpToXml returned error code " + rs.ActualStatusCode.ToString() + ", payload:");
                AstoriaTestLog.FailAndThrow(rs.Payload);
            }

            // Extract XML document from response.
            XmlDocument xml = new XmlDocument();
            xml.LoadXml(rs.Payload);

            // Skip verification in retail builds as they do not contain expression capture hook.
            string embeddedDocument = xml.DocumentElement.InnerText;
            AstoriaTestLog.WriteLine(embeddedDocument);
            if (embeddedDocument.StartsWith("WARNING"))
            {
                // Warn the user.
                AstoriaTestLog.WriteLine("WARNING: missing expression tree!");
                AstoriaTestLog.Skip("Test variation skipped");
            }

            // Separate string form and XML form.
            string[] pair = embeddedDocument.Split(new string[] { "[[===]]" }, StringSplitOptions.None);
            xml.LoadXml(pair[1].Replace("utf-16", "utf-8"));
            AstoriaTestLog.WriteLine(xml.OuterXml);
            if (queryTreeInfo != null)
            {
                queryTreeInfo.currentTreeXml = xml;
            }
            //return xml;
            return pair[0];
        }
        protected override bool VerifyNodes(QueryTreeInfo queryTreeInfo)
        {
            //Find the list of keys for this resource set that will appear as where nodes in the tree

            foreach (ResourceType type in queryTreeInfo.resourceContainer.ResourceTypes)
            {
                foreach (ResourceProperty property in type.Properties.OfType <ResourceProperty>())
                {
                    if (property.PrimaryKey != null)
                    {
                        refKeys.Add(property);
                        AstoriaTestLog.WriteLine(property.Name);
                    }
                }
            }

            if (queryTreeInfo.currentTree.Contains(queryTreeInfo.rootTree))
            {
                // Obtain the diff tree. The +1 is for the "." that is the node separator
                queryTreeInfo.diffTree = queryTreeInfo.currentTree.Substring(queryTreeInfo.rootTree.Length + 1);
                AstoriaTestLog.WriteLine("Diff Tree : " + queryTreeInfo.diffTree);
            }
            //Construct the Tree Dictionary

            String[] splitString = new String[] { ")." };
            String[] result      = queryTreeInfo.diffTree.Split(splitString, StringSplitOptions.None);

            AstoriaTestLog.WriteLine("Split string");
            foreach (String s in result)
            {
                AstoriaTestLog.WriteLine(s);
            }


            //ThenBy and Where nodes can repeat, so create a list to capture the multiple values
            List <String> whereList = new List <String>();



            //Look through each node and construct the dictionary
            foreach (String s in result)
            {
                if (s.StartsWith("Where"))
                {
                    //Can have multiple where nodes, so just create the list of values here and add it to dictionary later

                    String tempStr = s.Split(new String[] { "Where(" }, StringSplitOptions.RemoveEmptyEntries)[0];

                    //Dont add where(p => true) occurances
                    //TODO: Confirm if its ok to ignore where(p=>true) nodes.
                    if (!(tempStr.Contains("p => True")))
                    {
                        whereList.Add(tempStr);
                    }
                    else
                    {
                        AstoriaTestLog.WriteLine("Where(p => true) node found, ignoring the node");
                    }
                }
            }



            //Add the where list to the dictionary
            if (!nodeValues.ContainsKey("Where"))
            {
                if (whereList.Count > 0)
                {
                    nodeValues.Add("Where", whereList);
                }
                if ((refKeys.Count) != whereList.Count)
                {
                    //Where node count doesnt match
                    AstoriaTestLog.WriteLine("Where nodes count doesnt match");
                    return(false);
                }
            }


            return(true);
        }
 protected override bool VerifyMetaData(QueryTreeInfo queryTreeInfo)
 {
     // No metadata to verify for this pattern
     return true;
 }
Example #13
0
 //Compare will in turn call these individual comparison functions
 //Verify the structure of the tree
 protected abstract bool VerifyNodes(QueryTreeInfo queryTreeInfo);
 public override void Build(QueryTreeInfo queryTreeInfo)
 {
     queryTreeInfo.queryNodeTree = queryTreeInfo.rootQueryNodeTree.Where(queryTreeInfo.wkspc.GetRandomExistingKey(queryTreeInfo.resourceContainer));
     //TODO: What if there is no entity that you can select?
 }
        protected override bool VerifyLambda(QueryTreeInfo queryTreeInfo)
        {
            List <String> outVal = null;
            bool result = false;
            if (queryTreeInfo.queryComponent == QueryComponent.Top)
            {
                result = nodeValues.TryGetValue("Take", out outVal);
            }
            else if (queryTreeInfo.queryComponent == QueryComponent.Skip)
            {
                result = nodeValues.TryGetValue("Skip", out outVal);
            }
            

            //Check for take/skip value
            if (result)
            {
                if (!(takeSkipValue.ToString() == outVal[0]))
                {
                    //Take node value does not match
                    AstoriaTestLog.WriteLine("Take/Skip node value does not match");
                    return false;
                }
            }
            else
            {
                if (queryTreeInfo.queryComponent != QueryComponent.OrderBy)
                {
                    //Take node not found in the list
                    AstoriaTestLog.WriteLine("Take/Skip node not found");
                    return false;
                }
            }

            //Check for the orderby/thenby key values
            for (int i = 0; i < refKeys.Count ; i++ )
            {
                
                bool keyPresent;
                List<String> outOrderByVal = null;
                List<String> outThenByVal = null;
                //Must find orderby node
                keyPresent = nodeValues.TryGetValue("OrderBy", out outOrderByVal);
                if (outVal != null)
                {
                    outVal.Clear();
                    outVal.AddRange(outOrderByVal);
                }
                else
                {
                    outVal = outOrderByVal;
                }

                if (keyPresent)
                {
                    //thenby nodes are optional
                    nodeValues.TryGetValue("ThenBy", out outThenByVal);
                    if (outThenByVal != null)
                    {
                        outVal.AddRange(outThenByVal);
                    }
                }
                else
                {
                    //OrderBy/ThenBy node not found
                    AstoriaTestLog.WriteLine("OrderBy/ThenBy node not found");
                    return false;
                }
                
                //Verify the values
                if (keyPresent)
                {
                    bool valuePresent = false;
                    foreach (String s in outVal)
                    {
                        if(s.Contains("element." + refKeys[i].Name))
                        {
                            valuePresent = true;
                        }
                    }
                    if(!valuePresent)
                    {
                        //RefKey not found in the list
                        AstoriaTestLog.WriteLine("RefKey not found in the  list");
                        return false;
                    }
                }
                

            }
            return true;
        }
 protected override bool VerifyMetaData(QueryTreeInfo queryTreeInfo)
 {
     // No metadata to verify for this pattern
     return(true);
 }
Example #17
0
 public abstract void Build(QueryTreeInfo input);
        protected override bool VerifyNodes(QueryTreeInfo queryTreeInfo)
        {
            //Find the list of keys for this resource set that will appear as where nodes in the tree

            foreach (ResourceType type in queryTreeInfo.resourceContainer.ResourceTypes)
            {

                foreach (ResourceProperty property in type.Properties.OfType<ResourceProperty>())
                {
                    if (property.PrimaryKey != null)
                    {
                        refKeys.Add(property);
                        AstoriaTestLog.WriteLine(property.Name);
                    }

                }
            }

            if (queryTreeInfo.currentTree.Contains(queryTreeInfo.rootTree))
            {
                // Obtain the diff tree. The +1 is for the "." that is the node separator
                queryTreeInfo.diffTree = queryTreeInfo.currentTree.Substring(queryTreeInfo.rootTree.Length + 1);
                AstoriaTestLog.WriteLine("Diff Tree : " + queryTreeInfo.diffTree);
            }
            //Construct the Tree Dictionary

            String[] splitString = new String[] { ")." };
            String[] result = queryTreeInfo.diffTree.Split(splitString, StringSplitOptions.None);

            AstoriaTestLog.WriteLine("Split string");
            foreach (String s in result) 
            { 
                AstoriaTestLog.WriteLine(s); 
            }


            //ThenBy and Where nodes can repeat, so create a list to capture the multiple values
            List<String> whereList = new List<String>();
            
            

            //Look through each node and construct the dictionary
            foreach (String s in result)
            {
                if (s.StartsWith("Where"))
                {
                    //Can have multiple where nodes, so just create the list of values here and add it to dictionary later
                    
                    String tempStr = s.Split(new String[] { "Where(" }, StringSplitOptions.RemoveEmptyEntries)[0];

                    //Dont add where(p => true) occurances
                    //TODO: Confirm if its ok to ignore where(p=>true) nodes.
                    if (!(tempStr.Contains("p => True")))
                    {
                        whereList.Add(tempStr);
                    }
                    else
                    {
                        AstoriaTestLog.WriteLine("Where(p => true) node found, ignoring the node");
                    }
                }
            }

                       

            //Add the where list to the dictionary
            if (!nodeValues.ContainsKey("Where"))
            {
                if (whereList.Count > 0)
                {
                    nodeValues.Add("Where", whereList);
                }
                if ((refKeys.Count) != whereList.Count)
                {
                    
                    //Where node count doesnt match
                    AstoriaTestLog.WriteLine("Where nodes count doesnt match");
                    return false;
                }
            }


            return true;
        }
Example #19
0
 //Verify the meta data info in the nodes
 protected abstract bool VerifyMetaData(QueryTreeInfo queryTreeInfo);
Example #20
0
 //Compare will in turn call these individual comparison functions
 //Verify the structure of the tree
 protected abstract bool VerifyNodes(QueryTreeInfo queryTreeInfo);
Example #21
0
 public abstract void Build(QueryTreeInfo input);
        protected override bool VerifyNodes(QueryTreeInfo queryTreeInfo)
        {
            //Find the list of keys for this resource set that will appear as orderby/thenby nodes in the tree
            
            foreach (ResourceType type in queryTreeInfo.resourceContainer.ResourceTypes)
            {
                
                foreach (ResourceProperty property in type.Properties.OfType<ResourceProperty>())
                {
                    if (property.PrimaryKey != null)
                    {
                        refKeys.Add(property);
                        AstoriaTestLog.WriteLine(property.Name);
                    }
                        
                }
            }

            if (queryTreeInfo.currentTree.Contains(queryTreeInfo.rootTree))
            {
                // Obtain the diff tree. The +1 is for the "." that is the node separator
                queryTreeInfo.diffTree= queryTreeInfo.currentTree.Substring(queryTreeInfo.rootTree.Length + 1);
                AstoriaTestLog.WriteLine("Diff Tree : " + queryTreeInfo.diffTree);
            }
            //Construct the Tree Dictionary

            String[] splitString = new String[] { ")." };
            String[] result = queryTreeInfo.diffTree.Split(splitString, StringSplitOptions.None);

            AstoriaTestLog.WriteLine("Split string");
            foreach (String s in result) 
            { 
                AstoriaTestLog.WriteLine(s); 
            }

            
            //ThenBy and Where nodes can repeat, so create a list to capture the multiple values
            List <String> thenByList = new List<String>();
            List<String> whereList = new List<String>();
            String expectedNode = null;

            //Based on the queryComponent, identify the node we should look for in the tree
            if (queryTreeInfo.queryComponent == QueryComponent.Top)
            {
                expectedNode = "Take";
            }
            else if (queryTreeInfo.queryComponent == QueryComponent.Skip)
            {
                expectedNode = "Skip";
            }

            //Look through each node and construct the dictionary
            foreach (String s in result)
            {
                if (s.StartsWith("OrderBy"))
                {
                    if (!nodeValues.ContainsKey("OrderBy"))
                    {
                        nodeValues.Add("OrderBy", new List<String>(s.Split(new String[] { "OrderBy(" }, StringSplitOptions.RemoveEmptyEntries)));
                    }
                    else
                    {
                        //OrderBy found again, return error
                        AstoriaTestLog.WriteLine("More than 1 OrderBy node found");
                        return false;
                    }

                }
                if (s.StartsWith("ThenBy"))
                {
                    //Can have multiple thenby nodes, so just create the list of values here and add it to dictionary later
                    thenByList.Add((s.Split(new String[] { "ThenBy(" }, StringSplitOptions.RemoveEmptyEntries)[0]));
                }

                //Check for take/skip
                if (expectedNode != null)
                {
                    if (s.StartsWith(expectedNode))
                    {
                        if (!nodeValues.ContainsKey(expectedNode))
                        {
                            nodeValues.Add(expectedNode, new List<String>(s.Split(new String[] { expectedNode + "(", ")" }, StringSplitOptions.RemoveEmptyEntries)));
                        }
                        else
                        {
                            //Node found again, return error
                            AstoriaTestLog.WriteLine("More than 1 " + expectedNode + " node found");
                            return false;
                        }
                    }
                }
                if (s.StartsWith("Where"))
                {
                    //Can have multiple where nodes, so just create the list of values here and add it to dictionary later
                    whereList.Add((s.Split(new String[] { "Where(" }, StringSplitOptions.RemoveEmptyEntries)[0]));
                }
            }

            //Verify that the correct number of orderby/thenby/take nodes are present

            //Check for take/skip
            if (expectedNode != null)
            {
                //Is Take/Skip node present
                if (!nodeValues.ContainsKey(expectedNode))
                {
                    //Take/Skip node not found
                    AstoriaTestLog.WriteLine(expectedNode + " node not found");
                    return false;
                }
            }

            //Is OrderBy node present?
            if (!nodeValues.ContainsKey("OrderBy"))
            {
                //OrderBy node not found
                AstoriaTestLog.WriteLine("OrderBy node not found");
                return false;
            }

            //Add the theyby list to the dictionary and Verify the count of ThenBy nodes
            if (!nodeValues.ContainsKey("ThenBy"))
            {
                if (thenByList.Count > 0)
                {
                    nodeValues.Add("ThenBy", thenByList);
                }
                if ((refKeys.Count-1) != thenByList.Count)
                {
                    //ThenBy node count doesnt match
                    AstoriaTestLog.WriteLine("ThenBy nodes count doesnt match");
                    return false;
                }
            }

            //Add the where list to the dictionary
            if (!nodeValues.ContainsKey("Where"))
            {
                if (whereList.Count > 0)
                {
                    nodeValues.Add("Where", whereList);
                }
            }

           
            return true;
        }
Example #23
0
 //Verify the lambda expressions where applicable - in cases like select node
 protected abstract bool VerifyLambda(QueryTreeInfo queryTreeInfo);
 protected override bool VerifyLambda(QueryTreeInfo queryTreeInfo)
 {
     List<String> outVal = null;
     bool result = nodeValues.TryGetValue("Where", out outVal);
     
     //Check for the where key values
     for (int i = 0; i < refKeys.Count; i++)
     {
         bool valuePresent = false;
         foreach (String s in outVal)
         {
             if (s.Contains("element." + refKeys[i].Name))
             {
                 valuePresent = true;
             }
         }
         if (!valuePresent)
         {
             //RefKey not found in the list
             AstoriaTestLog.WriteLine("RefKey not found in the  list");
             return false;
         }
     }
     return true;
 }
Example #25
0
 //Verify the meta data info in the nodes
 protected abstract bool VerifyMetaData(QueryTreeInfo queryTreeInfo);
 public override void Build(QueryTreeInfo queryTreeInfo)
 {
     queryTreeInfo.queryNodeTree = queryTreeInfo.rootQueryNodeTree.Where(queryTreeInfo.wkspc.GetRandomExistingKey(queryTreeInfo.resourceContainer));
     //TODO: What if there is no entity that you can select?
 }
Example #27
0
        protected override bool VerifyNodes(QueryTreeInfo queryTreeInfo)
        {
            //Find the list of keys for this resource set that will appear as orderby/thenby nodes in the tree

            foreach (ResourceType type in queryTreeInfo.resourceContainer.ResourceTypes)
            {
                foreach (ResourceProperty property in type.Properties.OfType <ResourceProperty>())
                {
                    if (property.PrimaryKey != null)
                    {
                        refKeys.Add(property);
                        AstoriaTestLog.WriteLine(property.Name);
                    }
                }
            }

            if (queryTreeInfo.currentTree.Contains(queryTreeInfo.rootTree))
            {
                // Obtain the diff tree. The +1 is for the "." that is the node separator
                queryTreeInfo.diffTree = queryTreeInfo.currentTree.Substring(queryTreeInfo.rootTree.Length + 1);
                AstoriaTestLog.WriteLine("Diff Tree : " + queryTreeInfo.diffTree);
            }
            //Construct the Tree Dictionary

            String[] splitString = new String[] { ")." };
            String[] result      = queryTreeInfo.diffTree.Split(splitString, StringSplitOptions.None);

            AstoriaTestLog.WriteLine("Split string");
            foreach (String s in result)
            {
                AstoriaTestLog.WriteLine(s);
            }


            //ThenBy and Where nodes can repeat, so create a list to capture the multiple values
            List <String> thenByList   = new List <String>();
            List <String> whereList    = new List <String>();
            String        expectedNode = null;

            //Based on the queryComponent, identify the node we should look for in the tree
            if (queryTreeInfo.queryComponent == QueryComponent.Top)
            {
                expectedNode = "Take";
            }
            else if (queryTreeInfo.queryComponent == QueryComponent.Skip)
            {
                expectedNode = "Skip";
            }

            //Look through each node and construct the dictionary
            foreach (String s in result)
            {
                if (s.StartsWith("OrderBy"))
                {
                    if (!nodeValues.ContainsKey("OrderBy"))
                    {
                        nodeValues.Add("OrderBy", new List <String>(s.Split(new String[] { "OrderBy(" }, StringSplitOptions.RemoveEmptyEntries)));
                    }
                    else
                    {
                        //OrderBy found again, return error
                        AstoriaTestLog.WriteLine("More than 1 OrderBy node found");
                        return(false);
                    }
                }
                if (s.StartsWith("ThenBy"))
                {
                    //Can have multiple thenby nodes, so just create the list of values here and add it to dictionary later
                    thenByList.Add((s.Split(new String[] { "ThenBy(" }, StringSplitOptions.RemoveEmptyEntries)[0]));
                }

                //Check for take/skip
                if (expectedNode != null)
                {
                    if (s.StartsWith(expectedNode))
                    {
                        if (!nodeValues.ContainsKey(expectedNode))
                        {
                            nodeValues.Add(expectedNode, new List <String>(s.Split(new String[] { expectedNode + "(", ")" }, StringSplitOptions.RemoveEmptyEntries)));
                        }
                        else
                        {
                            //Node found again, return error
                            AstoriaTestLog.WriteLine("More than 1 " + expectedNode + " node found");
                            return(false);
                        }
                    }
                }
                if (s.StartsWith("Where"))
                {
                    //Can have multiple where nodes, so just create the list of values here and add it to dictionary later
                    whereList.Add((s.Split(new String[] { "Where(" }, StringSplitOptions.RemoveEmptyEntries)[0]));
                }
            }

            //Verify that the correct number of orderby/thenby/take nodes are present

            //Check for take/skip
            if (expectedNode != null)
            {
                //Is Take/Skip node present
                if (!nodeValues.ContainsKey(expectedNode))
                {
                    //Take/Skip node not found
                    AstoriaTestLog.WriteLine(expectedNode + " node not found");
                    return(false);
                }
            }

            //Is OrderBy node present?
            if (!nodeValues.ContainsKey("OrderBy"))
            {
                //OrderBy node not found
                AstoriaTestLog.WriteLine("OrderBy node not found");
                return(false);
            }

            //Add the theyby list to the dictionary and Verify the count of ThenBy nodes
            if (!nodeValues.ContainsKey("ThenBy"))
            {
                if (thenByList.Count > 0)
                {
                    nodeValues.Add("ThenBy", thenByList);
                }
                if ((refKeys.Count - 1) != thenByList.Count)
                {
                    //ThenBy node count doesnt match
                    AstoriaTestLog.WriteLine("ThenBy nodes count doesnt match");
                    return(false);
                }
            }

            //Add the where list to the dictionary
            if (!nodeValues.ContainsKey("Where"))
            {
                if (whereList.Count > 0)
                {
                    nodeValues.Add("Where", whereList);
                }
            }


            return(true);
        }
Example #28
0
        protected override bool VerifyLambda(QueryTreeInfo queryTreeInfo)
        {
            List <String> outVal = null;
            bool          result = false;

            if (queryTreeInfo.queryComponent == QueryComponent.Top)
            {
                result = nodeValues.TryGetValue("Take", out outVal);
            }
            else if (queryTreeInfo.queryComponent == QueryComponent.Skip)
            {
                result = nodeValues.TryGetValue("Skip", out outVal);
            }


            //Check for take/skip value
            if (result)
            {
                if (!(takeSkipValue.ToString() == outVal[0]))
                {
                    //Take node value does not match
                    AstoriaTestLog.WriteLine("Take/Skip node value does not match");
                    return(false);
                }
            }
            else
            {
                if (queryTreeInfo.queryComponent != QueryComponent.OrderBy)
                {
                    //Take node not found in the list
                    AstoriaTestLog.WriteLine("Take/Skip node not found");
                    return(false);
                }
            }

            //Check for the orderby/thenby key values
            for (int i = 0; i < refKeys.Count; i++)
            {
                bool          keyPresent;
                List <String> outOrderByVal = null;
                List <String> outThenByVal  = null;
                //Must find orderby node
                keyPresent = nodeValues.TryGetValue("OrderBy", out outOrderByVal);
                if (outVal != null)
                {
                    outVal.Clear();
                    outVal.AddRange(outOrderByVal);
                }
                else
                {
                    outVal = outOrderByVal;
                }

                if (keyPresent)
                {
                    //thenby nodes are optional
                    nodeValues.TryGetValue("ThenBy", out outThenByVal);
                    if (outThenByVal != null)
                    {
                        outVal.AddRange(outThenByVal);
                    }
                }
                else
                {
                    //OrderBy/ThenBy node not found
                    AstoriaTestLog.WriteLine("OrderBy/ThenBy node not found");
                    return(false);
                }

                //Verify the values
                if (keyPresent)
                {
                    bool valuePresent = false;
                    foreach (String s in outVal)
                    {
                        if (s.Contains("element." + refKeys[i].Name))
                        {
                            valuePresent = true;
                        }
                    }
                    if (!valuePresent)
                    {
                        //RefKey not found in the list
                        AstoriaTestLog.WriteLine("RefKey not found in the  list");
                        return(false);
                    }
                }
            }
            return(true);
        }
Example #29
0
 //Verify the lambda expressions where applicable - in cases like select node
 protected abstract bool VerifyLambda(QueryTreeInfo queryTreeInfo);