示例#1
0
 private void LoadPlan()
 {
     if (openPlanFileDialog.ShowDialog() == DialogResult.OK)
     {
         XmlDocument xmlDocument = new XmlDocument();
         xmlDocument.Load(openPlanFileDialog.FileName);
         ShowPlan showPlan = ShowPlan.FromXml(xmlDocument);
         showPlanControl.ShowPlan = showPlan;
     }
 }
示例#2
0
        public static TestDefinition FromXml(XmlDocument xmlDocument)
        {
            TestDefinition result = new TestDefinition();

            result.CommandText = xmlDocument.SelectSingleNode("/test/sql").InnerText;

            XmlNode expectedRuntimeErrorNode = xmlDocument.SelectSingleNode("/test/expectedRuntimeError");

            if (expectedRuntimeErrorNode != null)
            {
                result.ExpectedRuntimeError = expectedRuntimeErrorNode.InnerText;
            }

            XmlNode expectedErrorsNode = xmlDocument.SelectSingleNode("/test/expectedErrors");

            if (expectedErrorsNode != null)
            {
                List <CompilationError> errorList = new List <CompilationError>();
                foreach (XmlNode expectedErrorNode in expectedErrorsNode.SelectNodes("expectedError"))
                {
                    ErrorId          errorId          = (ErrorId)Enum.Parse(typeof(ErrorId), expectedErrorNode.Attributes["id"].Value);
                    string           errorText        = expectedErrorNode.Attributes["text"].Value;
                    CompilationError compilationError = new CompilationError(SourceRange.Empty, errorId, errorText);
                    errorList.Add(compilationError);
                }

                result.ExpectedCompilationErrors = errorList.ToArray();
            }

            XmlNode expectedResultsNode = xmlDocument.SelectSingleNode("/test/expectedResults");

            if (expectedResultsNode != null)
            {
                using (StringReader stringReader = new StringReader(expectedResultsNode.InnerXml))
                {
                    DataSet dataSet = new DataSet();
                    dataSet.ReadXml(stringReader);
                    result.ExpectedResults = dataSet.Tables[0];
                }
            }

            XmlNode expectedPlanNode = xmlDocument.SelectSingleNode("/test/expectedPlan");

            if (expectedPlanNode != null)
            {
                result.ExpectedPlan = ShowPlan.FromXml(expectedPlanNode);
            }

            return(result);
        }
示例#3
0
        private void ImportTestDefinition()
        {
            if (openTestDefinitionFileDialog.ShowDialog() == DialogResult.OK)
            {
                Text = String.Format("NQuery - [{0}]", Path.GetFileName(openTestDefinitionFileDialog.FileName));
                saveTestDefinitionFileDialog.FileName = openTestDefinitionFileDialog.FileName;

                string query;
                List <CompilationError> errorList = new List <CompilationError>();
                string   runtimeError             = null;
                DataSet  dataSet  = null;
                ShowPlan showPlan = null;

                #region XML Handling

                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.Load(openTestDefinitionFileDialog.FileName);

                query = xmlDocument.SelectSingleNode("/test/sql").InnerText;

                XmlNode expectedRuntimeErrorNode = xmlDocument.SelectSingleNode("/test/expectedRuntimeError");
                if (expectedRuntimeErrorNode != null)
                {
                    runtimeError = expectedRuntimeErrorNode.InnerText;
                }

                XmlNode expectedErrorsNode = xmlDocument.SelectSingleNode("/test/expectedErrors");
                if (expectedErrorsNode != null)
                {
                    foreach (XmlNode expectedErrorNode in expectedErrorsNode.SelectNodes("expectedError"))
                    {
                        ErrorId          errorId          = (ErrorId)Enum.Parse(typeof(ErrorId), expectedErrorNode.Attributes["id"].Value);
                        string           errorText        = expectedErrorNode.Attributes["text"].Value;
                        CompilationError compilationError = new CompilationError(SourceRange.Empty, errorId, errorText);
                        errorList.Add(compilationError);
                    }
                }

                XmlNode expectedResultsNode = xmlDocument.SelectSingleNode("/test/expectedResults");
                if (expectedResultsNode != null)
                {
                    dataSet = new DataSet();
                    using (StringReader stringReader = new StringReader(expectedResultsNode.InnerXml))
                    {
                        dataSet.ReadXml(stringReader);
                    }
                }

                XmlNode expectedPlanNode = xmlDocument.SelectSingleNode("/test/expectedPlan");
                if (expectedPlanNode != null)
                {
                    showPlan = ShowPlan.FromXml(expectedPlanNode);
                }

                #endregion

                ClearErrors();
                resultsDataGridView.DataSource = null;
                showPlanControl.ShowPlan       = null;

                syntaxEditor.Text = query;
                if (runtimeError != null)
                {
                    LoadErrors(runtimeError);
                }
                LoadErrors(errorList);
                if (dataSet != null)
                {
                    LoadResults(dataSet.Tables[0]);
                }
                if (showPlan != null)
                {
                    showPlanControl.ShowPlan = showPlan;
                }
            }
        }