Beispiel #1
0
 public TestVM(int repetitionAftherBadAnswer, int questionAmountAtOnce, Model.Test test)
 {
     prepare(repetitionAftherBadAnswer, questionAmountAtOnce);
     questionList      = testRepository.GetArchQuestionsForTest(test.Ref);
     questionListToUse = takeXRandomQuestions(questionAmountAtOnce);
     QuestionCount     = test.QuestionsCount;
     takeRandomActualQuestion();
 }
Beispiel #2
0
        //properties end

        public TestVM(Model.Test test, int repetitionAtStart, int repetitionAftherBadAnswer, int questionAmountAtOnce)
        {
            prepare(repetitionAftherBadAnswer, questionAmountAtOnce);
            questionList      = prepareQuestions(test, repetitionAtStart);
            QuestionCount     = questionList.Count;
            questionListToUse = takeXRandomQuestions(questionAmountAtOnce);
            takeRandomActualQuestion();
        }
Beispiel #3
0
        private List <Tuple <Question, int> > prepareQuestions(Model.Test test, int repetition)
        {
            List <Tuple <Question, int> > value = new List <Tuple <Question, int> >();

            foreach (Question q in testRepository.GetQuestionsForTest(test.Ref))
            {
                value.Add(new Tuple <Question, int>(q, repetition));
            }
            return(value);
        }
Beispiel #4
0
        //properties end

        public FinishedTestVM(Model.Test test, int questionRepetitionAtStart, int questionRepetitionAftherBAdAnswer, int questionRepetitionAtOnce, int goodAnswersCount, int badAnswersCount)
        {
            this.test = test;
            this.questionRepetitionAtStart         = questionRepetitionAtStart;
            this.questionRepetitionAftherBAdAnswer = questionRepetitionAftherBAdAnswer;
            this.questionRepetitionAtOnce          = questionRepetitionAtOnce;
            GoodAnswersCount = goodAnswersCount;
            BadAnswersCount  = badAnswersCount;

            //modyfikacja wow
        }
Beispiel #5
0
        private void CreateTest(object obj)
        {
            var view          = new TestControlV();
            var testControlVM = new TestControlVM(_repo, RoleId, view);

            view.DataContext = testControlVM;
            view.ShowDialog();
            _test = testControlVM.GetTest();
            if (_test != null)
            {
                OpenTestView();
            }
        }
Beispiel #6
0
        public int InsertATest(string challengeid, string userid)
        {
            OxcoderIFactory.IFactory factory = new OxcoderFactory.SqlSeverFactory();
            OxcoderIDAL.TestInfoIDAL dalad = factory.getTestInstance();
            Model.Test test = new Model.Test();
            test.Test_ID = Guid.NewGuid().ToString();
            test.Test_ChallengeID = challengeid;
            test.Test_UserID = userid;

            OxcoderIDAL.ChallengeInfoIDAL ci = factory.getChallengeInstance();
            ci.UpdateNum(challengeid,1);
            return dalad.InsertATest(test);
        }
Beispiel #7
0
        public int InsertATest(Model.Test test)
        {
            StringBuilder sql = new StringBuilder();

            sql.Append("insert into [Test] (Test_ID,Test_ChallengeID,Test_UserID) values(@Test_ID,@Test_ChallengeID,@Test_UserID)");
            SqlParameter[] par =
            {
                new SqlParameter("@Test_ID",          SqlDbType.VarChar, 50),
                new SqlParameter("@Test_ChallengeID", SqlDbType.VarChar, 50),
                new SqlParameter("@Test_UserID",      SqlDbType.VarChar, 50)
            };
            par[0].Value = test.Test_ID;
            par[1].Value = test.Test_ChallengeID;
            par[2].Value = test.Test_UserID;
            return(Common.DbHelperSQL.ExecuteSql(sql.ToString(), par));
        }
        public ActionResult SubmitTest(Model.Test test)
        {
            int correctAnswers = GradeTest(test);
            var testResult     = new TestResult();


            DateTime date           = DateTime.Now; // will give the date for today
            string   dateWithFormat = date.ToLongDateString();

            testResult.Date           = DateTime.Now;
            testResult.CorrectAnswers = correctAnswers;
            testResult.EmptyAnswers   = EmptyAnswers(test);
            testResult.WrongAnswers   = TESTQUESTIONSCOUNT - (testResult.EmptyAnswers + correctAnswers);
            testResult.Procent        = correctAnswers * 10;
            if (correctAnswers <= 2)
            {
                testResult.Status = "Bad";
                testResult.Grade  = "Слаб(2)";
            }
            else if (correctAnswers <= 4)
            {
                testResult.Status = "Bad";
                testResult.Grade  = "Среден(3)";
            }
            else if (correctAnswers <= 6)
            {
                testResult.Status = "Good";
                testResult.Grade  = "Добър(4)";
            }
            else if (correctAnswers <= 8)
            {
                testResult.Status = "Excellent";
                testResult.Grade  = "Много добър(5)";
            }
            else
            {
                testResult.Status = "Excellent";
                testResult.Grade  = "Отличен(6)";
            }
            testService.InsertResult(test.Id, User.Id, testResult.Grade);
            return(View("TestResult", testResult));
        }
Beispiel #9
0
        public Report Parse(string resultsFile)
        {
            this.resultsFile = resultsFile;

            XDocument doc = XDocument.Load(resultsFile);

            Report report = new Report();

            report.FileName     = Path.GetFileNameWithoutExtension(resultsFile);
            report.AssemblyName = doc.Root.Attribute("name") != null?doc.Root.Attribute("name").Value : null;

            report.TestRunner = TestRunner.NUnit;

            // run-info & environment values -> RunInfo
            var runInfo = CreateRunInfo(doc, report);

            if (runInfo != null)
            {
                report.AddRunInfo(runInfo.Info);
            }

            // report counts
            report.Total = doc.Descendants("test-case").Count();

            report.Passed =
                doc.Root.Attribute("passed") != null
                    ? Int32.Parse(doc.Root.Attribute("passed").Value)
                    : doc.Descendants("test-case").Where(x => x.Attribute("result").Value.Equals("success", StringComparison.CurrentCultureIgnoreCase)).Count();

            report.Failed =
                doc.Root.Attribute("failed") != null
                    ? Int32.Parse(doc.Root.Attribute("failed").Value)
                    : Int32.Parse(doc.Root.Attribute("failures").Value);

            report.Errors =
                doc.Root.Attribute("errors") != null
                    ? Int32.Parse(doc.Root.Attribute("errors").Value)
                    : 0;

            report.Inconclusive =
                doc.Root.Attribute("inconclusive") != null
                    ? Int32.Parse(doc.Root.Attribute("inconclusive").Value)
                    : Int32.Parse(doc.Root.Attribute("inconclusive").Value);

            report.Skipped =
                doc.Root.Attribute("skipped") != null
                    ? Int32.Parse(doc.Root.Attribute("skipped").Value)
                    : Int32.Parse(doc.Root.Attribute("skipped").Value);

            report.Skipped +=
                doc.Root.Attribute("ignored") != null
                    ? Int32.Parse(doc.Root.Attribute("ignored").Value)
                    : 0;

            // report duration
            report.StartTime =
                doc.Root.Attribute("start-time") != null
                    ? doc.Root.Attribute("start-time").Value
                    : doc.Root.Attribute("date").Value + " " + doc.Root.Attribute("time").Value;

            report.EndTime =
                doc.Root.Attribute("end-time") != null
                    ? doc.Root.Attribute("end-time").Value
                    : "";

            // report status messages
            var testSuiteTypeAssembly = doc.Descendants("test-suite")
                                        .Where(x => x.Attribute("result").Value.Equals("Failed") && x.Attribute("type").Value.Equals("Assembly"));

            report.StatusMessage = testSuiteTypeAssembly != null && testSuiteTypeAssembly.Count() > 0
                ? testSuiteTypeAssembly.First().Value
                : "";

            IEnumerable <XElement> suites = doc
                                            .Descendants("test-suite")
                                            .Where(x => x.Attribute("type").Value.Equals("TestFixture", StringComparison.CurrentCultureIgnoreCase));

            suites.AsParallel().ToList().ForEach(ts =>
            {
                var testSuite  = new TestSuite();
                testSuite.Name = ts.Attribute("name").Value;

                // Suite Time Info
                testSuite.StartTime =
                    ts.Attribute("start-time") != null
                        ? ts.Attribute("start-time").Value
                        : string.Empty;

                testSuite.StartTime =
                    String.IsNullOrEmpty(testSuite.StartTime) && ts.Attribute("time") != null
                        ? ts.Attribute("time").Value
                        : testSuite.StartTime;

                testSuite.EndTime =
                    ts.Attribute("end-time") != null
                        ? ts.Attribute("end-time").Value
                        : "";

                // any error messages and/or stack-trace
                var failure = ts.Element("failure");
                if (failure != null)
                {
                    var message = failure.Element("message");
                    if (message != null)
                    {
                        testSuite.StatusMessage = message.Value;
                    }

                    var stackTrace = failure.Element("stack-trace");
                    if (stackTrace != null && !string.IsNullOrWhiteSpace(stackTrace.Value))
                    {
                        testSuite.StatusMessage = string.Format(
                            "{0}\n\nStack trace:\n{1}", testSuite.StatusMessage, stackTrace.Value);
                    }
                }

                // get test suite level categories
                var suiteCategories = this.GetCategories(ts);

                // Test Cases
                ts.Descendants("test-case").AsParallel().ToList().ForEach(tc =>
                {
                    var test        = new Model.Test();
                    test.MethodName = tc.Attribute("methodname").Value;
                    test.Name       = tc.Attribute("name").Value;
                    test.Status     = StatusExtensions.ToStatus(tc.Attribute("result").Value);

                    // main a master list of all status
                    // used to build the status filter in the view
                    report.StatusList.Add(test.Status);

                    // TestCase Time Info
                    test.StartTime =
                        tc.Attribute("start-time") != null
                            ? tc.Attribute("start-time").Value
                            : "";
                    test.StartTime =
                        String.IsNullOrEmpty(test.StartTime) && (tc.Attribute("time") != null)
                            ? tc.Attribute("time").Value
                            : test.StartTime;
                    test.EndTime =
                        tc.Attribute("end-time") != null
                            ? tc.Attribute("end-time").Value
                            : "";
                    //duration
                    string duration = tc.Attribute("duration") != null ? tc.Attribute("duration").Value : "";
                    if (!string.IsNullOrEmpty(duration))
                    {
                        TimeSpan t    = TimeSpan.FromSeconds(Convert.ToDouble(duration));
                        test.Duration = t.ToString(@"hh\:mm\:ss\:fff");
                    }

                    // description
                    var description =
                        tc.Descendants("property")
                        .Where(c => c.Attribute("name").Value.Equals("Description", StringComparison.CurrentCultureIgnoreCase));
                    test.Description =
                        description.Count() > 0
                            ? description.ToArray()[0].Attribute("value").Value
                            : "";

                    // get test case level categories
                    var categories = this.GetCategories(tc);

                    // if this is a parameterized test, get the categories from the parent test-suite
                    var parameterizedTestElement = tc
                                                   .Ancestors("test-suite").ToList()
                                                   .Where(x => x.Attribute("type").Value.Equals("ParameterizedTest", StringComparison.CurrentCultureIgnoreCase))
                                                   .FirstOrDefault();

                    if (null != parameterizedTestElement)
                    {
                        var paramCategories = this.GetCategories(parameterizedTestElement);
                        categories.UnionWith(paramCategories);
                    }

                    //Merge test level categories with suite level categories and add to test and report
                    categories.UnionWith(suiteCategories);
                    test.CategoryList.AddRange(categories);
                    report.CategoryList.AddRange(categories);

                    string delimeter = Environment.NewLine + "====================================================" + Environment.NewLine;
                    // error and other status messages
                    test.StatusMessage =
                        tc.Element("failure") != null
                            ? delimeter + "EXCEPTION MESSAGE: " + Environment.NewLine + tc.Element("failure").Element("message").Value.Trim()
                            : "";
                    test.StatusMessage +=
                        tc.Element("failure") != null
                            ? tc.Element("failure").Element("stack-trace") != null
                                ? delimeter + "EXCEPTION STACKTRACE:" + Environment.NewLine + tc.Element("failure").Element("stack-trace").Value.Trim()
                                : ""
                            : "";

                    test.StatusMessage += tc.Element("reason") != null && tc.Element("reason").Element("message") != null
                        ? tc.Element("reason").Element("message").Value.Trim()
                        : "";

                    // add NUnit console output to the status message
                    test.StatusMessage += tc.Element("output") != null
                     ? delimeter + "EXECUTE STEPS:" + Environment.NewLine + tc.Element("output").Value.Trim() + delimeter
                     : "";

                    //add screenshot links
                    if (tc.Element("output") != null)
                    {
                        MatchCollection matches = Regex.Matches(tc.Element("output").Value.Trim(),
                                                                @"Generated Screenshot:\s(<a.*a>)");
                        foreach (Match match in matches)
                        {
                            if (match.Success)
                            {
                                test.ScreenshotLinks.Add(match.Groups[1].Value);
                            }
                        }
                    }
                    testSuite.TestList.Add(test);
                });

                testSuite.Status = ReportUtil.GetFixtureStatus(testSuite.TestList);

                report.TestSuiteList.Add(testSuite);
            });


            report.TestSuiteList = report.TestSuiteList.OrderBy(ts => ts.Name).ToList();

            //Sort category list so it's in alphabetical order
            report.CategoryList.Sort();

            return(report);
        }
Beispiel #10
0
        public Report Parse(string resultsFile)
        {
            this.resultsFile = resultsFile;

            XDocument doc = XDocument.Load(resultsFile);

            Report report = new Report();

            report.FileName     = Path.GetFileNameWithoutExtension(resultsFile);
            report.AssemblyName = doc.Root.Attribute("name") != null?doc.Root.Attribute("name").Value : null;

            report.TestRunner = TestRunner.NUnit;

            // run-info & environment values -> RunInfo
            var runInfo = CreateRunInfo(doc, report);

            if (runInfo != null)
            {
                report.AddRunInfo(runInfo.Info);
            }

            // report counts
            report.Total = doc.Descendants("test-case").Count();

            report.Passed =
                doc.Root.Attribute("passed") != null
                    ? Int32.Parse(doc.Root.Attribute("passed").Value)
                    : doc.Descendants("test-case").Where(x => x.Attribute("result").Value.Equals("success", StringComparison.CurrentCultureIgnoreCase)).Count();

            report.Failed =
                doc.Root.Attribute("failed") != null
                    ? Int32.Parse(doc.Root.Attribute("failed").Value)
                    : Int32.Parse(doc.Root.Attribute("failures").Value);

            report.Errors =
                doc.Root.Attribute("errors") != null
                    ? Int32.Parse(doc.Root.Attribute("errors").Value)
                    : 0;

            report.Inconclusive =
                doc.Root.Attribute("inconclusive") != null
                    ? Int32.Parse(doc.Root.Attribute("inconclusive").Value)
                    : Int32.Parse(doc.Root.Attribute("inconclusive").Value);

            report.Skipped =
                doc.Root.Attribute("skipped") != null
                    ? Int32.Parse(doc.Root.Attribute("skipped").Value)
                    : Int32.Parse(doc.Root.Attribute("skipped").Value);

            report.Skipped +=
                doc.Root.Attribute("ignored") != null
                    ? Int32.Parse(doc.Root.Attribute("ignored").Value)
                    : 0;

            // report duration
            report.StartTime =
                doc.Root.Attribute("start-time") != null
                    ? doc.Root.Attribute("start-time").Value
                    : doc.Root.Attribute("date").Value + " " + doc.Root.Attribute("time").Value;

            report.EndTime =
                doc.Root.Attribute("end-time") != null
                    ? doc.Root.Attribute("end-time").Value
                    : "";

            // report status messages
            var testSuiteTypeAssembly = doc.Descendants("test-suite")
                                        .Where(x => x.Attribute("result").Value.Equals("Failed") && x.Attribute("type").Value.Equals("Assembly"));

            report.StatusMessage = testSuiteTypeAssembly != null && testSuiteTypeAssembly.Count() > 0
                ? testSuiteTypeAssembly.First().Value
                : "";

            IEnumerable <XElement> suites = doc
                                            .Descendants("test-suite")
                                            .Where(x => x.Attribute("type").Value.Equals("TestFixture", StringComparison.CurrentCultureIgnoreCase));

            suites.AsParallel().ToList().ForEach(ts =>
            {
                var testSuite  = new TestSuite();
                testSuite.Name = ts.Attribute("name").Value;

                // Suite Time Info
                testSuite.StartTime =
                    ts.Attribute("start-time") != null
                        ? ts.Attribute("start-time").Value
                        : string.Empty;

                testSuite.StartTime =
                    String.IsNullOrEmpty(testSuite.StartTime) && ts.Attribute("time") != null
                        ? ts.Attribute("time").Value
                        : testSuite.StartTime;

                testSuite.EndTime =
                    ts.Attribute("end-time") != null
                        ? ts.Attribute("end-time").Value
                        : "";

                // any error messages and/or stack-trace
                var failure = ts.Element("failure");
                if (failure != null)
                {
                    var message = failure.Element("message");
                    if (message != null)
                    {
                        testSuite.StatusMessage = message.Value;
                    }

                    var stackTrace = failure.Element("stack-trace");
                    if (stackTrace != null && !string.IsNullOrWhiteSpace(stackTrace.Value))
                    {
                        testSuite.StatusMessage = string.Format(
                            "{0}\n\nStack trace:\n{1}", testSuite.StatusMessage, stackTrace.Value);
                    }
                }


                // Test Cases
                ts.Descendants("test-case").AsParallel().ToList().ForEach(tc =>
                {
                    var test = new Model.Test();

                    test.Name   = tc.Attribute("name").Value;
                    test.Status = StatusExtensions.ToStatus(tc.Attribute("result").Value);

                    // main a master list of all status
                    // used to build the status filter in the view
                    report.StatusList.Add(test.Status);

                    // TestCase Time Info
                    test.StartTime =
                        tc.Attribute("start-time") != null
                            ? tc.Attribute("start-time").Value
                            : "";
                    test.StartTime =
                        String.IsNullOrEmpty(test.StartTime) && (tc.Attribute("time") != null)
                            ? tc.Attribute("time").Value
                            : test.StartTime;
                    test.EndTime =
                        tc.Attribute("end-time") != null
                            ? tc.Attribute("end-time").Value
                            : "";

                    // description
                    var description =
                        tc.Descendants("property")
                        .Where(c => c.Attribute("name").Value.Equals("Description", StringComparison.CurrentCultureIgnoreCase));
                    test.Description =
                        description.Count() > 0
                            ? description.ToArray()[0].Attribute("value").Value
                            : "";

                    bool hasCategories =
                        tc.Descendants("property")
                        .Where(c => c.Attribute("name").Value.Equals("Category", StringComparison.CurrentCultureIgnoreCase)).Count() > 0;

                    if (hasCategories)
                    {
                        List <XElement> cats = tc
                                               .Descendants("property")
                                               .Where(c => c.Attribute("name").Value.Equals("Category", StringComparison.CurrentCultureIgnoreCase))
                                               .ToList();

                        cats.ForEach(x =>
                        {
                            string cat = x.Attribute("value").Value;

                            test.CategoryList.Add(cat);
                            report.CategoryList.Add(cat);
                        });
                    }

                    // error and other status messages
                    test.StatusMessage =
                        tc.Element("failure") != null
                            ? tc.Element("failure").Element("message").Value.Trim()
                            : "";
                    test.StatusMessage +=
                        tc.Element("failure") != null
                            ? tc.Element("failure").Element("stack-trace") != null
                                ? tc.Element("failure").Element("stack-trace").Value.Trim()
                                : ""
                            : "";

                    test.StatusMessage += tc.Element("reason") != null && tc.Element("reason").Element("message") != null
                        ? tc.Element("reason").Element("message").Value.Trim()
                        : "";

                    // add NUnit console output to the status message
                    test.StatusMessage += tc.Element("output") != null
                     ? tc.Element("output").Value.Trim()
                     : "";

                    testSuite.TestList.Add(test);
                });

                testSuite.Status = ReportUtil.GetFixtureStatus(testSuite.TestList);

                report.TestSuiteList.Add(testSuite);
            });

            return(report);
        }
Beispiel #11
0
 public void DeleteTest(Model.Test test)
 {
     context.Set <Model.Test>().Remove(test);
     context.SaveChanges();
 }
Beispiel #12
0
        public Report Parse(string resultsFile)
        {
            XDocument doc = XDocument.Load(resultsFile);

            Report report = new Report();

            report.FileName   = Path.GetFileNameWithoutExtension(resultsFile);
            report.TestRunner = TestRunner.MSTest2010;

            // run-info & environment values -> RunInfo
            var runInfo = CreateRunInfo(doc, report).Info;

            report.AddRunInfo(runInfo);

            // report counts
            var resultNodes = doc.Descendants(xns + "UnitTestResult");

            report.Total        = resultNodes.Count();
            report.Passed       = resultNodes.Where(x => x.Attribute("outcome").Value.Equals("Passed")).Count();
            report.Failed       = resultNodes.Where(x => x.Attribute("outcome").Value.Equals("Failed")).Count();
            report.Inconclusive = resultNodes
                                  .Where(x =>
                                         x.Attribute("outcome").Value.Equals("Inconclusive") ||
                                         x.Attribute("outcome").Value.Equals("passedButRunAborted") ||
                                         x.Attribute("outcome").Value.Equals("disconnected") ||
                                         x.Attribute("outcome").Value.Equals("notRunnable") ||
                                         x.Attribute("outcome").Value.Equals("warning") ||
                                         x.Attribute("outcome").Value.Equals("pending"))
                                  .Count();
            report.Skipped = resultNodes.Where(x => x.Attribute("outcome").Value.Equals("NotExecuted")).Count();
            report.Errors  = resultNodes
                             .Where(x =>
                                    x.Attribute("outcome").Value.Equals("Passed") ||
                                    x.Attribute("outcome").Value.Equals("Aborted") ||
                                    x.Attribute("outcome").Value.Equals("timeout"))
                             .Count();

            // report duration
            XElement times = doc.Descendants(xns + "Times").First();

            report.StartTime = times.Attribute("start").Value;
            report.EndTime   = times.Attribute("finish").Value;

            // ToDo: add fixtures + tests
            doc.Descendants(xns + "UnitTestResult").AsParallel().ToList().ForEach(tc =>
            {
                var test = new Model.Test();

                test.Name   = tc.Attribute("testName").Value;
                test.Status = StatusExtensions.ToStatus(tc.Attribute("outcome").Value);

                // main a master list of all status
                // used to build the status filter in the view
                report.StatusList.Add(test.Status);

                // TestCase Time Info
                test.StartTime =
                    tc.Attribute("startTime") != null
                        ? tc.Attribute("startTime").Value
                        : "";
                test.EndTime =
                    tc.Attribute("endTime") != null
                        ? tc.Attribute("endTime").Value
                        : "";
                test.Duration = TimeSpan.Parse(tc.Attribute("duration").Value).TotalMilliseconds;

                // error and other status messages
                test.StatusMessage =
                    tc.Element(xns + "Output") != null
                        ? tc.Element(xns + "Output").Value.Trim()
                        : "";

                var unitTestElement = doc.Descendants(xns + "UnitTest").Where(x => x.Attribute("name").Value.Equals(test.Name));
                if (unitTestElement != null && unitTestElement.Count() > 0)
                {
                    var className = unitTestElement.First().Element(xns + "TestMethod").Attribute("className").Value;
                    var testSuite = report.TestSuiteList.SingleOrDefault(t => t.Name.Equals(className));

                    if (testSuite == null)
                    {
                        testSuite      = new TestSuite();
                        testSuite.Name = className;

                        report.TestSuiteList.Add(testSuite);
                    }

                    testSuite.TestList.Add(test);
                    testSuite.Duration += test.Duration;
                    testSuite.Status    = ReportUtil.GetFixtureStatus(testSuite.TestList);
                }
            });

            return(report);
        }
        public Report Parse(string resultsFile)
        {
            var doc = XDocument.Load(resultsFile);

            var report = new Report();

            report.FileName     = Path.GetFileNameWithoutExtension(resultsFile);
            report.AssemblyName = doc.Descendants(xns + "files").First().Descendants(xns + "file").First().Value;
            report.TestParser   = this;

            // run-info & environment values -> RunInfo
            var runInfo = CreateRunInfo(doc, report).Info;

            report.AddRunInfo(runInfo);

            // test cases
            var tests = doc.Descendants(xns + "testStep")
                        .Where(x => x.Attribute("isTestCase").Value.Equals("true", StringComparison.CurrentCultureIgnoreCase));

            // report counts
            var statistics = doc.Descendants(xns + "statistics").First();

            report.Total        = tests.Count();
            report.Passed       = Int32.Parse(statistics.Attribute("passedCount").Value);
            report.Failed       = Int32.Parse(statistics.Attribute("failedCount").Value);
            report.Inconclusive = Int32.Parse(statistics.Attribute("inconclusiveCount").Value);
            report.Skipped      = Int32.Parse(statistics.Attribute("skippedCount").Value);
            report.Errors       = 0;

            // report duration
            XElement testPackageRun = doc.Descendants(xns + "testPackageRun").First();

            report.StartTime = testPackageRun.Attribute("startTime").Value;
            report.EndTime   = testPackageRun.Attribute("endTime").Value;

            var       suitesList = new List <string>();
            TestSuite testSuite  = null;

            tests.AsParallel().ToList().ForEach(tc =>
            {
                var testSuiteName = tc.Attribute("fullName").Value;
                testSuiteName     = testSuiteName.Contains('/')
                    ? testSuiteName.Split('/')[testSuiteName.Split('/').Length - 2]
                    : testSuiteName;

                if (!suitesList.Contains(testSuiteName))
                {
                    testSuite           = new TestSuite();
                    testSuite.Name      = testSuiteName;
                    testSuite.StartTime = tc.Parent.Attribute("startTime").Value;
                    testSuite.EndTime   = tc.Parent.Attribute("endTime").Value;

                    report.TestSuiteList.Add(testSuite);

                    suitesList.Add(testSuiteName);
                }

                var test = new Model.Test();

                test.Name   = tc.Attribute("name").Value;
                test.Status = StatusExtensions.ToStatus(tc.Parent.Descendants(xns + "outcome").First().Attribute("status").Value);

                // main a master list of all status
                // used to build the status filter in the view
                report.AddStatus(test.Status);

                var entry = tc.Descendants(xns + "entry");

                // description
                var description = entry != null
                    ? entry.Where(x => x.Attribute("key").Value.Equals("Description"))
                    : null;
                test.Description = description != null && description.Count() > 0
                    ? description.First().Value
                    : "";

                // error and other status messages
                var ignoreReason = entry != null
                    ? entry.Where(x => x.Attribute("key").Value.Equals("IgnoreReason"))
                    : null;
                test.StatusMessage = ignoreReason != null && ignoreReason.Count() > 0
                    ? ignoreReason.First().Value
                    : "";

                var testLog         = tc.Parent.Descendants(xns + "testLog");
                test.StatusMessage += testLog != null && testLog.Count() > 0
                    ? testLog.First().Value
                    : "";

                // assign categories
                var category = entry != null
                    ? entry.Where(x => x.Attribute("key").Value.Equals("Category"))
                    : null;
                if (category != null && category.Count() > 0)
                {
                    category.ToList().ForEach(s =>
                    {
                        string cat = s.Value;

                        test.CategoryList.Add(cat);
                        report.AddCategory(cat);
                    });
                }

                testSuite.TestList.Add(test);
                testSuite.Status = ReportUtil.GetFixtureStatus(testSuite.TestList);
            });

            return(report);
        }
        public Report Parse(string resultsFile)
        {
            var doc = XDocument.Load(resultsFile);

            var report = new Report();

            report.FileName = Path.GetFileNameWithoutExtension(resultsFile);
            report.AssemblyName = doc.Descendants(xns + "files").First().Descendants(xns + "file").First().Value;
            report.TestParser = this;

            // run-info & environment values -> RunInfo
            var runInfo = CreateRunInfo(doc, report).Info;
            report.AddRunInfo(runInfo);

            // test cases
            var tests = doc.Descendants(xns + "testStep")
                .Where(x => x.Attribute("isTestCase").Value.Equals("true", StringComparison.CurrentCultureIgnoreCase));

            // report counts
            var statistics = doc.Descendants(xns + "statistics").First();
            report.Total = tests.Count();
            report.Passed = Int32.Parse(statistics.Attribute("passedCount").Value);
            report.Failed = Int32.Parse(statistics.Attribute("failedCount").Value);
            report.Inconclusive = Int32.Parse(statistics.Attribute("inconclusiveCount").Value);
            report.Skipped = Int32.Parse(statistics.Attribute("skippedCount").Value);
            report.Errors = 0;

            // report duration
            XElement testPackageRun = doc.Descendants(xns + "testPackageRun").First();
            report.StartTime = testPackageRun.Attribute("startTime").Value;
            report.EndTime = testPackageRun.Attribute("endTime").Value;

            var suitesList = new List<string>();
            TestSuite testSuite = null;

            tests.AsParallel().ToList().ForEach(tc =>
            {
                var testSuiteName = tc.Attribute("fullName").Value;
                testSuiteName = testSuiteName.Contains('/')
                    ? testSuiteName.Split('/')[testSuiteName.Split('/').Length - 2]
                    : testSuiteName;

                if (!suitesList.Contains(testSuiteName))
                {
                    testSuite = new TestSuite();
                    testSuite.Name = testSuiteName;
                    testSuite.StartTime = tc.Parent.Attribute("startTime").Value;
                    testSuite.EndTime = tc.Parent.Attribute("endTime").Value;

                    report.TestSuiteList.Add(testSuite);

                    suitesList.Add(testSuiteName);
                }

                var test = new Model.Test();

                test.Name = tc.Attribute("name").Value;
                test.Status = StatusExtensions.ToStatus(tc.Parent.Descendants(xns + "outcome").First().Attribute("status").Value);

                // main a master list of all status
                // used to build the status filter in the view
                report.AddStatus(test.Status);

                var entry = tc.Descendants(xns + "entry");

                // description
                var description = entry != null
                    ? entry.Where(x => x.Attribute("key").Value.Equals("Description"))
                    : null;
                test.Description =  description != null && description.Count() > 0
                    ? description.First().Value
                    : "";

                // error and other status messages
                var ignoreReason = entry != null
                    ? entry.Where(x => x.Attribute("key").Value.Equals("IgnoreReason"))
                    : null;
                test.StatusMessage = ignoreReason != null && ignoreReason.Count() > 0
                    ? ignoreReason.First().Value
                    : "";

                var testLog = tc.Parent.Descendants(xns + "testLog");
                test.StatusMessage += testLog != null && testLog.Count() > 0
                    ? testLog.First().Value
                    : "";

                // assign categories
                var category = entry != null
                    ? entry.Where(x => x.Attribute("key").Value.Equals("Category"))
                    : null;
                if (category != null && category.Count() > 0)
                {
                    category.ToList().ForEach(s =>
                    {
                        string cat = s.Value;

                        test.CategoryList.Add(cat);
                        report.AddCategory(cat);
                    });
                }

                testSuite.TestList.Add(test);
                testSuite.Status = ReportUtil.GetFixtureStatus(testSuite.TestList);
            });

            return report;
        }
Beispiel #15
0
 public void EditTest(Model.Test test)
 {
     context.Entry <Model.Test>(test).CurrentValues.SetValues(test);
     context.SaveChanges();
 }
Beispiel #16
0
        public Report Parse(string resultsFile)
        {
            this.resultsFile = resultsFile;

            XDocument doc = XDocument.Load(resultsFile);

            Report report = new Report();

            report.FileName = Path.GetFileNameWithoutExtension(resultsFile);
            report.AssemblyName = doc.Root.Attribute("name").Value;
            report.TestRunner = TestRunner.NUnit;

            // run-info & environment values -> RunInfo
            var runInfo = CreateRunInfo(doc, report);
            report.AddRunInfo(runInfo.Info);

            // report counts
            report.Total = doc.Descendants("test-case").Count();

            report.Passed =
                doc.Root.Attribute("passed") != null
                    ? Int32.Parse(doc.Root.Attribute("passed").Value)
                    : doc.Descendants("test-case").Where(x => x.Attribute("result").Value.Equals("success", StringComparison.CurrentCultureIgnoreCase)).Count();

            report.Failed =
                doc.Root.Attribute("failed") != null
                    ? Int32.Parse(doc.Root.Attribute("failed").Value)
                    : Int32.Parse(doc.Root.Attribute("failures").Value);

            report.Errors =
                doc.Root.Attribute("errors") != null
                    ? Int32.Parse(doc.Root.Attribute("errors").Value)
                    : 0;

            report.Inconclusive =
                doc.Root.Attribute("inconclusive") != null
                    ? Int32.Parse(doc.Root.Attribute("inconclusive").Value)
                    : Int32.Parse(doc.Root.Attribute("inconclusive").Value);

            report.Skipped =
                doc.Root.Attribute("skipped") != null
                    ? Int32.Parse(doc.Root.Attribute("skipped").Value)
                    : Int32.Parse(doc.Root.Attribute("skipped").Value);

            report.Skipped +=
                doc.Root.Attribute("ignored") != null
                    ? Int32.Parse(doc.Root.Attribute("ignored").Value)
                    : 0;

            // report duration
            report.StartTime =
                doc.Root.Attribute("start-time") != null
                    ? doc.Root.Attribute("start-time").Value
                    : doc.Root.Attribute("date").Value + " " + doc.Root.Attribute("time").Value;

            report.EndTime =
                doc.Root.Attribute("end-time") != null
                    ? doc.Root.Attribute("end-time").Value
                    : "";

            IEnumerable<XElement> suites = doc
                .Descendants("test-suite")
                .Where(x => x.Attribute("type").Value.Equals("TestFixture", StringComparison.CurrentCultureIgnoreCase));

            suites.AsParallel().ToList().ForEach(ts =>
            {
                var testSuite = new TestSuite();
                testSuite.Name = ts.Attribute("name").Value;

                // Suite Time Info
                testSuite.StartTime =
                    ts.Attribute("start-time") != null
                        ? ts.Attribute("start-time").Value
                        : string.Empty;

                testSuite.StartTime =
                    String.IsNullOrEmpty(testSuite.StartTime) && ts.Attribute("time") != null
                        ? ts.Attribute("time").Value
                        : testSuite.StartTime;

                testSuite.EndTime =
                    ts.Attribute("end-time") != null
                        ? ts.Attribute("end-time").Value
                        : "";

                // any error messages or stack-trace
                testSuite.StatusMessage =
                    ts.Element("failure") != null
                        ? ts.Element("failure").Element("message").Value
                        : "";

                // Test Cases
                ts.Descendants("test-case").AsParallel().ToList().ForEach(tc =>
                {
                    var test = new Model.Test();

                    test.Name = tc.Attribute("name").Value;
                    test.Status = StatusExtensions.ToStatus(tc.Attribute("result").Value);

                    // main a master list of all status
                    // used to build the status filter in the view
                    report.StatusList.Add(test.Status);

                    // TestCase Time Info
                    test.StartTime =
                        tc.Attribute("start-time") != null
                            ? tc.Attribute("start-time").Value
                            : "";
                    test.StartTime =
                        String.IsNullOrEmpty(test.StartTime) && (tc.Attribute("time") != null)
                            ? tc.Attribute("time").Value
                            : test.StartTime;
                    test.EndTime =
                        tc.Attribute("end-time") != null
                            ? tc.Attribute("end-time").Value
                            : "";

                    // description
                    var description =
                        tc.Descendants("property")
                        .Where(c => c.Attribute("name").Value.Equals("Description", StringComparison.CurrentCultureIgnoreCase));
                    test.Description =
                        description.Count() > 0
                            ? description.ToArray()[0].Attribute("value").Value
                            : "";

                    bool hasCategories =
                        tc.Descendants("property")
                        .Where(c => c.Attribute("name").Value.Equals("Category", StringComparison.CurrentCultureIgnoreCase)).Count() > 0;

                    if (hasCategories)
                    {
                        List<XElement> cats = tc
                            .Descendants("property")
                            .Where(c => c.Attribute("name").Value.Equals("Category", StringComparison.CurrentCultureIgnoreCase))
                            .ToList();

                        cats.ForEach(x =>
                        {
                            string cat = x.Attribute("value").Value;

                            test.CategoryList.Add(cat);
                            report.CategoryList.Add(cat);
                        });
                    }

                    // error and other status messages
                    test.StatusMessage =
                        tc.Element("failure") != null
                            ? tc.Element("failure").Element("message").Value
                            : "";
                    test.StatusMessage +=
                        tc.Element("failure") != null
                            ? tc.Element("failure").Element("stack-trace") != null
                                ? tc.Element("failure").Element("stack-trace").Value
                                : ""
                            : "";

                    testSuite.TestList.Add(test);
                });

                testSuite.Status = ReportUtil.GetFixtureStatus(testSuite.TestList);

                report.TestSuiteList.Add(testSuite);
            });

            return report;
        }
Beispiel #17
0
 public void CreateTest(Model.Test test)
 {
     context.Set <Model.Test>().Add(test);
     context.SaveChanges();
 }
Beispiel #18
0
        public Report Parse(string resultsFile)
        {
            _resultsFile = resultsFile;

            var doc = XDocument.Load(resultsFile);

            if (doc.Root == null)
            {
                throw new NullReferenceException();
            }

            var report = new Report
            {
                FileName     = Path.GetFileNameWithoutExtension(resultsFile),
                AssemblyName = doc.Root.Attribute("name") != null?doc.Root.Attribute("name").Value : null,
                TestRunner   = TestRunner.NUnit
            };


            // run-info & environment values -> RunInfo
            var runInfo = CreateRunInfo(doc, report);

            if (runInfo != null)
            {
                report.AddRunInfo(runInfo.Info);
            }

            // report counts
            report.Total = doc.Descendants("test-case").Count();

            report.Passed =
                doc.Root.Attribute("passed") != null
                    ? Int32.Parse(doc.Root.Attribute("passed").Value)
                    : doc.Descendants("test-case").Where(x => x.Attribute("result").Value.Equals("success", StringComparison.CurrentCultureIgnoreCase)).Count();

            report.Failed =
                doc.Root.Attribute("failed") != null
                    ? Int32.Parse(doc.Root.Attribute("failed").Value)
                    : Int32.Parse(doc.Root.Attribute("failures").Value);

            report.Errors =
                doc.Root.Attribute("errors") != null
                    ? Int32.Parse(doc.Root.Attribute("errors").Value)
                    : 0;

            report.Inconclusive =
                doc.Root.Attribute("inconclusive") != null
                    ? Int32.Parse(doc.Root.Attribute("inconclusive").Value)
                    : Int32.Parse(doc.Root.Attribute("inconclusive").Value);

            report.Skipped =
                doc.Root.Attribute("skipped") != null
                    ? Int32.Parse(doc.Root.Attribute("skipped").Value)
                    : Int32.Parse(doc.Root.Attribute("skipped").Value);

            report.Skipped +=
                doc.Root.Attribute("ignored") != null
                    ? Int32.Parse(doc.Root.Attribute("ignored").Value)
                    : 0;

            // report duration
            report.StartTime =
                doc.Root.Attribute("start-time") != null
                    ? doc.Root.Attribute("start-time").Value
                    : doc.Root.Attribute("date").Value + " " + doc.Root.Attribute("time").Value;

            report.EndTime =
                doc.Root.Attribute("end-time") != null
                    ? doc.Root.Attribute("end-time").Value
                    : "";

            // report status messages
            var testSuiteTypeAssembly = doc.Descendants("test-suite")
                                        .Where(x => x.Attribute("result").Value.Equals("Failed") && x.Attribute("type").Value.Equals("Assembly"));

            report.StatusMessage = testSuiteTypeAssembly != null && testSuiteTypeAssembly.Count() > 0
                ? testSuiteTypeAssembly.First().Value
                : "";

            var suites = doc
                         .Descendants("test-suite")
                         .Where(x => x.Attribute("type").Value.Equals("TestFixture", StringComparison.CurrentCultureIgnoreCase));

            suites.AsParallel().ToList().ForEach(ts =>
            {
                var testSuite  = new TestSuite();
                testSuite.Name = ts.Attribute("name").Value;

                // Suite Time Info
                testSuite.StartTime =
                    ts.Attribute("start-time") != null
                        ? ts.Attribute("start-time").Value
                        : string.Empty;

                testSuite.StartTime =
                    String.IsNullOrEmpty(testSuite.StartTime) && ts.Attribute("time") != null
                        ? ts.Attribute("time").Value
                        : testSuite.StartTime;

                testSuite.EndTime =
                    ts.Attribute("end-time") != null
                        ? ts.Attribute("end-time").Value
                        : "";

                // any error messages and/or stack-trace
                var failure = ts.Element("failure");
                if (failure != null)
                {
                    var message = failure.Element("message");
                    if (message != null)
                    {
                        testSuite.StatusMessage = message.Value;
                    }

                    var stackTrace = failure.Element("stack-trace");
                    if (stackTrace != null && !string.IsNullOrWhiteSpace(stackTrace.Value))
                    {
                        testSuite.StatusMessage = string.Format(
                            "{0}\n\nStack trace:\n{1}", testSuite.StatusMessage, stackTrace.Value);
                    }
                }

                var output = ts.Element("output") != null?ts.Element("output").Value:null;
                if (!string.IsNullOrWhiteSpace(output))
                {
                    testSuite.StatusMessage += "\n\nOutput:\n" + output;
                }

                // get test suite level categories
                var suiteCategories = this.GetCategories(ts, false);

                // Test Cases
                ts.Descendants("test-case").AsParallel().ToList().ForEach(tc =>
                {
                    var test = new Model.Test();

                    test.Name   = tc.Attribute("name").Value;
                    test.Status = StatusExtensions.ToStatus(tc.Attribute("result").Value);

                    // main a master list of all status
                    // used to build the status filter in the view
                    report.StatusList.Add(test.Status);

                    // TestCase Time Info
                    test.StartTime =
                        tc.Attribute("start-time") != null
                            ? tc.Attribute("start-time").Value
                            : "";
                    test.StartTime =
                        String.IsNullOrEmpty(test.StartTime) && (tc.Attribute("time") != null)
                            ? tc.Attribute("time").Value
                            : test.StartTime;
                    test.EndTime =
                        tc.Attribute("end-time") != null
                            ? tc.Attribute("end-time").Value
                            : "";

                    // description
                    var description =
                        tc.Descendants("property")
                        .Where(c => c.Attribute("name").Value.Equals("Description", StringComparison.CurrentCultureIgnoreCase));
                    test.Description =
                        description.Count() > 0
                            ? description.ToArray()[0].Attribute("value").Value
                            : "";

                    // get test case level categories
                    var categories = this.GetCategories(tc, true);

                    // if this is a parameterized test, get the categories from the parent test-suite
                    var parameterizedTestElement = tc
                                                   .Ancestors("test-suite").ToList()
                                                   .Where(x => x.Attribute("type").Value.Equals("ParameterizedTest", StringComparison.CurrentCultureIgnoreCase))
                                                   .FirstOrDefault();

                    if (null != parameterizedTestElement)
                    {
                        var paramCategories = this.GetCategories(parameterizedTestElement, false);
                        categories.UnionWith(paramCategories);
                    }

                    //Merge test level categories with suite level categories and add to test and report
                    categories.UnionWith(suiteCategories);
                    test.CategoryList.AddRange(categories);
                    report.CategoryList.AddRange(categories);


                    // error and other status messages
                    test.StatusMessage =
                        tc.Element("failure") != null && tc.Element("failure").Element("message") != null
                            ? tc.Element("failure").Element("message").Value.Trim()
                            : "";
                    test.StatusMessage +=
                        tc.Element("failure") != null
                            ? tc.Element("failure").Element("stack-trace") != null
                                ? tc.Element("failure").Element("stack-trace").Value.Trim()
                                : ""
                            : "";

                    test.StatusMessage += tc.Element("reason") != null && tc.Element("reason").Element("message") != null
                        ? tc.Element("reason").Element("message").Value.Trim()
                        : "";

                    // add NUnit console output to the status message
                    test.StatusMessage += tc.Element("output") != null
                     ? tc.Element("output").Value.Trim()
                     : "";

                    testSuite.TestList.Add(test);
                });

                testSuite.Status = ReportUtil.GetFixtureStatus(testSuite.TestList);

                report.TestSuiteList.Add(testSuite);
            });

            //Sort category list so it's in alphabetical order
            report.CategoryList.Sort();

            return(report);
        }
 public ViewModel()
 {
     Test  = new Model.Test();
     ViAnz = new VisuAnzeigen();
 }
Beispiel #20
0
        public Report Parse(string resultsFile)
        {
            XDocument doc = XDocument.Load(resultsFile);

            Report report = new Report();

            report.FileName = Path.GetFileNameWithoutExtension(resultsFile);
            report.TestRunner = TestRunner.MSTest2010;

            // run-info & environment values -> RunInfo
            var runInfo = CreateRunInfo(doc, report).Info;
            report.AddRunInfo(runInfo);

            // report counts
            var resultNodes = doc.Descendants(xns + "UnitTestResult");
            report.Total = resultNodes.Count();
            report.Passed = resultNodes.Where(x => x.Attribute("outcome").Value.Equals("Passed")).Count();
            report.Failed = resultNodes.Where(x => x.Attribute("outcome").Value.Equals("Failed")).Count();
            report.Inconclusive = resultNodes
                .Where(x =>
                    x.Attribute("outcome").Value.Equals("Inconclusive")
                    || x.Attribute("outcome").Value.Equals("passedButRunAborted")
                    || x.Attribute("outcome").Value.Equals("disconnected")
                    || x.Attribute("outcome").Value.Equals("notRunnable")
                    || x.Attribute("outcome").Value.Equals("warning")
                    || x.Attribute("outcome").Value.Equals("pending"))
                .Count();
            report.Skipped = resultNodes.Where(x => x.Attribute("outcome").Value.Equals("NotExecuted")).Count();
            report.Errors = resultNodes
                .Where(x =>
                    x.Attribute("outcome").Value.Equals("Passed")
                    || x.Attribute("outcome").Value.Equals("Aborted")
                    || x.Attribute("outcome").Value.Equals("timeout"))
                .Count();

            // report duration
            XElement times = doc.Descendants(xns + "Times").First();
            report.StartTime = times.Attribute("start").Value;
            report.EndTime = times.Attribute("finish").Value;

            // ToDo: add fixtures + tests
            doc.Descendants(xns + "UnitTestResult").AsParallel().ToList().ForEach(tc =>
            {
                var test = new Model.Test();

                test.Name = tc.Attribute("testName").Value;
                test.Status = StatusExtensions.ToStatus(tc.Attribute("outcome").Value);

                // main a master list of all status
                // used to build the status filter in the view
                report.StatusList.Add(test.Status);

                // TestCase Time Info
                test.StartTime =
                    tc.Attribute("startTime") != null
                        ? tc.Attribute("startTime").Value
                        : "";
                test.EndTime =
                    tc.Attribute("endTime") != null
                        ? tc.Attribute("endTime").Value
                        : "";

                var timespan = Convert.ToDateTime(test.StartTime) - Convert.ToDateTime(test.EndTime);
                test.Duration = timespan.Milliseconds;

                // error and other status messages
                test.StatusMessage = tc.Element(xns + "Output") != null ? tc.Element(xns + "Output").Value.Trim() : "";

                var unitTestElement = doc.Descendants(xns + "UnitTest").FirstOrDefault(x => x.Attribute("name").Value.Equals(test.Name));

                if (unitTestElement != null)
                {
                    
                    var descriptionElement = unitTestElement.Element(xns + "Description");
                    if (descriptionElement != null)
                    {
                        test.Description = descriptionElement.Value;
                    }

                    var categories = (from testCategory in unitTestElement.Descendants(xns + "TestCategoryItem")
                                          select testCategory.Attributes("TestCategory").Select(x => x.Value).FirstOrDefault()).ToList();
                    
                    test.CategoryList = categories;
                    
                    
                    if (categories.Any())
                    {
                        foreach (var suiteName in categories)
                        {
                            AddTestToSuite(report, test, suiteName);
                        }
                    }
                    else
                    {
                        var suiteName = unitTestElement.Element(xns + "TestMethod").Attribute("className").Value;
                        AddTestToSuite(report, test, suiteName);
                    }
                }
            });

            report.TestSuiteList = report.TestSuiteList.OrderBy(x => x.Name).ToList();

            return report;
        }
Beispiel #21
0
        public Report Parse(string resultsFile)
        {
            XDocument doc = XDocument.Load(resultsFile);

            Report report = new Report();

            report.FileName   = Path.GetFileNameWithoutExtension(resultsFile);
            report.TestRunner = TestRunner.MSTest2010;

            // run-info & environment values -> RunInfo
            var runInfo = CreateRunInfo(doc, report).Info;

            report.AddRunInfo(runInfo);

            // report counts
            var resultNodes = doc.Descendants(xns + "UnitTestResult");

            report.Total        = resultNodes.Count();
            report.Passed       = resultNodes.Where(x => x.Attribute("outcome").Value.Equals("Passed")).Count();
            report.Failed       = resultNodes.Where(x => x.Attribute("outcome").Value.Equals("Failed")).Count();
            report.Inconclusive = resultNodes
                                  .Where(x =>
                                         x.Attribute("outcome").Value.Equals("Inconclusive") ||
                                         x.Attribute("outcome").Value.Equals("passedButRunAborted") ||
                                         x.Attribute("outcome").Value.Equals("disconnected") ||
                                         x.Attribute("outcome").Value.Equals("notRunnable") ||
                                         x.Attribute("outcome").Value.Equals("warning") ||
                                         x.Attribute("outcome").Value.Equals("pending"))
                                  .Count();
            report.Skipped = resultNodes.Where(x => x.Attribute("outcome").Value.Equals("NotExecuted")).Count();
            report.Errors  = resultNodes
                             .Where(x =>
                                    x.Attribute("outcome").Value.Equals("Passed") ||
                                    x.Attribute("outcome").Value.Equals("Aborted") ||
                                    x.Attribute("outcome").Value.Equals("timeout"))
                             .Count();

            // report duration
            XElement times = doc.Descendants(xns + "Times").First();

            report.StartTime = times.Attribute("start").Value;
            report.EndTime   = times.Attribute("finish").Value;

            // ToDo: add fixtures + tests
            doc.Descendants(xns + "UnitTestResult").AsParallel().ToList().ForEach(tc =>
            {
                var test = new Model.Test();

                test.Name   = tc.Attribute("testName").Value;
                test.Status = StatusExtensions.ToStatus(tc.Attribute("outcome").Value);

                // main a master list of all status
                // used to build the status filter in the view
                report.StatusList.Add(test.Status);

                // TestCase Time Info
                test.StartTime =
                    tc.Attribute("startTime") != null
                        ? tc.Attribute("startTime").Value
                        : "";
                test.EndTime =
                    tc.Attribute("endTime") != null
                        ? tc.Attribute("endTime").Value
                        : "";

                var timespan  = Convert.ToDateTime(test.StartTime) - Convert.ToDateTime(test.EndTime);
                test.Duration = timespan.Milliseconds;

                // error and other status messages
                test.StatusMessage = tc.Element(xns + "Output") != null ? tc.Element(xns + "Output").Value.Trim() : "";

                var unitTestElement = doc.Descendants(xns + "UnitTest").FirstOrDefault(x => x.Attribute("name").Value.Equals(test.Name));

                if (unitTestElement != null)
                {
                    var descriptionElement = unitTestElement.Element(xns + "Description");
                    if (descriptionElement != null)
                    {
                        test.Description = descriptionElement.Value;
                    }

                    var categories = (from testCategory in unitTestElement.Descendants(xns + "TestCategoryItem")
                                      select testCategory.Attributes("TestCategory").Select(x => x.Value).FirstOrDefault()).ToList();

                    test.CategoryList = categories;


                    if (categories.Any())
                    {
                        foreach (var suiteName in categories)
                        {
                            AddTestToSuite(report, test, suiteName);
                        }
                    }
                    else
                    {
                        var suiteName = unitTestElement.Element(xns + "TestMethod").Attribute("className").Value;
                        AddTestToSuite(report, test, suiteName);
                    }
                }
            });

            report.TestSuiteList = report.TestSuiteList.OrderBy(x => x.Name).ToList();

            return(report);
        }
Beispiel #22
0
        public Report Parse(string resultsFile)
        {
            XDocument doc = XDocument.Load(resultsFile);

            Report report = new Report();

            report.FileName = Path.GetFileNameWithoutExtension(resultsFile);
            report.TestRunner = TestRunner.MSTest2010;

            // run-info & environment values -> RunInfo
            var runInfo = CreateRunInfo(doc, report).Info;
            report.AddRunInfo(runInfo);

            // report counts
            var resultNodes = doc.Descendants(xns + "UnitTestResult");
            report.Total = resultNodes.Count();
            report.Passed = resultNodes.Where(x => x.Attribute("outcome").Value.Equals("Passed")).Count();
            report.Failed = resultNodes.Where(x => x.Attribute("outcome").Value.Equals("Failed")).Count();
            report.Inconclusive = resultNodes
                .Where(x => 
                    x.Attribute("outcome").Value.Equals("Inconclusive") 
                    || x.Attribute("outcome").Value.Equals("passedButRunAborted") 
                    || x.Attribute("outcome").Value.Equals("disconnected") 
                    || x.Attribute("outcome").Value.Equals("notRunnable") 
                    || x.Attribute("outcome").Value.Equals("warning") 
                    || x.Attribute("outcome").Value.Equals("pending"))
                .Count();
            report.Skipped = resultNodes.Where(x => x.Attribute("outcome").Value.Equals("NotExecuted")).Count();
            report.Errors = resultNodes
                .Where(x => 
                    x.Attribute("outcome").Value.Equals("Passed") 
                    || x.Attribute("outcome").Value.Equals("Aborted") 
                    || x.Attribute("outcome").Value.Equals("timeout"))
                .Count();

            // report duration
            XElement times = doc.Descendants(xns + "Times").First();
            report.StartTime = times.Attribute("start").Value;
            report.EndTime = times.Attribute("finish").Value;

            // ToDo: add fixtures + tests
            doc.Descendants(xns + "UnitTestResult").AsParallel().ToList().ForEach(tc =>
            {
                var test = new Model.Test();

                test.Name = tc.Attribute("testName").Value;
                test.Status = StatusExtensions.ToStatus(tc.Attribute("outcome").Value);

                // main a master list of all status
                // used to build the status filter in the view
                report.StatusList.Add(test.Status);

                // TestCase Time Info
                test.StartTime =
                    tc.Attribute("startTime") != null
                        ? tc.Attribute("startTime").Value
                        : "";
                test.EndTime =
                    tc.Attribute("endTime") != null
                        ? tc.Attribute("endTime").Value
                        : "";
                test.Duration = TimeSpan.Parse(tc.Attribute("duration").Value).TotalMilliseconds;

                // error and other status messages
                test.StatusMessage =
                    tc.Element(xns + "Output") != null
                        ? tc.Element(xns + "Output").Value.Trim()
                        : "";

                var unitTestElement = doc.Descendants(xns + "UnitTest").Where(x => x.Attribute("name").Value.Equals(test.Name));
                if (unitTestElement != null && unitTestElement.Count() > 0)
                {
                    var className = unitTestElement.First().Element(xns + "TestMethod").Attribute("className").Value;
                    var testSuite = report.TestSuiteList.SingleOrDefault(t => t.Name.Equals(className));

                    if (testSuite == null)
                    {
                        testSuite = new TestSuite();
                        testSuite.Name = className;

                        report.TestSuiteList.Add(testSuite);
                    }

                    testSuite.TestList.Add(test);
                    testSuite.Duration += test.Duration;
                    testSuite.Status = ReportUtil.GetFixtureStatus(testSuite.TestList);
                }
            });

            return report;
        }