Esempio n. 1
0
        public static void CreateReportFromFile(string path)
        {
            IReporter reporter = null;

            try
            {
                reporter = ReporterFactory.Build(TestingFramework.NUnit, new TestDataProvider());
                var testRuns = GetTestRunsListFromFile(path, reporter.Logger);
                foreach (var ghprTestCase in testRuns.Where(t => t.GhprTestScreenshots.Any()))
                {
                    foreach (var screenshot in ghprTestCase.GhprTestScreenshots)
                    {
                        reporter.DataWriterService.SaveScreenshot(screenshot);
                    }
                }
                reporter.GenerateFullReport(testRuns.Select(tr => new KeyValuePair <TestRunDto, TestOutputDto>(tr.GhprTestRun, tr.GhprTestOutput)).ToList());
                reporter.CleanUpJob();
                reporter.TearDown();
            }
            catch (Exception ex)
            {
                reporter?.Logger.Exception("Exception in CreateReportFromFile", ex);
            }
        }
        public void OnTestEvent(string report)
        {
            var eventTime = DateTime.UtcNow;
            var xmlNode   = XmlHelper.CreateXmlNode(report);

            switch (xmlNode.Name)
            {
            case "start-run":
            {
                var cmd      = Environment.CommandLine;
                var args     = Environment.GetCommandLineArgs();
                var projName = args.Length >= 2 ? args[1] : cmd;
                Reporter = ReporterFactory.Build(TestingFramework.NUnit, new TestDataProvider(), projName);
                Reporter.RunStarted();
                _testCases  = new List <GhprTestCase>();
                _testSuites = new List <GhprTestSuite>();
                break;
            }

            case "start-test":
            {
                var testRun = TestRunHelper.GetTestRunOnStarted(xmlNode, eventTime, Reporter.Logger);
                Reporter.TestStarted(testRun.GhprTestRun);
                break;
            }

            case "test-case":
            {
                var testCase = TestRunHelper.GetTestRunOnFinished(xmlNode, eventTime, Reporter.Logger);
                testCase.GhprTestOutput.TestOutputInfo.Date = eventTime;
                foreach (var screenshot in testCase.GhprTestScreenshots)
                {
                    var testScreenshotInfo = Reporter.DataWriterService.SaveScreenshot(screenshot);
                    if (testCase.GhprTestRun.Screenshots.All(s => s.Date != screenshot.TestScreenshotInfo.Date))
                    {
                        testCase.GhprTestRun.Screenshots.Add(testScreenshotInfo);
                    }
                }
                Reporter.TestFinished(testCase.GhprTestRun, testCase.GhprTestOutput);
                _testCases.Add(testCase);
                break;
            }

            case "test-suite":
            {
                var testSuite = TestRunHelper.GetTestSuite(xmlNode);
                _testSuites.Add(testSuite);
                var tests = _testCases.Where(tc => tc.ParentId.Equals(testSuite.Id) && !tc.ParentId.Equals(""))
                            .ToList();
                var childSuites = _testSuites
                                  .Where(ts => ts.ParentId.Equals(testSuite.Id) && !ts.ParentId.Equals("") && ts.Type.Equals("ParameterizedFixture")).ToList();
                foreach (var suite in childSuites)
                {
                    tests.AddRange(_testCases.Where(tc => tc.ParentId.Equals(suite.Id) && !tc.ParentId.Equals("")));
                }
                foreach (var test in tests)
                {
                    test.GhprTestOutput.SuiteOutput = testSuite.Output;
                    Reporter.DataWriterService.UpdateTestOutput(test.GhprTestRun.TestInfo, test.GhprTestOutput);
                }

                break;
            }

            case "test-run":
            {
                Reporter.RunFinished();
                Reporter.CleanUpJob();
                Reporter.TearDown();
                break;
            }
            }
        }
Esempio n. 3
0
        public void OnTestEvent(string report)
        {
            var eventTime = DateTime.Now;
            var xmlNode   = XmlHelper.CreateXmlNode(report);

            switch (xmlNode.Name)
            {
            case "start-run":
            {
                Reporter.RunStarted();
                _testCases  = new List <GhprTestCase>();
                _testSuites = new List <GhprTestSuite>();
                break;
            }

            case "start-test":
            {
                var testRun = TestRunHelper.GetTestRunOnStarted(xmlNode, eventTime, Reporter.Logger);
                Reporter.TestStarted(testRun.GhprTestRun);
                break;
            }

            case "test-case":
            {
                var testCase = TestRunHelper.GetTestRunOnFinished(xmlNode, eventTime, Reporter.Logger);
                testCase.GhprTestOutput.TestOutputInfo.Date = eventTime;
                foreach (var screenshot in testCase.GhprTestScreenshots)
                {
                    var testScreenshotInfo = Reporter.DataWriterService.SaveScreenshot(screenshot);
                    testCase.GhprTestRun.Screenshots.Add(testScreenshotInfo);
                }
                Reporter.TestFinished(testCase.GhprTestRun, testCase.GhprTestOutput);
                _testCases.Add(testCase);
                break;
            }

            case "test-suite":
            {
                var testSuite = TestRunHelper.GetTestSuite(xmlNode);
                _testSuites.Add(testSuite);
                var tests = _testCases.Where(tc => tc.ParentId.Equals(testSuite.Id) && !tc.ParentId.Equals(""))
                            .ToList();
                var childSuites = _testSuites
                                  .Where(ts => ts.ParentId.Equals(testSuite.Id) && !ts.ParentId.Equals("") && ts.Type.Equals("ParameterizedFixture")).ToList();
                foreach (var suite in childSuites)
                {
                    tests.AddRange(_testCases.Where(tc => tc.ParentId.Equals(suite.Id) && !tc.ParentId.Equals("")));
                }
                foreach (var test in tests)
                {
                    test.GhprTestOutput.SuiteOutput = testSuite.Output;
                    Reporter.DataWriterService.UpdateTestOutput(test.GhprTestRun.TestInfo, test.GhprTestOutput);
                }

                break;
            }

            case "test-run":
            {
                Reporter.RunFinished();
                Reporter.CleanUpJob();
                Reporter.TearDown();
                break;
            }
            }
        }