public void SetResult_ThrowsIfSetTwice() { var testRun = new TestRun(null); var result = new TestEngineResult(); testRun.SetResult(result); Assert.Throws<InvalidOperationException>(() => testRun.SetResult(result)); }
public void IsComplete_TrueIfComplete() { var testRun = new TestRun(null); var result = new TestEngineResult(); testRun.SetResult(result); Assert.IsTrue(testRun.IsComplete); }
public async Task can_assign_multiple_aws_ips_testruns_that_dont_already_have_agent_ip() { var testConfiguration = new TestConfiguration(5, 10, 5, "BbcGetRequest", "PerformanceDsl.Tests.Tests"); var testRun = new TestRun { DllThatContainsTestsPath = "C:\\Agent\\Tests\\PerformanceDsl.Tests.dll", TestRunIdentifier = Guid.NewGuid() }; testRun.TestConfigurations.Add(testConfiguration); var test = new Test { Agent = null, TestRun = testRun }; var testSuite = new TestSuite(); testSuite.Tests.Add(test); test = new Test { Agent = null, TestRun = testRun }; testSuite.Tests.Add(test); test = new Test { Agent = null, TestRun = testRun }; testSuite.Tests.Add(test); var performanceServer = new PerformanceServer(); await performanceServer.BeginTestRun(testSuite); }
/// <summary> /// Initialize the editor to a default state based on given test run. /// </summary> /// <param name="serviceProvider"></param> /// <param name="run">Obselete. Always null.</param> void IRunConfigurationEditor.Initialize(System.IServiceProvider serviceProvider, TestRun run) { // Initialize to something like: 7.0, 7.1, 8.0 foreach (string version in VSRegistry.GetVersions()) { m_hiveCombo.Items.Add(version); } }
public void OneNameCriterion() { ITestMethod tm = new TestMethod(new TestFixture(typeof(SampleTestFixture)), typeof(SampleTestFixture).GetMethod("Foo")); var nameCriterion = new NameCriterion(typeof(SampleTestFixture).FullName + ".Foo"); var selection = new TestRun(nameCriterion); Assert.True(selection.Contains(tm)); }
void runner_TestCompleted(TestRun sender, TestCompletedEventArgs args) { var testList = view as TestRunView; if (testList == null) return; if (args.Result.Pass) testList.PassedCount = (++passed).ToString(); else testList.FailedCount = (++failed).ToString(); }
public static void GetAnotherTestRunWithStatus(TestRunStatuses status, ITestWorkflow workflow) { var testRun = new TestRun { Name = "test run the second", Status = status }; testRun.SetWorkflow(workflow); TestRunQueue.TestRuns.Add(testRun); }
/// <summary> /// Publishes the given results to the test run. /// </summary> /// <param name="testResults">Results to be published.</param> public async Task AddResultsAsync(TestRun testRun, TestCaseResultData[] testResults, CancellationToken cancellationToken) { Trace.Entering(); int noOfResultsToBePublished = BATCH_SIZE; _executionContext.Output(StringUtil.Loc("PublishingTestResults", testRun.Id)); for (int i = 0; i < testResults.Length; i += BATCH_SIZE) { cancellationToken.ThrowIfCancellationRequested(); if (i + BATCH_SIZE >= testResults.Length) { noOfResultsToBePublished = testResults.Length - i; } _executionContext.Output(StringUtil.Loc("TestResultsRemaining", (testResults.Length - i), testRun.Id)); var currentBatch = new TestCaseResultData[noOfResultsToBePublished]; Array.Copy(testResults, i, currentBatch, 0, noOfResultsToBePublished); List<TestCaseResult> testresults = await _testResultsServer.AddTestResultsToTestRunAsync(currentBatch, _projectName, testRun.Id, cancellationToken); for (int j = 0; j < noOfResultsToBePublished; j++) { cancellationToken.ThrowIfCancellationRequested(); // Do not upload duplicate entries string[] attachments = testResults[i + j].Attachments; if (attachments != null) { Hashtable attachedFiles = new Hashtable(StringComparer.CurrentCultureIgnoreCase); var createAttachmentsTasks = attachments.Select(async attachment => { if (!attachedFiles.ContainsKey(attachment)) { TestAttachmentRequestModel reqModel = GetAttachmentRequestModel(attachment); if (reqModel != null) { await _testResultsServer.CreateTestResultAttachmentAsync(reqModel, _projectName, testRun.Id, testresults[j].Id, cancellationToken); } attachedFiles.Add(attachment, null); } }); await Task.WhenAll(createAttachmentsTasks); } // Upload console log as attachment string consoleLog = testResults[i + j].ConsoleLog; TestAttachmentRequestModel attachmentRequestModel = GetConsoleLogAttachmentRequestModel(consoleLog); if (attachmentRequestModel != null) { await _testResultsServer.CreateTestResultAttachmentAsync(attachmentRequestModel, _projectName, testRun.Id, testresults[j].Id, cancellationToken); } } } Trace.Leaving(); }
public static ITestRun GetTestRunWithStatus(TestRunStatuses status) { var workflow = new TestWorkflow(TestLabCollection.TestLabs.First()) { Name = "workflow 01" }; workflow.SetTestLab(TestLabCollection.TestLabs.First()); WorkflowCollection.Workflows.Add(workflow); var testRun = new TestRun { Name = "test run 03", Status = status }; testRun.SetWorkflow(workflow); TestRunQueue.TestRuns.Add(testRun); return testRun; }
public void Show() { this.view = new TestRunView(); Application.Current.MainWindow.Child = view; runner = new TestRun(testAssembly); runner.TestCompleted += new TestCompletedEventHandler(runner_TestCompleted); runner.AllTestsCompleted += new EventHandler(runner_AllTestsCompleted); new Thread(new ThreadStart(runner.Execute)).Start(); }
public void TwoNameCriteria() { ITestMethod tm = new TestMethod(new TestFixture(typeof(SampleTestFixture)), typeof(SampleTestFixture).GetMethod("Foo")); var addCriterion = new OrCriterion(); addCriterion.Add(new NameCriterion(typeof(SampleTestFixture).FullName + ".Foo")); addCriterion.Add(new NameCriterion("bar")); var testRun = new TestRun(addCriterion); Assert.True(testRun.Contains(tm)); }
public void NamespaceCriterion() { ITestMethod tm1 = new TestMethod(new TestFixture(typeof(SampleTestFixture)), typeof(SampleTestFixture).GetMethod("Foo")); ITestMethod tm2 = new TestMethod(new TestFixture(typeof(CriteriaTests)), typeof(CriteriaTests).GetMethod("NamespaceCriterion")); var selection = new TestRun(new NamespaceCriterion(tm1.DeclaringTypeFullName)); Assert.True(selection.Contains(tm1)); Assert.False(selection.Contains(tm2)); }
public void Wait_AllowsMultipleWaits() { var testRun = new TestRun(null); testRun.SetResult(new TestEngineResult()); Assert.IsTrue(testRun.Wait(TimeSpan.FromMilliseconds(0)), "Expected wait to be true because the test is complete"); Assert.IsTrue(testRun.Wait(TimeSpan.FromMilliseconds(0)), "Expected the second wait to be non blocking"); }
public Scenario CreateScenario(xb.Scenario scenario, TestRun testRun) { return new Scenario() { AreaPath = scenario.Feature.Area.Name, FeatureName = scenario.Feature.Name, Name = scenario.Name, Outcome = scenario.Outcome, Reason = scenario.Reason, EndTime = scenario.EndTime, TestRun = testRun, StartTime = scenario.StartTime }; }
private void BuildScenarios(xb.TestRun testRun, TestRun testRunDb) { var scenarios = from area in testRun.Areas from feature in area.Features from scenario in feature.Scenarios select scenario; foreach(xb.Scenario scenario in scenarios) { Scenario scenarioDb = factory.CreateScenario(scenario, testRunDb); scenarioDb.TestRun = testRunDb; dbContext.Scenarios.Add(scenarioDb); BuildSteps(scenario, scenarioDb); } }
public void Wait_ReturnsFalseTillTestCompletes() { var testRun = new TestRun(null); var result = new TestEngineResult("<test-assembly />"); Assert.IsFalse(testRun.Wait(TimeSpan.FromMilliseconds(0)), "Expected wait to be false because test hasn't completed yet"); testRun.SetResult(result); Assert.IsTrue(testRun.Wait(TimeSpan.FromMilliseconds(0)), "Expected wait to be true because the test is complete"); Assert.AreEqual(result.Xml, testRun.Result); }
protected override TestRun CreateTestRun(string topSuiteName, XmlNode testRunNode) { if(testRunNode == null) { return null; } var node = testRunNode.SelectSingleNode(TestRunNameXpath); if(node != null) { var name = topSuiteName + "." + node.Value; var testRun = new TestRun(TestTime, name) { State = GetTestRunState(testRunNode) }; return testRun; } return null; }
public ITestRun CreateTestRun(ITestRunCommand testRunCommand, DynamicDictionary formData) { if (string.IsNullOrEmpty(testRunCommand.TestRunName)) testRunCommand.TestRunName = testRunCommand.WorkflowName + " " + DateTime.Now; var testRun = new TestRun { Name = testRunCommand.TestRunName, Status = testRunCommand.Status }; var currentWorkflow = WorkflowCollection.Workflows.FirstOrDefault(wfl => testRunCommand.WorkflowName == wfl.Name); SetCommonData(testRun, currentWorkflow.DefaultData.Data); SetWorkflow(testRunCommand, testRun); SetStartUpParameters(testRun); SetCommonData(testRun, formData); SetCreatedTime(testRun); return testRun; }
private static StringCollection GetSuiteNames(TestRun testRun) { var suiteNames = new StringCollection(); var fullName = testRun.TestRef; while(fullName.Length > 0) { var length = (fullName.Contains(".")) ? fullName.LastIndexOf('.') : 0; fullName = fullName.Substring(0, length); if(fullName.Length > 0) { suiteNames.Add(fullName); } } return suiteNames; }
public static ITestRun GetTestRunWithStatus(TestRunStatuses status, params string[] rules) { var workflow = new TestWorkflow(TestLabCollection.TestLabs.First()) { Name = "workflow 01" }; workflow.SetTestLab(TestLabCollection.TestLabs.First()); WorkflowCollection.Workflows.Add(workflow); var testRun = new TestRun { Name = "test run 03", Status = status }; testRun.SetWorkflow(workflow); TestRunQueue.TestRuns.Add(testRun); var taskId = 0; if (null != rules) // 20150904 rules.ToList().ForEach(rule => TaskPool.Tasks.Add(new TestTask { Id = ++taskId, Rule = rule, WorkflowId = workflow.Id, TestRunId = testRun.Id })); // rules.ToList().ForEach(rule => TaskPool.Tasks.Add(new TestTask (TestTaskRuntimeTypes.Powershell) { Id = ++taskId, Rule = rule, WorkflowId = workflow.Id, TestRunId = testRun.Id })); return testRun; }
public void can_run_tests() { var testConfiguration = new TestConfiguration(5, 10, 5, "BbcGetRequest", "PerformanceDsl.Tests.Tests"); var testRun = new TestRun { DllThatContainsTestsPath = "C:\\Agent\\Tests\\PerformanceDsl.Tests.dll", TestRunIdentifier = Guid.NewGuid() }; testRun.TestConfigurations.Add(testConfiguration); var testRunner = new TestRunner(); XmlConfigurator.Configure(); Task task = testRunner.Begin(testRun); task.ContinueWith(x => { Console.WriteLine(x.Status.ToString()); Console.WriteLine("end"); }); task.Wait(); }
public async Task can_send_test_to_agent_where_test_has_no_agent() { var testConfiguration = new TestConfiguration(5, 10, 5, "BbcGetRequest", "PerformanceDsl.Tests.Tests"); var testRun = new TestRun { DllThatContainsTestsPath = "C:\\Agent\\Tests\\PerformanceDsl.Tests.dll", TestRunIdentifier = Guid.NewGuid() }; testRun.TestConfigurations.Add(testConfiguration); var test = new Test { Agent = null, TestRun = testRun }; var testSuite = new TestSuite(); testSuite.Tests.Add(test); var performanceServer = new PerformanceServer(); await performanceServer.BeginTestRun(testSuite); }
public async Task can_post_to_agent() { var testConfiguration = new TestConfiguration(5, 10, 5, "BbcGetRequest", "PerformanceDsl.Tests.Tests"); var testRun = new TestRun { DllThatContainsTestsPath = "C:\\Agent\\Tests\\PerformanceDsl.Tests.dll", TestRunIdentifier = Guid.NewGuid() }; testRun.TestConfigurations.Add(testConfiguration); string serialisedTestRun = JsonConvert.SerializeObject(testRun); using (var httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var content = new StringContent(serialisedTestRun); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); HttpResponseMessage result = await httpClient.PostAsync("http://localhost:9999", content); result.EnsureSuccessStatusCode(); } }
public async Task can_upload_dll_to_agent() { var testConfiguration = new TestConfiguration(5, 10, 5, "BbcGetRequest", "PerformanceDsl.Tests.Tests"); var testRun = new TestRun { DllThatContainsTestsPath = "C:\\Agent\\Tests\\PerformanceDsl.Tests.dll", TestRunIdentifier = Guid.NewGuid() }; testRun.TestConfigurations.Add(testConfiguration); var test = new Test { Agent = "localhost", TestRun = testRun }; var testSuite = new TestSuite(); testSuite.Tests.Add(test); testSuite.DllsThatNeedUploadingToAgent.Add( @"C:\git\PerformanceDsl\PerformanceDsl.Tests\PerformanceDsl.Tests\bin\Debug\PerformanceDsl.Tests.dll"); var performanceServer = new PerformanceServer(); await performanceServer.BeginTestRun(testSuite); }
private void AddOrUpdateSuite(IDictionary<string, SuiteRun> suiteHash, TestRun testRun, StringCollection suiteNames) { foreach(var suiteName in suiteNames) { if(!suiteHash.ContainsKey(suiteName)) { var newSuite = new SuiteRun(suiteName, SuiteRunDesc, TestTime, suiteName); suiteHash.Add(suiteName, newSuite); } var suiteRun = suiteHash[suiteName]; if(testRun.State == TestRun.TestRunState.Passed) { suiteRun.Passed++; } if(testRun.State == TestRun.TestRunState.Failed) { suiteRun.Failed++; } if(testRun.State == TestRun.TestRunState.NotRun) { suiteRun.NotRun++; } } }
protected override TestRun CreateTestRun(string topSuiteName, XmlNode testRunNode) { if(testRunNode == null || string.IsNullOrEmpty(topSuiteName)) { return null; } var node = testRunNode.SelectSingleNode(TestRunNameXpath); if(node != null) { var fullName = node.Value; var position = fullName.IndexOf(topSuiteName); var name = fullName.Substring(position); var testRun = new TestRun(TestTime, name) { State = GetTestRunState(testRunNode) }; var elapsedNode = testRunNode.SelectSingleNode(ElapsedXpath); if(elapsedNode != null) { testRun.Elapsed = Convert.ToDouble(elapsedNode.Value); } return testRun; } return null; }
protected TestResultParserStateContext(TestRun testRun) { Initialize(testRun); }
public void ShouldFindRegistrationsForSomeClassesOnDifferentArchiveParts() { XmlElementHelper helper = new XmlElementHelper().Add("arkiv", new XmlElementHelper() .Add("arkivdel", new XmlElementHelper() .Add("systemID", "someArchivePartSystemId_1") .Add("klassifikasjonssystem", new XmlElementHelper() .Add("klasse", // Has 2 registrations new XmlElementHelper() .Add("systemID", "someClassSystemId_1") .Add("registrering", string.Empty) .Add("registrering", string.Empty)) .Add("klasse", // Has sub-class new XmlElementHelper() .Add("systemID", "someClassSystemId_2") .Add("klasse", // Has 1 registration new XmlElementHelper() .Add("systemID", "someClassSystemId_3") .Add("registrering", string.Empty))) .Add("klasse", // Has 2 sub-class new XmlElementHelper() .Add("systemID", "someClassSystemId_4") .Add("klasse", // Has no registrations new XmlElementHelper() .Add("systemID", "someClassSystemId_5"))))) .Add("arkivdel", new XmlElementHelper() .Add("systemID", "someArchivePartSystemId_2") .Add("klassifikasjonssystem", new XmlElementHelper() .Add("klasse", // Has 2 registrations new XmlElementHelper() .Add("systemID", "someClassSystemId_6") .Add("registrering", string.Empty) .Add("registrering", string.Empty)) .Add("klasse", // Has sub-class new XmlElementHelper() .Add("systemID", "someClassSystemId_7") .Add("klasse", // Has 1 registration new XmlElementHelper() .Add("systemID", "someClassSystemId_8") .Add("registrering", string.Empty))) .Add("klasse", // Has 2 sub-class new XmlElementHelper() .Add("systemID", "someClassSystemId_9") .Add("klasse", // Has no registrations new XmlElementHelper() .Add("systemID", "someClassSystemId_10")))))); TestRun testRun = helper.RunEventsOnTest(new NumberOfRegistrationsPerClass()); testRun.Results.Should().Contain(r => r.Message.Equals( "Arkivdel (systemID): someArchivePartSystemId_1 - Klasse (systemID): someClassSystemId_1 - Antall: 2" )); testRun.Results.Should().Contain(r => r.Message.Equals( "Arkivdel (systemID): someArchivePartSystemId_1 - Klasse (systemID): someClassSystemId_3 - Antall: 1" )); testRun.Results.Should().Contain(r => r.Message.Equals( "Arkivdel (systemID): someArchivePartSystemId_2 - Klasse (systemID): someClassSystemId_6 - Antall: 2" )); testRun.Results.Should().Contain(r => r.Message.Equals( "Arkivdel (systemID): someArchivePartSystemId_2 - Klasse (systemID): someClassSystemId_8 - Antall: 1" )); testRun.Results.Should().Contain(r => r.Message.Equals( "Klasser uten registreringer (og uten underklasser) - Antall: 2" )); testRun.Results.Count.Should().Be(5); }
private List <TestCase> ConvertUnitTestsResultsToTestCases(List <TestRunUnitTestResult> unitTestResults, TestRun testRun) { var testCases = new List <TestCase>(); foreach (var unitTest in unitTestResults) { var testDefinition = testRun.TestDefinitions.FirstOrDefault(x => x.id.Equals(unitTest.testId)); string fullName = $"{testDefinition?.TestMethod.className}.{testDefinition?.TestMethod.name}"; testCases.Add(new TestCase(fullName, testDefinition?.TestMethod.className)); } return(testCases); }
private static void LogTestRunDetails(TestRun testRun) { Logger.LogMessage(string.Format(CultureInfo.InvariantCulture, "TestRun: Name = {0} , Id = {1}, State = {2}", testRun.Name, testRun.Id, testRun.State)); }
public Task <bool> NextFinished(Test test, TestRun testRun, int progressCount, int targetCount, int passed, int failed) { return(Task.FromResult(true)); }
public Task <bool> Finished(TestRun testRun, int passed, int failed) { return(Task.FromResult(true)); }
public static TestRun Parse(string filepath) { var doc = XDocument.Load(filepath); var filename = Path.GetFileNameWithoutExtension(filepath); var report = new TestRun { Name = filename, TestCaseCount = doc.Descendants("test-case").Count(), Passed = GetPassed(doc.Root), Failed = GetFailed(doc.Root), Inconclusive = GetInconclusive(doc.Root), Skipped = GetSkipped(doc.Root), StartTime = GetStartTime(doc.Root), EndTime = GetEndTime(doc.Root) }; report.Duration = (DateTime.Parse(report.EndTime) - DateTime.Parse(report.StartTime)).ToString(@"hh\:mm\:ss"); var filterElement = doc.Root.Element("filter"); switch (filterElement.Descendants().First().Name.LocalName) { case "namespace": report.Category = filterElement.Element("namespace").Value; break; case "cat": report.Category = filterElement.Element("cat").Value; break; default: report.Category = "Unknown"; break; } // TestSuites 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.TestRun = report; testSuite.TestRunId = report._Id; testSuite.Name = ts.Attribute("name")?.Value; // Suite Time Info testSuite.StartTime = GetStartTime(ts); testSuite.EndTime = GetEndTime(ts); testSuite.Duration = (DateTime.Parse(testSuite.EndTime) - DateTime.Parse(testSuite.StartTime)).ToString(@"hh\:mm\:ss"); testSuite.TestCaseCount = ts.Descendants("test-case").Count(); testSuite.Passed = GetPassed(ts); testSuite.Failed = GetFailed(ts); testSuite.Inconclusive = GetInconclusive(ts); testSuite.Skipped = GetSkipped(ts); // any error messages and/or stack-trace var testSuiteFailure = ts.Element("failure"); if (testSuiteFailure != null) { var message = testSuiteFailure.Element("message"); if (message != null) { testSuite.StatusMessage = message.Value; } var stackTrace = testSuiteFailure.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 = GetCategories(ts, false); // Test Cases ts.Descendants("test-case").AsParallel().ToList().ForEach(tc => { var test = new TestCase(); test.TestSuite = testSuite; test.TestSuiteId = testSuite._Id; test.Name = tc.Attribute("name")?.Value; test.Result = ResultExtensions.ToStatus(tc.Attribute("result")?.Value); // TestCase Time Info test.StartTime = GetStartTime(tc); test.EndTime = GetEndTime(tc); test.Duration = (DateTime.Parse(test.EndTime) - DateTime.Parse(test.StartTime)).ToString(@"hh\:mm\:ss"); // description var description = tc.Descendants("property") .Where(c => c.Attribute("name").Value .Equals("Description", StringComparison.CurrentCultureIgnoreCase)); test.Description = description.Any() ? description.ToArray()[0].Attribute("value")?.Value : ""; // Categories var categoryProperties = tc.Descendants("property") .Where(c => c.Attribute("name").Value .Equals("Category", StringComparison.CurrentCultureIgnoreCase)); foreach (var property in categoryProperties) { test.Categories.Add(property.Attribute("value")?.Value); } //error and other status messages var testCaseFailure = new Failure { Message = tc.Element("failure") != null ? tc.Element("failure")?.Element("message")?.Value.Trim() : "", StackTrace = tc.Element("failure") != null ? tc.Element("failure")?.Element("stack-trace") != null ? tc.Element("failure")?.Element("stack-trace")?.Value.Trim() : "" : "", Output = tc.Element("output") != null ? tc.Element("output") != null ? tc.Element("output")?.Value.Trim() : "" : "" }; test.Failure = testCaseFailure; testSuite.TestCases.Add(test); testSuite.TestCaseIds.Add(test._Id); }); testSuite.Categories = AggregateCategories(testSuite); testSuite.Result = AggregateResults(testSuite.TestCases); report.TestSuites.Add(testSuite); report.TestSuiteIds.Add(testSuite._Id); }); report.Categories = AggregateCategories(report); report.Result = AggregateResults(report.TestSuites); return(report); }
public async Task <TestResult> Run(TestRun run) { var test = run.Case; var agent = run.Queue.Agent; var session = run.Queue.Session; var build = session.Build; //get test's feature file string workFile = Path.Combine(build.LocalPath, test.Location); string outputFileName = test.FullName + ".html"; var outputFile = new FileInfo(Path.Combine(session.LocalPath, outputFileName)); if (!outputFile.Directory.Exists) { outputFile.Directory.Create(); } //find ruby folder for startProgram //const string startProgram = @"c:\ruby200-x64\bin\cucumber.bat"; var rubyDir = new DirectoryInfo(@"c:\").GetDirectories("ruby*", SearchOption.TopDirectoryOnly).FirstOrDefault(); if (rubyDir == null) { throw new DirectoryNotFoundException("ruby installation not found on " + agent.Name); } string startProgram = string.Format(@"c:\{0}\bin\cucumber.bat", rubyDir.Name); string startProgramArgs = string.Format("\"{0}\" --tag @Name_{1} -f html --out \"{2}\"", workFile, test.Name, outputFile.FullName); var pi = new ProcessStartInfo(startProgram, startProgramArgs); pi.EnvironmentVariables.Add(session.Config.Key, session.Config.Value); await ProcessEx.RunAsync(pi); outputFile.Refresh(); if (!outputFile.Exists) { throw new FileNotFoundException("result file not found", outputFile.FullName); } //parse result from output file string text = null; int attempts = 0; while (text == null && attempts++ < 5) { try { using (var sr = outputFile.OpenText()) { text = await sr.ReadToEndAsync(); } } catch (Exception ex) { Trace.TraceError("error when parsing result file, retry: {0}, error: {1}", attempts, ex.ToString()); } } var summaryMatch = RxSummary.Match(text); var failMatch = RxFail.Match(text); var result = new TestResult { Output = Path.Combine(session.GetPathOnAgent(agent), outputFileName), Summary = summaryMatch.Groups[1].Value + " " + summaryMatch.Groups[2].Value, PassOrFail = !failMatch.Success }; if (result.PassOrFail == false) { var q = from Match m in RxFailDetails.Matches(failMatch.Groups[1].Value) select m.Groups[1].Value; result.ErrorDetails = string.Join("\n", q); } return(result); }
private void Test(TestRun testRun) { _stream.WriteLine(@" <div class=""test"">"); _stream.WriteLine($@" <h3 id=""{testRun.TestId}"">"); if (testRun.TestId.Number != 0) { _stream.WriteLine(@" " + testRun.TestId + " – "); } _stream.WriteLine(@" " + testRun.TestName); _stream.WriteLine(@" </h3>"); _stream.WriteLine(@" <p><b>Type:</b> " + GetTestTypeDisplayName(testRun.TestType) + "</p>"); _stream.WriteLine(@""); _stream.WriteLine(@" <p class=""test-description"">"); _stream.WriteLine(@" " + testRun.TestDescription); _stream.WriteLine(@" </p>"); _stream.WriteLine(@""); _stream.WriteLine(@" <h4>" + Resources.Report.HeadingTestResults + "</h4>"); if (TestTypeIsControl(testRun) && testRun.IsSuccess()) { _stream.WriteLine("<p>" + Resources.Report.TestNoErrorsFound + "</p>"); } else { _stream.WriteLine(@" <table class=""table"">"); _stream.WriteLine(@" <thead>"); _stream.WriteLine(@" <tr>"); _stream.WriteLine(@" <th>" + Resources.Report.TestLocation + "</th>"); _stream.WriteLine(@" <th>" + Resources.Report.TestMessage + "</th>"); _stream.WriteLine(@" </tr>"); _stream.WriteLine(@" </thead>"); _stream.WriteLine(@" <tbody>"); foreach (TestResult testResult in testRun.Results.Take(NumberOfResultsToDisplay)) { _stream.WriteLine(@" <tr>"); _stream.WriteLine(@" <td>"); _stream.WriteLine(@" " + testResult.Location); _stream.WriteLine(@" </td>"); _stream.WriteLine(@" <td>"); _stream.WriteLine(@" " + SubstitueLineBreaksWithHtmlBreak(testResult.Message)); _stream.WriteLine(@" </td>"); _stream.WriteLine(@" </tr>"); } if (testRun.Results.Count > NumberOfResultsToDisplay) { string moreResultsMessage = string.Format( Resources.Report.TestMoreResultsOfSameKind, testRun.Results.Count - NumberOfResultsToDisplay ); _stream.WriteLine(@" <tr>"); _stream.WriteLine(@" <td></td>"); _stream.WriteLine(@" <td>" + moreResultsMessage + "</td>"); _stream.WriteLine(@" </tr>"); } _stream.WriteLine(@" </tbody>"); _stream.WriteLine(@" </table>"); } _stream.WriteLine(@" </div>"); }
private static bool TestTypeIsControl(TestRun testRun) { return(testRun.TestType == TestType.ContentControl || testRun.TestType == TestType.StructureControl); }
public static void BeforeTestRun() { TestRun.Init(); }
public async Task <bool> AddAsync(TestRun testRun) { await _dbContext.TestRuns.AddAsync(testRun); return(SaveChanges()); }
// Get the path to the result files private static IList <string> ToResultFiles(ObjectModel.AttachmentSet attachmentSet, Guid testResultExecutionId, TestRun testRun, string trxFileDirectory) { string runDirectoryName = Path.Combine(trxFileDirectory, testRun.RunConfiguration.RunDeploymentRootDirectory); string testResultDirectory = Path.Combine(runDirectoryName, "In"); if (!Guid.Equals(testResultExecutionId, Guid.Empty)) { testResultDirectory = Path.Combine(testResultDirectory, testResultExecutionId.ToString()); } testResultDirectory = Path.Combine(testResultDirectory, Environment.MachineName); if (!Directory.Exists(testResultDirectory)) { Directory.CreateDirectory(testResultDirectory); } List <string> resultFiles = new List <string>(); foreach (ObjectModel.UriDataAttachment uriDataAttachment in attachmentSet.Attachments) { if (ObjectModel.EqtTrace.IsVerboseEnabled) { ObjectModel.EqtTrace.Verbose("TrxLogger: ToResultFiles: Got attachment " + uriDataAttachment.Uri + " with local path " + uriDataAttachment.Uri.LocalPath); } string sourceFile = uriDataAttachment.Uri.LocalPath; Debug.Assert(Path.IsPathRooted(sourceFile), "Source file is not rooted"); // copy the source file to the target location string targetFileName = FileHelper.GetNextIterationFileName(testResultDirectory, Path.GetFileName(sourceFile), false); CopyFile(sourceFile, targetFileName); // Add the source file name to the result files list. // (Trx viewer automatically adds In\<Guid> to the result file. string fileName = Path.Combine(Environment.MachineName, Path.GetFileName(targetFileName)); resultFiles.Add(fileName); } return(resultFiles); }
private void ProcessSubmission(Submission submission) { // TODO: Check for N+1 queries problem this.logger.InfoFormat("Work on submission №{0} started.", submission.Id); var executionStrategy = this.CreateExecutionStrategy(submission.SubmissionType.ExecutionStrategyType); var context = new ExecutionContext { SubmissionId = submission.Id, AdditionalCompilerArguments = submission.SubmissionType.AdditionalCompilerArguments, CheckerAssemblyName = submission.Problem.Checker.DllFile, CheckerParameter = submission.Problem.Checker.Parameter, CheckerTypeName = submission.Problem.Checker.ClassName, FileContent = submission.Content, AllowedFileExtensions = submission.SubmissionType.AllowedFileExtensions, CompilerType = submission.SubmissionType.CompilerType, MemoryLimit = submission.Problem.MemoryLimit, TimeLimit = submission.Problem.TimeLimit, TaskSkeleton = submission.Problem.SolutionSkeleton, Tests = submission.Problem.Tests .AsQueryable() .Select(x => new TestContext { Id = x.Id, Input = x.InputDataAsString, Output = x.OutputDataAsString, IsTrialTest = x.IsTrialTest, OrderBy = x.OrderBy }).ToList(), }; ExecutionResult executionResult; try { executionResult = executionStrategy.SafeExecute(context); } catch (Exception exception) { this.logger.Error($"executionStrategy.Execute on submission №{submission.Id} has thrown an exception:", exception); submission.ProcessingComment = $"Exception in executionStrategy.Execute: {exception.Message}"; return; } submission.IsCompiledSuccessfully = executionResult.IsCompiledSuccessfully; submission.CompilerComment = executionResult.CompilerComment; if (!executionResult.IsCompiledSuccessfully) { return; } foreach (var testResult in executionResult.TestResults) { var testRun = new TestRun { CheckerComment = testResult.CheckerDetails.Comment, ExpectedOutputFragment = testResult.CheckerDetails.ExpectedOutputFragment, UserOutputFragment = testResult.CheckerDetails.UserOutputFragment, ExecutionComment = testResult.ExecutionComment, MemoryUsed = testResult.MemoryUsed, ResultType = testResult.ResultType, TestId = testResult.Id, TimeUsed = testResult.TimeUsed, }; submission.TestRuns.Add(testRun); } this.logger.InfoFormat("Work on submission №{0} ended.", submission.Id); }
public Task <bool> Start(TestRun testRun, int numberOfThreads, string header) { return(Task.FromResult(true)); }
public void NumberOfClassesIsTwoInEachArchivePart() { XmlElementHelper helper = new XmlElementHelper().Add("arkiv", new XmlElementHelper() // Arkivdel 1 .Add("arkivdel", new XmlElementHelper() .Add("systemID", "someSystemId_1") // Primært klassifikasjonssystem (inneholder registrering eller mappe) .Add("klassifikasjonssystem", new XmlElementHelper() .Add("systemID", "klassSys_1") .Add("registrering", new XmlElementHelper() .Add("klasse", string.Empty) .Add("klasse", new XmlElementHelper() .Add("klasse", new XmlElementHelper())))) // Sekundært klassifikasjonssystem .Add("klassifikasjonssystem", new XmlElementHelper() .Add("systemID", "klassSys_2") .Add("klasse", string.Empty) .Add("klasse", new XmlElementHelper() .Add("klasse", new XmlElementHelper())))) // Arkivdel 2 .Add("arkivdel", new XmlElementHelper() .Add("systemID", "someSystemId_2") // Primært klassifikasjonssystem (inneholder registrering eller mappe) .Add("klassifikasjonssystem", new XmlElementHelper() .Add("systemID", "klassSys_1") .Add("mappe", new XmlElementHelper() .Add("klasse", string.Empty) .Add("klasse", new XmlElementHelper() .Add("klasse", new XmlElementHelper())))) // Sekundært klassifikasjonssystem .Add("klassifikasjonssystem", new XmlElementHelper() .Add("systemID", "klassSys_2") .Add("klasse", string.Empty) .Add("klasse", new XmlElementHelper() .Add("klasse", new XmlElementHelper()))))); TestRun testRun = helper.RunEventsOnTest(new NumberOfClasses()); testRun.Results.Should().Contain(r => r.Message.Equals("Arkivdel (systemID): someSystemId_1 - Primært klassifikasjonssystem (systemID): klassSys_1 - Totalt antall klasser: 3")); testRun.Results.Should().Contain(r => r.Message.Equals("Arkivdel (systemID): someSystemId_1 - Primært klassifikasjonssystem (systemID): klassSys_1 - Klasser på nivå 1: 2")); testRun.Results.Should().Contain(r => r.Message.Equals("Arkivdel (systemID): someSystemId_1 - Primært klassifikasjonssystem (systemID): klassSys_1 - Klasser på nivå 2: 1")); testRun.Results.Should().Contain(r => r.Message.Equals("Arkivdel (systemID): someSystemId_1 - Sekundært klassifikasjonssystem (systemID): klassSys_2 - Totalt antall klasser: 3")); testRun.Results.Should().Contain(r => r.Message.Equals("Arkivdel (systemID): someSystemId_1 - Sekundært klassifikasjonssystem (systemID): klassSys_2 - Klasser på nivå 1: 2")); testRun.Results.Should().Contain(r => r.Message.Equals("Arkivdel (systemID): someSystemId_1 - Sekundært klassifikasjonssystem (systemID): klassSys_2 - Klasser på nivå 2: 1")); testRun.Results.Should().Contain(r => r.Message.Equals("Arkivdel (systemID): someSystemId_2 - Primært klassifikasjonssystem (systemID): klassSys_1 - Totalt antall klasser: 3")); testRun.Results.Should().Contain(r => r.Message.Equals("Arkivdel (systemID): someSystemId_2 - Primært klassifikasjonssystem (systemID): klassSys_1 - Klasser på nivå 1: 2")); testRun.Results.Should().Contain(r => r.Message.Equals("Arkivdel (systemID): someSystemId_2 - Primært klassifikasjonssystem (systemID): klassSys_1 - Klasser på nivå 2: 1")); testRun.Results.Should().Contain(r => r.Message.Equals("Arkivdel (systemID): someSystemId_2 - Sekundært klassifikasjonssystem (systemID): klassSys_2 - Totalt antall klasser: 3")); testRun.Results.Should().Contain(r => r.Message.Equals("Arkivdel (systemID): someSystemId_2 - Sekundært klassifikasjonssystem (systemID): klassSys_2 - Klasser på nivå 1: 2")); testRun.Results.Should().Contain(r => r.Message.Equals("Arkivdel (systemID): someSystemId_2 - Sekundært klassifikasjonssystem (systemID): klassSys_2 - Klasser på nivå 2: 1")); }
public Task <bool> Stop(TestRun testRun, int passed, int failed, int progressCount, int targetCount) { return(Task.FromResult(true)); }
private void MainForm_Load(object sender, EventArgs e) { var config = new ConfigCurrentUser(); Location = config.MainFormLocation; Size = config.MainFormSize; Command.CreateCommands(this, _csUnitControl); Command.FillToolStrip(_toolStrip); if (_clh.HasOption("recipe")) { if (Utils.FileExists(_clh.GetOptionValueFor("recipe"), true)) { RecipeFactory.Load(_clh.GetOptionValueFor("recipe")); } } else if (_clh.HasOption("assembly")) { if (Utils.FileExists(_clh.GetOptionValueFor("assembly"), true)) { var assemblyPathName = _clh.GetOptionValueFor("assembly"); if (!Path.IsPathRooted(assemblyPathName)) { assemblyPathName = Path.Combine(Environment.CurrentDirectory, assemblyPathName); } RecipeFactory.Current.AddAssembly(assemblyPathName); } } else { switch (config.StartupLoadItem) { case "Recipe": if (config.RecentRecipies.Count > 0 && Utils.FileExists(config.RecentRecipies[0], true)) { RecipeFactory.Load(config.RecentRecipies[0]); } break; case "Assembly": if (config.RecentAssemblies.Count > 0 && Utils.FileExists(config.RecentAssemblies[0], true)) { RecipeFactory.Current.AddAssembly(config.RecentAssemblies[0]); } break; } } // Setup the xml handler if (_clh.HasOption("xml")) { _xmlWriter = new DefaultXmlWriter(RecipeFactory.Current, _clh.GetOptionValueFor("xml")); } // Automatically start the recipe if (_clh.HasOption("autorun")) { if (RecipeFactory.Current != null) { var testRun = new TestRun(new AllTestsCriterion()); RecipeFactory.Current.RunTests(testRun); } } }
static void Main() { List <KustoDataObj> MockedData = new List <KustoDataObj>(); MockedData.Add(new KustoDataObj(112, "Pull Request 112", 1, 1, "Test run 1", 0.5)); MockedData.Add(new KustoDataObj(112, "Pull Request 112", 1, 1, "Test run 2", 0.2)); MockedData.Add(new KustoDataObj(112, "Pull Request 112", 2, 2, "Test run 1", 0.6)); MockedData.Add(new KustoDataObj(112, "Pull Request 112", 2, 2, "Test run 2", 0.3)); MockedData.Add(new KustoDataObj(113, "Pull Request 113", 3, 3, "Test run 3", 0.1)); MockedData.Add(new KustoDataObj(114, "Pull Request 114", 4, 4, "Test run 4", 0.7)); MockedData.Add(new KustoDataObj(114, "Pull Request 114", 5, 5, "Test run 5", 0.3)); using (var db = new BloggingContext()) { foreach (var row in MockedData) { long id = row.PrId; PullRequest pr = db.PullRequests.Find(id); if (pr == null) { pr = new PullRequest() { Id = id, Title = row.PrTitle }; db.PullRequests.Add(pr); } long buildId = row.BuildId; PullRequestBuildInfo prBuild = db.Builds.Find(buildId); if (prBuild == null) { prBuild = new PullRequestBuildInfo() { Id = buildId, TestRuns = new List <TestRun>(), PullRequest = pr }; db.Builds.Add(prBuild); } long testRunId = row.TrId; TestRun testRun = db.TestRuns.Find(testRunId); if (testRun == null) { testRun = new TestRun() { Id = testRunId, BuildId = testRunId, Content = row.TrContent, PullRequest = pr }; db.TestRuns.Add(testRun); } var metric = new LatencyMetric() { Percentile = row.Percentile }; testRun.LatencyMetrics.Add(metric); prBuild.TestRuns.Add(testRun); db.SaveChanges(); } } }
public string GenerateTRXReport ( TestSummary testSummary ) { var runId = _guidService.NewGuid().ToString(); var testSettingsGuid = _guidService.NewGuid().ToString(); var testLists = new TestList[] { new TestList { Id = _guidService.NewGuid().ToString(), Name = TEST_LIST_NAME_RESULTS_NOT_IN_A_LIST }, new TestList { Id = _guidService.NewGuid().ToString(), Name = TEST_LIST_NAME_ALL_LOADED_TESTS } }; var testRun = new TestRun { Id = runId, Name = $"{ TEST_RUN_NAME} {testSummary.StartDateTime.ToString(@"yyyy-MM-dd HH:mm:ss")}", RunUser = TEST_RUN_USER, Times = new Times { Creation = testSummary.StartDateTime.ToString(@"yyyy-MM-ddTHH:mm:ss.FFFFFFF+00:00"), Finsh = testSummary.EndDateTime.ToString(@"yyyy-MM-ddTHH:mm:ss.FFFFFFF+00:00"), Queuing = testSummary.StartDateTime.ToString(@"yyyy-MM-ddTHH:mm:ss.FFFFFFF+00:00"), Start = testSummary.StartDateTime.ToString(@"yyyy-MM-ddTHH:mm:ss.FFFFFFF+00:00") }, TestSettings = new TestSettings { Deployment = new Deployment { RunDeploymentRoot = RUN_DEPLOYMENT_ROOT }, Name = DEPLOYMENT_NAME, Id = testSettingsGuid.ToString() }, Results = testSummary.TestResults.Select(testResult => new UnitTestResult { ComputerName = COMPUTER_NAME, Duration = testResult.Duration.ToString(), StartTime = testResult.StartTime.ToString(@"yyyy-MM-ddTHH:mm:ss.FFFFFFF+00:00"), EndTime = testResult.EndTime.ToString(@"yyyy-MM-ddTHH:mm:ss.FFFFFFF+00:00"), ExecutionId = testResult.ExecutionId.ToString(), Outcome = testResult.Pass ? "passed" : "failed", RelativeResultsDirectory = RELATIVE_RESULTS_DIRECTORY, TestId = testResult.TestId.ToString(), TestListId = testLists[0].Id, TestName = testResult.TestName, TestType = testResult.TestType.ToString(), }).ToArray(), TestDefinitions = testSummary.TestResults.Select(testResult => new UnitTest { Execution = new Execution { Id = testResult.ExecutionId.ToString() }, Id = testResult.TestId.ToString(), Name = testResult.TestName, Storage = UNIT_TEST_PATH, TestMethod = new TestMethod { AdapterTypeName = ADAPTER_TYPE_NAME, ClassName = testResult.ClassName, CodeBase = CODE_BASE, Name = testResult.TestName } }).ToArray(), TestEntries = testSummary.TestResults.Select(testResult => new TestEntry { ExecutionId = testResult.ExecutionId.ToString(), TestId = testResult.TestId.ToString(), TestListId = testLists[0].Id }).ToArray(), TestLists = testLists, ResultSummary = new ResultSummary { Outcome = RESULT_OUTCOME, Counters = new Counters { Total = testSummary.TestResults.Count(), Executed = testSummary.TestResults.Count(), Passed = testSummary.TestResults.Count(testresult => testresult.Pass), Failed = testSummary.TestResults.Count(testresult => !testresult.Pass) } } }; XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.Add("", ""); XmlSerializer xmlSerializer = new XmlSerializer(testRun.GetType()); using Utf8StringWriter textWriter = new Utf8StringWriter(); xmlSerializer.Serialize(textWriter, testRun, ns); return(textWriter.ToString()); }
/// <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(); }
public void ShouldFindSeveralDocumentFormatsInSeveralArchiveParts() { XmlElementHelper helper = new XmlElementHelper().Add("arkiv", new XmlElementHelper() .Add("arkivdel", new XmlElementHelper() .Add("systemID", "someArchivePartSystemId_1") .Add("klassifikasjonssystem", new XmlElementHelper().Add("klasse", new XmlElementHelper() .Add("mappe", new XmlElementHelper() .Add("registrering", new[] { "xsi:type", "journalpost" }, new XmlElementHelper() .Add("dokumentbeskrivelse", new XmlElementHelper() .Add("dokumentobjekt", new XmlElementHelper() .Add("format", "pdf") .Add("referanseDokumentfil", "filename1.pdf"))))) .Add("mappe", new XmlElementHelper() .Add("registrering", new[] { "xsi:type", "journalpost" }, new XmlElementHelper() .Add("dokumentbeskrivelse", new XmlElementHelper() .Add("dokumentobjekt", new XmlElementHelper() .Add("format", "pdf") .Add("referanseDokumentfil", "filename2.pdf"))))) .Add("mappe", new XmlElementHelper() .Add("registrering", new[] { "xsi:type", "journalpost" }, new XmlElementHelper() .Add("dokumentbeskrivelse", new XmlElementHelper() .Add("dokumentobjekt", new XmlElementHelper() .Add("format", "docx") .Add("referanseDokumentfil", "filename3.docx"))))) .Add("mappe", new XmlElementHelper() .Add("registrering", new[] { "xsi:type", "journalpost" }, new XmlElementHelper() .Add("dokumentbeskrivelse", new XmlElementHelper() .Add("dokumentobjekt", new XmlElementHelper() .Add("format", "pdf") .Add("referanseDokumentfil", "filename4.docx")))))))) .Add("arkivdel", new XmlElementHelper() .Add("systemID", "someArchivePartSystemId_2") .Add("klassifikasjonssystem", new XmlElementHelper().Add("klasse", new XmlElementHelper() .Add("mappe", new XmlElementHelper() .Add("registrering", new[] { "xsi:type", "journalpost" }, new XmlElementHelper() .Add("dokumentbeskrivelse", new XmlElementHelper() .Add("dokumentobjekt", new XmlElementHelper() .Add("format", "pdf") .Add("referanseDokumentfil", "filename5.pdf"))))) .Add("mappe", new XmlElementHelper() .Add("registrering", new[] { "xsi:type", "journalpost" }, new XmlElementHelper() .Add("dokumentbeskrivelse", new XmlElementHelper() .Add("dokumentobjekt", new XmlElementHelper() .Add("format", "pdf") .Add("referanseDokumentfil", "filename6.pdf"))))) .Add("mappe", new XmlElementHelper() .Add("registrering", new[] { "xsi:type", "journalpost" }, new XmlElementHelper() .Add("dokumentbeskrivelse", new XmlElementHelper() .Add("dokumentobjekt", new XmlElementHelper() .Add("format", "docx") .Add("referanseDokumentfil", "filename7.docx"))))) .Add("mappe", new XmlElementHelper() .Add("registrering", new[] { "xsi:type", "journalpost" }, new XmlElementHelper() .Add("dokumentbeskrivelse", new XmlElementHelper() .Add("dokumentobjekt", new XmlElementHelper() .Add("format", "pdf") .Add("referanseDokumentfil", "filename8.docx"))))))))); TestRun testRun = helper.RunEventsOnTest(new NumberOfEachDocumentFormat()); testRun.Results.Should().Contain(r => r.Message.Equals( "Arkivdel (systemID): someArchivePartSystemId_1 - Dokumentformat: pdf - Antall: 2") ); testRun.Results.Should().Contain(r => r.Message.Equals( "Arkivdel (systemID): someArchivePartSystemId_1 - Dokumentformat: docx - Antall: 1") ); testRun.Results.Should() .Contain(r => r.Message.Equals( "Format-misforhold: Dokumentformat: pdf - Dokumentfilreferanse: filename4.docx") && r.IsError() ); testRun.Results.Should().Contain(r => r.Message.Equals( "Arkivdel (systemID): someArchivePartSystemId_2 - Dokumentformat: pdf - Antall: 2") ); testRun.Results.Should().Contain(r => r.Message.Equals( "Arkivdel (systemID): someArchivePartSystemId_2 - Dokumentformat: docx - Antall: 1") ); testRun.Results.Should() .Contain(r => r.Message.Equals( "Format-misforhold: Dokumentformat: pdf - Dokumentfilreferanse: filename8.docx") && r.IsError() ); testRun.Results.Count.Should().Be(6); }
public void Initialize(TestRun testRun) { TestRun = testRun; CurrentLineNumber = 0; }
public void BatchSizeIsCorrect() { SetupMocks(); int batchSize = 1000; ResetValues(); _publisher.StartTestRunAsync(new TestRunData()).Wait(); List<TestCaseResultData> testCaseResultData = new List<TestCaseResultData>(); for (int i = 0; i < batchSize + 1; i++) { testCaseResultData.Add(new TestCaseResultData()); } var testRun = new TestRun { Id = 1 }; _publisher.AddResultsAsync(testRun, testCaseResultData.ToArray()).Wait(); Assert.Equal(2, _batchSizes.Count); Assert.Equal(batchSize, _batchSizes[0]); Assert.Equal(1, _batchSizes[1]); }
/// <summary> /// Publishes the given results to the test run. /// </summary> /// <param name="testResults">Results to be published.</param> public async Task AddResultsAsync(TestRun testRun, TestCaseResultData[] testResults, CancellationToken cancellationToken) { Trace.Entering(); int noOfResultsToBePublished = BATCH_SIZE; _executionContext.Output(StringUtil.Loc("PublishingTestResults", testRun.Id)); for (int i = 0; i < testResults.Length; i += BATCH_SIZE) { cancellationToken.ThrowIfCancellationRequested(); if (i + BATCH_SIZE >= testResults.Length) { noOfResultsToBePublished = testResults.Length - i; } _executionContext.Output(StringUtil.Loc("TestResultsRemaining", (testResults.Length - i), testRun.Id)); var currentBatch = new TestCaseResultData[noOfResultsToBePublished]; var testResultsBatch = new TestCaseResult[noOfResultsToBePublished]; Array.Copy(testResults, i, currentBatch, 0, noOfResultsToBePublished); for (int testResultsIndex = 0; testResultsIndex < noOfResultsToBePublished; testResultsIndex++) { testResultsBatch[testResultsIndex] = new TestCaseResult(); TestCaseResultDataConverter.Convert(currentBatch[testResultsIndex], testResultsBatch[testResultsIndex]); } List <TestCaseResult> testresults = await _testResultsServer.AddTestResultsToTestRunAsync(testResultsBatch, _projectName, testRun.Id, cancellationToken); for (int j = 0; j < noOfResultsToBePublished; j++) { cancellationToken.ThrowIfCancellationRequested(); // Remove duplicate entries string[] attachments = testResults[i + j]?.AttachmentData?.AttachmentsFilePathList?.ToArray(); HashSet <string> attachedFiles = GetUniqueTestRunFiles(attachments); if (attachedFiles != null) { var createAttachmentsTasks = attachedFiles.Select(async attachment => { TestAttachmentRequestModel reqModel = GetAttachmentRequestModel(attachment); if (reqModel != null) { await _testResultsServer.CreateTestResultAttachmentAsync(reqModel, _projectName, testRun.Id, testresults[j].Id, cancellationToken); } }); await Task.WhenAll(createAttachmentsTasks); } // Upload console log as attachment string consoleLog = testResults[i + j]?.AttachmentData?.ConsoleLog; TestAttachmentRequestModel attachmentRequestModel = GetConsoleLogAttachmentRequestModel(consoleLog); if (attachmentRequestModel != null) { await _testResultsServer.CreateTestResultAttachmentAsync(attachmentRequestModel, _projectName, testRun.Id, testresults[j].Id, cancellationToken); } // Upload standard error as attachment string standardError = testResults[i + j]?.AttachmentData?.StandardError; TestAttachmentRequestModel stdErrAttachmentRequestModel = GetStandardErrorAttachmentRequestModel(standardError); if (stdErrAttachmentRequestModel != null) { await _testResultsServer.CreateTestResultAttachmentAsync(stdErrAttachmentRequestModel, _projectName, testRun.Id, testresults[j].Id, cancellationToken); } } } Trace.Leaving(); }
/// <summary> /// Start a run of the tests in the loaded TestPackage, returning immediately. /// The tests are run asynchronously and the listener interface is notified /// as it progresses. /// </summary> /// <param name="listener">An ITestEventHandler to receive events</param> /// <param name="filter">A TestFilter used to select tests</param> /// <returns>An <see cref="ITestRun"/> that will provide the result of the test execution</returns> protected virtual ITestRun RunTestsAsync(ITestEventListener listener, TestFilter filter) { var testRun = new TestRun(this); using (var worker = new BackgroundWorker()) { worker.DoWork += (s, ea) => { var result = RunTests(listener, filter); testRun.SetResult(result); }; worker.RunWorkerAsync(); } return testRun; }
internal static List <CollectorDataEntry> ToCollectionEntries(IEnumerable <ObjectModel.AttachmentSet> attachmentSets, TestRun testRun, string trxFileDirectory) { List <CollectorDataEntry> collectorEntries = new List <CollectorDataEntry>(); if (attachmentSets == null) { return(collectorEntries); } foreach (var attachmentSet in attachmentSets) { if (attachmentSet.Uri.AbsoluteUri.StartsWith(TrxLogger.DataCollectorUriPrefix, StringComparison.OrdinalIgnoreCase)) { CollectorDataEntry collectorEntry = ToCollectorEntry(attachmentSet, Guid.Empty, testRun, trxFileDirectory); collectorEntries.Add(collectorEntry); } } return(collectorEntries); }
void SetWorkflow(ITestRunCommand testRunCommand, TestRun testRun) { testRun.SetWorkflow(WorkflowCollection.Workflows.First(wfl => wfl.Name == testRunCommand.WorkflowName)); TestLabCollection.TestLabs.First(testLab => testLab.Id == testRun.TestLabId).Status = TestLabStatuses.Busy; }
public void SystemInformationFileUploadsWithCorrectAttachmentType() { SetupMocks(); File.WriteAllText("SystemInformation.xml", "asdf"); ResetValues(); _testRunData = _publisher.ReadResultsFromFile(_testRunContext, "filepath"); _publisher.StartTestRunAsync(_testRunData).Wait(); TestCaseResultData result = new TestCaseResultData(); result.Attachments = new string[] { "SystemInformation.xml" }; var testRun = new TestRun { Id = 1 }; _publisher.AddResultsAsync(testRun, new TestCaseResultData[] { result }).Wait(); Assert.Equal(_resultsLevelAttachments.Count, 1); Assert.Equal(_resultsLevelAttachments[1].Count, 1); Assert.Equal(_resultsLevelAttachments[1][0].AttachmentType, AttachmentType.IntermediateCollectorData.ToString()); try { File.Delete("SystemInformation.xml"); } catch { } }
internal static IList <String> ToResultFiles(IEnumerable <ObjectModel.AttachmentSet> attachmentSets, TestRun testRun, string trxFileDirectory, List <string> errorMessages) { List <String> resultFiles = new List <string>(); if (attachmentSets == null) { return(resultFiles); } foreach (var attachmentSet in attachmentSets) { if (!attachmentSet.Uri.AbsoluteUri.StartsWith(TrxLogger.DataCollectorUriPrefix, StringComparison.OrdinalIgnoreCase)) { try { IList <String> testResultFiles = ToResultFiles(attachmentSet, Guid.Empty, testRun, trxFileDirectory); resultFiles.AddRange(testResultFiles); } catch (Exception e) { string errorMsg = string.Format( CultureInfo.CurrentCulture, TrxLoggerResources.FailureToAttach, attachmentSet.DisplayName, e.GetType().ToString(), e.Message); errorMessages.Add(errorMsg); } } } return(resultFiles); }
public void PublishConsoleLogIsSuccessful() { SetupMocks(); ResetValues(); TestCaseResultData testResultWithLog = new TestCaseResultData(); testResultWithLog.ConsoleLog = "Publish console log is successfully logged"; TestCaseResultData testResultWithNoLog = new TestCaseResultData(); testResultWithNoLog.ConsoleLog = ""; TestCaseResultData testResultDefault = new TestCaseResultData(); List<TestCaseResultData> testResults = new List<TestCaseResultData>() { testResultWithLog, testResultWithNoLog, testResultDefault }; // execute publish task _testRunData = _publisher.ReadResultsFromFile(_testRunContext, "filepath"); _publisher.StartTestRunAsync(_testRunData).Wait(); var testRun = new TestRun { Id = 1 }; _publisher.AddResultsAsync(testRun, testResults.ToArray()).Wait(); _publisher.EndTestRunAsync(_testRunData, 1).Wait(); // validate Assert.Equal(_resultsLevelAttachments.Count, 1); Assert.Equal(_resultsLevelAttachments[1].Count, 1); Assert.Equal(_resultsLevelAttachments[1][0].AttachmentType, AttachmentType.ConsoleLog.ToString()); string encodedData = _resultsLevelAttachments[1][0].Stream; byte[] bytes = Convert.FromBase64String(encodedData); string decodedData = System.Text.Encoding.UTF8.GetString(bytes); Assert.Equal(decodedData, testResultWithLog.ConsoleLog); }
private static void UpdateTestResultAttachments(ObjectModel.TestResult rockSteadyTestResult, TrxObjectModel.UnitTestResult testResult, TestRun testRun, string trxFileDirectory, bool addAttachments) { if (rockSteadyTestResult.Attachments == null || rockSteadyTestResult.Attachments.Count == 0) { return; } // the testResult needs to have the testRun property set. Otherwise Data Collector entries can't be added. testResult.SetTestRun(testRun); // result files List <string> resultFiles = new List <string>(); // data collection files List <CollectorDataEntry> collectorEntries = new List <CollectorDataEntry>(); foreach (ObjectModel.AttachmentSet attachmentSet in rockSteadyTestResult.Attachments) { try { // If the attachement is from data collector if (attachmentSet.Uri.AbsoluteUri.StartsWith(TrxLogger.DataCollectorUriPrefix, StringComparison.OrdinalIgnoreCase)) { CollectorDataEntry collectorEntry = ToCollectorEntry(attachmentSet, testResult.Id.ExecutionId.Id, testRun, trxFileDirectory); collectorEntries.Add(collectorEntry); } else { IList <string> testResultFiles = ToResultFiles(attachmentSet, testResult.Id.ExecutionId.Id, testRun, trxFileDirectory); resultFiles.AddRange(testResultFiles); } } catch (Exception e) { string errorMsg = string.Format( CultureInfo.CurrentCulture, TrxLoggerResources.FailureToAttach, attachmentSet.DisplayName, e.GetType().ToString(), e.Message); StringBuilder stdErr = new StringBuilder(testResult.StdErr); stdErr.AppendLine(errorMsg); testResult.StdErr = stdErr.ToString(); testResult.Outcome = TrxObjectModel.TestOutcome.Error; } } if (addAttachments) { if (resultFiles.Count > 0) { testResult.AddResultFiles(resultFiles); } if (collectorEntries.Count > 0) { testResult.AddCollectorDataEntries(collectorEntries); } } }
// Returns a list of collector entry private static CollectorDataEntry ToCollectorEntry(ObjectModel.AttachmentSet attachmentSet, Guid testResultExecutionId, TestRun testRun, string trxFileDirectory) { string runDirectoryName = Path.Combine(trxFileDirectory, testRun.RunConfiguration.RunDeploymentRootDirectory); string inDirectory = Path.Combine(runDirectoryName, "In"); string targetDirectory = inDirectory; if (!testResultExecutionId.Equals(Guid.Empty)) { targetDirectory = Path.Combine(inDirectory, testResultExecutionId.ToString()); } targetDirectory = Path.Combine(targetDirectory, Environment.MachineName); if (!Directory.Exists(targetDirectory)) { Directory.CreateDirectory(targetDirectory); } List <IDataAttachment> uriDataAttachments = new List <IDataAttachment>(); foreach (ObjectModel.UriDataAttachment uriDataAttachment in attachmentSet.Attachments) { if (ObjectModel.EqtTrace.IsVerboseEnabled) { ObjectModel.EqtTrace.Verbose("TrxLogger: ToCollectorEntry: Got attachment " + uriDataAttachment.Uri + " with description " + uriDataAttachment.Description); } string sourceFile = uriDataAttachment.Uri.LocalPath; Debug.Assert(Path.IsPathRooted(sourceFile), "Source file is not rooted"); // copy the source file to the target location string targetFileName = FileHelper.GetNextIterationFileName(targetDirectory, Path.GetFileName(sourceFile), false); CopyFile(sourceFile, targetFileName); // Add the source file name to the collector files list. // (Trx viewer automatically adds In\ to the collected file. string fileName = Path.Combine(Environment.MachineName, Path.GetFileName(sourceFile)); Uri sourceFileUri = new Uri(fileName, UriKind.Relative); UriDataAttachment dataAttachment = new UriDataAttachment(uriDataAttachment.Description, sourceFileUri); uriDataAttachments.Add(dataAttachment); } return(new CollectorDataEntry( attachmentSet.Uri, attachmentSet.DisplayName, Environment.MachineName, Environment.MachineName, false, uriDataAttachments)); }