コード例 #1
0
ファイル: TrxFileParser.cs プロジェクト: teknologika/stax
        public TestResultCollection processTrxFile(string fileName, bool publishFailures, bool PublishErrorInformation)
        {
            TestResultCollection resultCollection = new TestResultCollection();
            //Holds the contents of the trx file
            string trxFileContents;

            //Read out the contents of the trx file
            using (StreamReader trxReader = new StreamReader(fileName))
            {
                trxFileContents = trxReader.ReadToEnd();
                trxReader.Close();
            }

            //Load the file contents into an XML document object
            XmlDocument trxFileXml = new XmlDocument();
            trxFileXml.LoadXml(trxFileContents);

            //Configure the namespace manager
            XmlNamespaceManager xmlManager = new XmlNamespaceManager(trxFileXml.NameTable);
            xmlManager.AddNamespace("ns", "http://microsoft.com/schemas/VisualStudio/TeamTest/2006");

            //Get the list of unit test result nodes
            XmlNodeList resultNodes = trxFileXml.GetElementsByTagName("UnitTestResult");
            resultCollection.Append(ProcessResultsNode(resultNodes, publishFailures, PublishErrorInformation));

            //Now do the same for Manual tests
            resultNodes = trxFileXml.GetElementsByTagName("ManualTestResult");
            resultCollection.Append(ProcessResultsNode(resultNodes, publishFailures, PublishErrorInformation));

            XmlNodeList definitionNodes = trxFileXml.GetElementsByTagName("TestDefinitions");
            AddWorkItemsToResults(resultCollection, trxFileXml);
            AddExecutionUserToResults(resultCollection, trxFileXml);

            return resultCollection;
        }
コード例 #2
0
ファイル: MainPublisherForm.cs プロジェクト: teknologika/stax
        private void btnOk_Click(object sender, EventArgs e)
        {
            Exception errorCatch = null;
            try
            {
                TestResultCollection allTestResults = new TestResultCollection();
                TrxFileParser trxparser = new TrxFileParser();
                this.Enabled = false;

                if (chkLstTrxFiles.CheckedItems.Count > 0)
                {
                    Settings _settings = new Settings();
                    if (ddlProvider.Text.ToLower() == "mercury")
                    {
                        //resultWriter = MercuryResultWriter.Instance();
                    }
                    else
                    {
                       resultWriter = TFS2010ResultWriter.Instance(_currentProjectContext, cbxCreateTestRun.Checked);
                    }
                    if (resultWriter.Cancelled)
                    {
                        ErrorReportingForm ef = new ErrorReportingForm();
                        ef.txtErrorDetails.Text = "User cancelled";
                        ef.Show();
                    }
                    else
                    {
                        //Show the output form
                        resultsForm = new PublishResults();
                        resultsForm.txtOutput.Text = "";
                        resultsForm.btnOk.Click += new EventHandler(resutlsForm_btnOk_click);
                        resultsForm.Show();
                        //Publish each of the selected trx files
                        resultsForm.SetOutputText("Processing results file...Start");
                        for (int i = 0; i < chkLstTrxFiles.CheckedItems.Count; i++)
                        {
                            allTestResults.Append(trxparser.processTrxFile(txtResultsFolder.Text + @"\" + chkLstTrxFiles.CheckedItems[i].ToString(), publishFailures.Checked, publishErrorInfo.Checked));
                        }
                        resultsForm.SetOutputText("Processing results file...Done.");

                        foreach (TestResult item in allTestResults)
                        {
                            resultsForm.AddResult(resultWriter.UpdateTestResult(item, this.publishFailures.Checked, this.publishInconclusive.Checked, this.publishErrorInfo.Checked));
                        }
                        resultsForm.btnOk.Enabled = true;
                    }
                    this.btnOk.Enabled = false;
                    this.btnCancel.Text = "Close";
                }
            }
            catch (Exception ex)
            {
                errorCatch = ex;
                ErrorReportingForm ef = new ErrorReportingForm();
                ef.txtErrorDetails.Text = errorCatch.Message + errorCatch.StackTrace;
                ef.Show();
                resultsForm.Close();
                this.Close();
            }
            finally
            {
                if (resultWriter != null)
                {
                    resultWriter.Disconnect();
                }
            }
        }