public void Collect()
        {
            RunData a = new RunData();
            RunData b = new RunData();
            RunData c = new RunData();
            IList<RunData> items = new List<RunData> { a, b, c };
            ResultFile fileA = new ResultFile();
            ResultFile fileB = new ResultFile();
            ResultFile fileC = new ResultFile();
            Stream streamA = Stub<Stream>();
            Stream streamB = Stub<Stream>();
            Stream streamC = Stub<Stream>();

            using (Ordered())
            {
                fileHelper.Expect(m => m.OpenTrxFile(a)).Return(streamA);
                trxParser.Expect(m => m.Parse(streamA)).Return(fileA);
                fileHelper.Expect(m => m.OpenTrxFile(b)).Return(streamB);
                trxParser.Expect(m => m.Parse(streamB)).Return(fileB);
                fileHelper.Expect(m => m.OpenTrxFile(c)).Return(streamC);
                trxParser.Expect(m => m.Parse(streamC)).Return(fileC);
            }

            IList<ResultFile> actual = VerifyTarget(() => target.Collect(items));
            Assert.AreEqual(fileA, actual[0]);
            Assert.AreEqual(fileB, actual[1]);
            Assert.AreEqual(fileC, actual[2]);
        }
Ejemplo n.º 2
0
        private void ExtractDefinitions(XmlReader reader, ResultFile trx)
        {
            if (reader.ReadToFollowing("TestDefinitions"))
            {
                if (reader.ReadToDescendant("UnitTest"))
                {
                    do
                    {
                        var testId = Guid.Parse(reader.GetAttribute("id"));
                        var tempResult = trx.Results.First(result => result.TestId == testId);
                        tempResult.Storage = reader.GetAttribute("storage");

                        if (reader.ReadToFollowing("TestMethod"))
                        {
                            tempResult.CodeBase = reader.GetAttribute("codeBase");
                            tempResult.AdapterTypeName = reader.GetAttribute("adapterTypeName");
                            tempResult.ClassName = reader.GetAttribute("className");
                        }

                        reader.ReadToNextSibling("UnitTest");
                    }
                    while (reader.ReadToNextSibling("UnitTest"));
                }
            }
        }
Ejemplo n.º 3
0
        public ResultFile Parse(Stream stream)
        {
            ResultFile trx = new ResultFile { Results = new List<TestResult>(), Summary = new ResultSummary(), StdOut = new List<string>() };

            using (XmlReader reader = XmlReader.Create(stream))
            {
                ExtractTestRunInfo(reader, trx);
                ExtractTimes(reader, trx);
                ExtractTestSettings(reader, trx);
                ExtractResults(reader, trx);
                ExtractDefinitions(reader, trx);
                ExtractSummary(reader, trx);
            }

            return trx;
        }
Ejemplo n.º 4
0
        private void ExtractResults(XmlReader reader, ResultFile trx)
        {
            if (reader.ReadToFollowing("Results"))
            {
                if (reader.ReadToDescendant("UnitTestResult"))
                {
                    do
                    {
                        TestResult item = new TestResult();
                        item.ExecutionId = Guid.Parse(reader.GetAttribute("executionId"));
                        item.TestId = Guid.Parse(reader.GetAttribute("testId"));
                        item.TestName = reader.GetAttribute("testName");
                        item.Duration = reader.GetAttribute("duration");
                        item.Outcome = reader.GetAttribute("outcome");
                        item.TestListId = Guid.Parse(reader.GetAttribute("testListId"));
                        item.ComputerName = reader.GetAttribute("computerName");
                        item.StartTime = reader.GetAttribute("startTime");
                        item.EndTime = reader.GetAttribute("endTime");
                        item.RelativeResultDirectory = Guid.Parse(reader.GetAttribute("relativeResultsDirectory"));

                        using (XmlReader errorReader = reader.ReadSubtree())
                        {
                            if (errorReader.ReadToFollowing("Message"))
                            {
                                item.ErrorMessage = reader.ReadElementContentAsString();
                                errorReader.ReadToNextSibling("StackTrace");
                                item.StackTrace = errorReader.ReadElementContentAsString();
                            }
                        }

                        trx.Results.Add(item);
                    }
                    while (reader.ReadToNextSibling("UnitTestResult"));
                }
            }
        }
Ejemplo n.º 5
0
        private void ExtractSummary(XmlReader reader, ResultFile trx)
        {
            if (reader.ReadToFollowing("ResultSummary"))
            {
                ResultSummary item = trx.Summary;
                item.Outcome = reader.GetAttribute("outcome");
                if (reader.ReadToFollowing("Counters"))
                {
                    item.Total = int.Parse(reader.GetAttribute("total"));
                    item.Executed = int.Parse(reader.GetAttribute("executed"));
                    item.Passed = int.Parse(reader.GetAttribute("passed"));
                    item.Failed = int.Parse(reader.GetAttribute("failed"));
                    item.Error = int.Parse(reader.GetAttribute("error"));
                    item.Timeout = int.Parse(reader.GetAttribute("timeout"));
                    item.Aborted = int.Parse(reader.GetAttribute("aborted"));
                    item.Inconclusive = int.Parse(reader.GetAttribute("inconclusive"));
                    item.PassedButRunAborted =
                        int.Parse(reader.GetAttribute("passedButRunAborted"));
                    item.NotRunnable = int.Parse(reader.GetAttribute("notRunnable"));
                    item.NotExecuted = int.Parse(reader.GetAttribute("notExecuted"));
                    item.Disconnected = int.Parse(reader.GetAttribute("disconnected"));
                    item.Warning = int.Parse(reader.GetAttribute("warning"));
                    item.Completed = int.Parse(reader.GetAttribute("completed"));
                    item.InProgress = int.Parse(reader.GetAttribute("inProgress"));
                    item.Pending = int.Parse(reader.GetAttribute("pending"));
                }

                if (reader.ReadToFollowing("StdOut"))
                {
                    do
                    {
                        trx.StdOut.Add(reader.ReadElementContentAsString());
                    }
                    while (reader.ReadToNextSibling("StdOut"));
                }
            }
        }
Ejemplo n.º 6
0
 private void ExtractTimes(XmlReader reader, ResultFile trx)
 {
     if (reader.ReadToFollowing("Times"))
     {
         trx.Summary.StartTime = DateTime.Parse(reader.GetAttribute("start"), CultureInfo.InvariantCulture);
         trx.Summary.FinishTime = DateTime.Parse(reader.GetAttribute("finish"), CultureInfo.InvariantCulture);
     }
 }
Ejemplo n.º 7
0
 private void ExtractTestSettings(XmlReader reader, ResultFile trx)
 {
     if (reader.ReadToFollowing("Deployment"))
     {
         trx.RunDeploymentRoot = reader.GetAttribute("runDeploymentRoot");
     }
 }
Ejemplo n.º 8
0
 private void ExtractTestRunInfo(XmlReader reader, ResultFile trx)
 {
     if (reader.ReadToFollowing("TestRun"))
     {
         trx.Summary.Name = reader.GetAttribute("name");
         trx.Summary.RunUser = reader.GetAttribute("runUser");
     }
 }