Exemplo n.º 1
0
        public static void PraseSingleTestCase(string caseXml)
        {
            XDocument Xml    = XDocument.Parse(caseXml);
            string    caseID = Xml.Root.Attribute("name").Value;
            var       XStep  = Xml.Root.XPathSelectElements("//Step").ToList();

            XStep.Sort((x, y) =>
            {
                return(int.Parse(x.Attribute("order").Value)
                       .CompareTo(int.Parse(y.Attribute("order").Value)));
            });
            //Construct data sourse
            foreach (var Case in XStep)
            {
                string id        = string.Empty;
                string name      = Case.Attribute("name").Value;
                string order     = Case.Attribute("order").Value;
                string desc      = Case.Attribute("desc").Value;
                string stepName  = string.Empty;
                string stepValue = string.Empty;
                Dictionary <string, string> attribute = new Dictionary <string, string>();
                foreach (var Step in Case.Elements())
                {
                    stepName  = Step.Attribute("name").Value;
                    stepValue = Step.Attribute("value").Value;
                    if (stepName == "SID")
                    {
                        id = stepValue;
                        continue;
                    }
                    try
                    {
                        attribute.Add(stepName.ToLower(), stepValue);
                    }
                    catch
                    {
                        string error = string.Format("删除第{0}条案例,第{1}步骤后重试", caseID, order);
                        Console.WriteLine(error);
                        throw new Exception(error);
                    }
                }
                object parameter = new
                {
                    Step = new Dictionary <string, string> {
                        { "caseID", caseID },
                        { "id", id },
                        { "name", name },
                        { "order", order },
                        { "desc", desc }
                    },
                    Parameter = attribute
                };
                StepDataSourse.Add(id, parameter);
            }
        }