public int AddTestSetRecord() { // Grab the build of the environment we're testing string build = GetBuildNumber(); // Log a record to indicate we're starting up the testing testRun = new TestRun() { TestDate = DateTime.Now, Build = build, Status = RunStatus.Initializing, TestWasAborted = false, TestWasCancelled = false, TestConfiguration = testConfiguration, }; context.TestRunSet.Add(testRun); // persist to the database SaveChanges(); // Clear the first test run flag this.firstTest = true; return testRun.Id; }
/// <summary> /// Adds a test result to the database /// </summary> /// <param name="test">Test result</param> public void AddTestResult(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestResult test) { if (firstTest) { firstTest = false; // If the testRun record was already created then grab it else create a new one int testRunId; if (!String.IsNullOrEmpty(GetParameter("PnPTestRunId")) && Int32.TryParse(GetParameter("PnPTestRunId"), out testRunId)) { testRun = context.TestRunSet.Find(testRunId); } else { AddTestSetRecord(); } // Bring status to "running" testRun.Status = RunStatus.Running; } // Store the test result TestResult tr = new TestResult() { ComputerName = test.ComputerName, TestCaseName = !string.IsNullOrEmpty(test.DisplayName) ? test.DisplayName : test.TestCase.FullyQualifiedName, Duration = test.Duration, ErrorMessage = test.ErrorMessage, ErrorStackTrace = test.ErrorStackTrace, StartTime = test.StartTime, EndTime = test.EndTime, }; switch (test.Outcome) { case Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.None: tr.Outcome = Outcome.None; break; case Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed: tr.Outcome = Outcome.Passed; break; case Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Failed: tr.Outcome = Outcome.Failed; break; case Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Skipped: tr.Outcome = Outcome.Skipped; break; case Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.NotFound: tr.Outcome = Outcome.NotFound; break; default: tr.Outcome = Outcome.None; break; } if (test.Messages != null && test.Messages.Count > 0) { foreach (var message in test.Messages) { tr.TestResultMessages.Add(new TestResultMessage() { Category = message.Category, Text = message.Text, }); } } testRun.TestResults.Add(tr); SaveChanges(); }