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);
        }
示例#2
0
        // Generate the next random query to test
        public void Next()
        {
            // Choose a random Query component to test
            this.queryComponent = Enum.GetValues(typeof(QueryComponent)).Cast <QueryComponent>().Choose();
            AstoriaTestLog.WriteLine("Testing.... " + this.queryComponent.ToString());

            // Idenity the queryComponents corresponding verification class
            ConcretePatternDictionary patternDictionary = new ConcretePatternDictionary();

            this.pattern = patternDictionary.GetPattern(this.queryComponent);

            // Build the actual query tree for the queryComponent
            this.pattern.Build(this);
        }
示例#3
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;
        }
示例#4
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;
        }
示例#5
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);
        }
示例#7
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);
        }
示例#8
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);
        }
示例#9
0
        public void VerifyService()
        {
            // for call logging, we need the directory to exist, and the service doesn't necessarily have permission to create it
            // TODO: find some better, common place to put this for IIS, WebServiceHost, etc. Right now this is the best spot
#if !ClientSKUFramework
            IOUtil.EnsureEmptyDirectoryExists(Path.Combine(DestinationFolder, CallOrder.APICallLog.DirectoryName));
#endif

            const int retryCount = 10;
            const int sleepTime  = 6000;

            AstoriaTestLog.WriteLineIgnore("Verifying web service: " + this.ServiceUri);

            HttpWebRequest  request      = null;
            HttpWebResponse response     = null;
            WebException    webException = null;

            for (int count = 0; count < retryCount; count++)
            {
                try
                {
                    request = (HttpWebRequest)HttpWebRequest.Create(this.ServiceUri + "/$metadata");
                    request.UseDefaultCredentials = true;
                    response = (HttpWebResponse)request.GetResponse();
                    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                        reader.ReadToEnd();

                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        AstoriaTestLog.WriteLineIgnore("Service verified.");
                        return;
                    }
                    else
                    {
                        // can this happen without throwing?
                        AstoriaTestLog.WriteLine("\tUnexpected status code: " + response.StatusCode);
                    }
                }
                catch (Exception e)
                {
                    string indent = "\t";
                    while (e != null)
                    {
                        if (e is WebException)
                        {
                            webException = e as WebException;
                        }

                        AstoriaTestLog.WriteLine(indent + e.GetType().Name + ": " + e.Message);
                        indent += "\t";
                        e       = e.InnerException;
                    }
                }
                Thread.Sleep(sleepTime);
            }

            if (webException != null)
            {
                AstoriaTestLog.TraceLine("Web exception:");
                AstoriaTestLog.TraceLine(webException.ToString());
                if (webException.Response != null)
                {
                    string exceptionPayload;
                    using (StreamReader reader = new StreamReader(webException.Response.GetResponseStream()))
                        exceptionPayload = reader.ReadToEnd();
                    AstoriaTestLog.TraceLine("Exception Payload:");
                    AstoriaTestLog.TraceLine(exceptionPayload);
                }
            }

            AstoriaTestLog.FailAndThrow("Service could not be verified.");
        }