/// <summary> /// Processes the StatLight result. /// </summary> /// <param name="testRun">The test run.</param> /// <returns>The test results.</returns> internal IEnumerable <TrxResult> ProcessStatLightResult(TestRunType testRun) { IEnumerable <TrxResult> trxResults = new List <TrxResult>(); TestDefinitionType definition = GetDefinitions(testRun); ResultsType results = GetResults(testRun); if (definition == null || results == null) { return(trxResults); } if (definition.Items == null || results.Items == null) { return(trxResults); } IEnumerable <UnitTestType> unitTestDefinitions = definition.Items.OfType <UnitTestType>(); IEnumerable <UnitTestResultType> items = results.Items.OfType <UnitTestResultType>(); trxResults = from e in unitTestDefinitions from f in items from g in this.TestCases where e.id == f.testId && g.FullyQualifiedName == string.Concat(e.TestMethod.className, ".", e.TestMethod.name) select new TrxResult { UnitTest = e, UnitTestResult = f, TestCase = g }; return(trxResults); }
public TrxResultsParser(string filename) { // Deserialize _testRunType = DeserializeFile <TestRunType>(filename); // Parse Results collection and Times element from the report var resultsType = new ResultsType(); var testDefinitions = new TestRunTypeTestDefinitions(); foreach (var item in _testRunType.Items) { TypeSwitch.Switch(item, TypeSwitch.Case <ResultsType>((results) => resultsType = results), TypeSwitch.Case <TestRunTypeTimes>((results) => _testRunTimes = results), TypeSwitch.Case <TestRunTypeTestDefinitions>((results) => testDefinitions = results) ); } _resultsFromReport = resultsType.Items.Select(item => (UnitTestResultType)item); // Extract the codebase (name of DLL from the first record) FileName = Path.GetFileNameWithoutExtension( testDefinitions.Items[0] == null ? string.Empty : ((UnitTestType)testDefinitions.Items[0]).TestMethod.codeBase); }
public void Write(XmlWriter writer, TestRunType testRun) { try { _serializer.Serialize(writer, testRun, new XmlSerializerNamespaces(new XmlQualifiedName[] { new XmlQualifiedName(string.Empty, "http://microsoft.com/schemas/VisualStudio/TeamTest/2010") })); } catch (Exception) { throw; } finally { if (writer != null) { try { writer.Close(); } catch { } } } }
/// <summary> /// Reads the specified TRX file path. /// </summary> /// <param name="trxFilePath">The TRX file path.</param> /// <returns>The test run.</returns> internal TestRunType Read(string trxFilePath) { TestRunType testRunType; TestRunType testRun = null; if (File.Exists(trxFilePath)) { try { StreamReader fileStreamReader = new StreamReader(trxFilePath); try { XmlSerializer serializer = new XmlSerializer(typeof(TestRunType)); testRun = (TestRunType)serializer.Deserialize(fileStreamReader); } finally { fileStreamReader.Dispose(); } } catch (Exception exception) { this.logger.SendMessage(TestMessageLevel.Error, string.Concat(Localized.ErrorOnDeserializeTrxFile, trxFilePath)); this.logger.SendMessage(TestMessageLevel.Error, exception.ToString()); testRunType = testRun; return(testRunType); } } testRunType = testRun; return(testRunType); }
private List <TestResultViewModel> GetFilteredTestResults(TestRunType testRunType) { return(GetLastTestRuns(testRunType) .Where(t => !t.HasMidnightErrors && !t.HasTooManyErrors && !t.HasSeleniumGridErrors) .SelectMany(s => s.Results) .ToList()); }
public void Initialize() { _testRun = new TestRunType { id = "570a67dd-14b3-4443-881a-850c376edee9", name = "Web Test Allegra.com", runUser = "******" }; }
public TestRunMetaData(string fileName, FlytApplication applicationType, DateTime lastRun, TestRunType testRunType, int buildNumber, int duration) { OriginalFileName = fileName; FlytApplicationType = applicationType; LastRun = lastRun; TestRunType = testRunType; BuildNumber = buildNumber; Duration = duration / 60; }
public void Will_generate_trx_xml() { //Since the generated file is through GUID, we cannot do a simply string compare. var transformer = new TrxXmlTransformer(GetFileSystemWrapper()); var summary = BuildTestCaseSummary(); var result = transformer.Transform(summary); XmlReader xr = new XmlTextReader(new StringReader(result)); XmlSerializer xs = new XmlSerializer(typeof(TestRunType)); Assert.True(xs.CanDeserialize(xr)); TestRunType trx = (TestRunType)xs.Deserialize(xr); var testDefinitions = trx.Items.GetInstance <TestDefinitionType>(VSTSExtensions.TestRunItemType.TestDefinition).Items.Cast <UnitTestType>().ToArray(); Assert.Equal(testDefinitions.Count(), 4); for (int i = 0; i < testDefinitions.Count(); i++) { var vststUnitTest = testDefinitions[i]; var testSummary = summary.Tests[i]; Assert.Equal(vststUnitTest.TestMethod.name, testSummary.TestName); Assert.Equal(vststUnitTest.TestMethod.adapterTypeName, "Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapter"); } var testResults = trx.Items.GetInstance <ResultsType>(VSTSExtensions.TestRunItemType.Results).Items.Cast <UnitTestResultType>().ToArray(); Assert.Equal(testResults.Count(), 4); for (int i = 0; i < testResults.Count(); i++) { var vststUnitTestResult = testResults[i]; var testSummary = summary.Tests[i]; Assert.Equal(vststUnitTestResult.testName, testSummary.TestName); Assert.Equal(vststUnitTestResult.outcome, testSummary.Passed ? "Passed":"Failed"); if (vststUnitTestResult.Items != null && vststUnitTestResult.Items.Any()) { Assert.Equal(((OutputType)vststUnitTestResult.Items[0]).ErrorInfo.Message, testSummary.TestResults[0].Message); } } var counters = (CountersType) trx.Items.GetInstance <TestRunTypeResultSummary>(VSTSExtensions.TestRunItemType.ResultSummary) .Items.First(); Assert.Equal(counters.passed, 2); Assert.Equal(counters.failed, 2); TestRunType trxObject; }
public void Execute(string fileName) { //Suck in the file & turn it into a test run type. StreamReader fileStreamReader = new StreamReader(fileName); XmlSerializer xmlSer = new XmlSerializer(typeof(TestRunType)); TestRunType testRunType = (TestRunType)xmlSer.Deserialize(fileStreamReader); //Send the test run type to the joker this._joker.Generate(testRunType); }
public void Write(TextWriter writer, TestRunType testRun) { var xmlWriterSettings = new XmlWriterSettings { Encoding = Utf8EncodingWithNoByteOrderMark, Indent = true }; var xmlWriter = XmlWriter.Create(writer, xmlWriterSettings); Write(xmlWriter, testRun); }
public TestResults(string trxFile) { var serializer = new XmlSerializer(typeof(TestRunType)); using (var fileStream = File.OpenRead(trxFile)) { _testRunType = (TestRunType)serializer.Deserialize(fileStream); } _testRunType.Items.OfType <TestRunTypeResultSummary>().Content().Items.OfType <CountersType>().Content(); FullPath = trxFile; }
/// <summary> /// Gets the test results. /// </summary> /// <param name="testRun">The test run.</param> /// <returns>The test results.</returns> internal static ResultsType GetResults(TestRunType testRun) { if (testRun == null) { return(null); } return(( from e in testRun.Items where e is ResultsType select e).First() as ResultsType); }
/// <summary> /// Gets the definitions. /// </summary> /// <param name="testRun">The test run.</param> /// <returns>The test definitions.</returns> internal static TestDefinitionType GetDefinitions(TestRunType testRun) { if (testRun == null) { return(null); } return(( from e in testRun.Items where e is TestDefinitionType select e).First() as TestDefinitionType); }
public DataTable GetTestResultData() { string fileName; DataTable testResultTable = null; try { // Construct DirectoryInfo for the folder path passed in as an argument string baseDirectory = AppDomain.CurrentDomain.BaseDirectory; //baseDirectory = baseDirectory.Substring(0, baseDirectory.IndexOf("bin")); DirectoryInfo di = new DirectoryInfo(baseDirectory); ResultTable resultTable = new ResultTable(); testResultTable = resultTable.CreateTestResultTable(); // For each .trx file in the given folder process it foreach (FileInfo file in di.GetFiles("*.trx")) { fileName = file.Name; // Deserialize TestRunType object from the trx file StreamReader fileStreamReader = new StreamReader(file.FullName); XmlSerializer xmlSer = new XmlSerializer(typeof(TestRunType)); TestRunType testRunType = (TestRunType)xmlSer.Deserialize(fileStreamReader); // Navigate to UnitTestResultType object and update the sheet with test result information foreach (object itob1 in testRunType.Items) { ResultsType resultsType = itob1 as ResultsType; if (resultsType != null) { foreach (object itob2 in resultsType.Items) { UnitTestResultType unitTestResultType = itob2 as UnitTestResultType; if (unitTestResultType != null) { DataRow row = testResultTable.NewRow(); row[Constant.PROCESSEDFILENAME] = fileName; row[Constant.TESTID] = unitTestResultType.testId; row[Constant.TESTNAME] = unitTestResultType.testName; row[Constant.TESTOUTCOME] = unitTestResultType.outcome; row[Constant.ERRORMESSAGE] = ((System.Xml.XmlNode[])(((OutputType)(((TestResultType)(unitTestResultType)).Items[0])).ErrorInfo.Message))[0].Value; testResultTable.Rows.Add(row); } } } } } } catch (Exception) { } return(testResultTable); }
public List <TestRunViewModel> GetLastTestRuns(TestRunType type) { using (var db = new CollectorContext()) { var testResultViewModels = from testResult in db.TestResults join testRun in db.TestRuns on testResult.TestRunId equals testRun.Id where testRun.TestRunType == type && testRun.LastRun > _twoMonthsAgo select new TestResultViewModel(new TestResult(testResult, testRun)); return(testResultViewModels .ToList() .GroupBy(t => t.TestResult.TestRunMetaData.Id) .Select(grp => new TestRunViewModel(grp.ToList())) .ToList()); } }
public TestRunViewModel GetTestRun(TestRunType type, FlytApplication app, int version) { using (var db = new CollectorContext()) { var testResultViewModels = from testResult in db.TestResults join testRun in db.TestRuns on testResult.TestRunId equals testRun.Id where testRun.TestRunType == type && testRun.FlytApplicationType == app && testRun.BuildNumber == version select new TestResultViewModel(new TestResult(testResult, testRun)); return(testResultViewModels .ToList() .GroupBy(t => t.TestResult.TestRunMetaData.Id) .Select(grp => new TestRunViewModel(grp.ToList())) .First()); } }
/// <summary> /// Processes the results. /// </summary> /// <param name="tests">The tests.</param> /// <param name="argument">The argument.</param> /// <param name="frameworkHandle">The framework handle.</param> internal void ProcessResults(IEnumerable <TestCase> tests, TestCaseArgument argument, IFrameworkHandle frameworkHandle) { TrxSchemaReader reader = new TrxSchemaReader(this.logger, tests); TestRunType testRun = reader.Read(argument.TestRunOptions.ReportOutputPath); if (testRun == null) { return; } foreach (TrxResult result in reader.ProcessStatLightResult(testRun)) { TestResult testResult = result.GetTestResult(this.logger); frameworkHandle.RecordResult(testResult); frameworkHandle.RecordEnd(result.TestCase, testResult.Outcome); } }
private void Testresult() { var testRun = new TestRunType(); var resultContainer = new ResultsType(); var definitionContainer = new TestDefinitionType(); resultContainer.Items = results.ToArray(); definitionContainer.Items = definitions.ToArray(); resultContainer.ItemsElementName = new ItemsChoiceType3[results.Count]; definitionContainer.ItemsElementName = new ItemsChoiceType4[results.Count]; for (int i = 0; i < results.Count; i++) { resultContainer.ItemsElementName[i] = ItemsChoiceType3.UnitTestResult; definitionContainer.ItemsElementName[i] = ItemsChoiceType4.UnitTest; } testRun.Items = new List <object> { resultContainer, definitionContainer }.ToArray(); string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "smoketestresult.trx"); var x = new XmlSerializer(testRun.GetType()); var xmlnsEmpty = new XmlSerializerNamespaces(); xmlnsEmpty.Add("x", "http://microsoft.com/schemas/VisualStudio/TeamTest/2010"); xmlnsEmpty.Add("x1", "http://www.w3.org/2001/XMLSchema-instance"); xmlnsEmpty.Add("x2", "http://www.w3.org/2001/XMLSchema"); using (var fs = new FileStream(filePath, FileMode.Create, FileAccess.Write)) { x.Serialize(fs, testRun, xmlnsEmpty); fs.Flush(); } //Replace namespaces because on the publish test results to TFS, TFS doesnt accept the namespaces and we couldn't suppress them during serialization string text = File.ReadAllText(filePath); text = text.Replace("x:", ""); text = text.Replace("x1:", ""); text = text.Replace("x2:", ""); text = text.Replace("xmlns:x=\"http://microsoft.com/schemas/VisualStudio/TeamTest/2010\"", "xmlns=\"http://microsoft.com/schemas/VisualStudio/TeamTest/2010\""); text = text.Replace("xmlns:x1=\"http://www.w3.org/2001/XMLSchema-instance\"", ""); text = text.Replace("xmlns:x2=\"http://www.w3.org/2001/XMLSchema\"", ""); File.WriteAllText(filePath, text); }
private IRestResponse GetTestRunTask <T>(TestRunType testRunType, T taskParams) { int testBuildId = -1; string content = string.Empty; string statusCode = string.Empty; Type paramType = taskParams.GetType(); BaseUtils baseUtils = new BaseUtils(); try { if (paramType == typeof(int)) { testBuildId = baseUtils.ConvertToType <int>(taskParams); } else if (paramType == typeof(object[])) { testBuildId = (int)baseUtils.ConvertToType <object[]>(taskParams)[0]; } var testRunTaskParms = new object[] { testRunType, testBuildId, }; var testRunTask = CallExecuteRequest(Method.GET, ResourceType.TestRuns, null, testRunTaskParms); Task.WaitAll(testRunTask); var response = testRunTask.Result; statusCode = response.StatusCode.ToString(); content = response.Content; return(response); } catch (Exception e) { log.Debug($"Get TestRun Task StatusCode: {statusCode}\n{e.Message}"); log.Debug(content); throw; } }
public override string Transform(TestCaseSummary testFileSummary) { if (testFileSummary == null) { throw new ArgumentNullException("testFileSummary"); } testRun = new TestRunType { id = Guid.NewGuid().ToString(), name = "Chutzpah_JS_UnitTest_" + DateTime.Now.ToString("yy-MMM-dd hh:mm:ss zz") }; var windowsIdentity = System.Security.Principal.WindowsIdentity.GetCurrent(); if (windowsIdentity != null) { testRun.runUser = windowsIdentity.Name; } testRun.Items = new object[] { new TestRunTypeResultSummary(), new ResultsType(), new TestDefinitionType(), new TestEntriesType1(), new TestRunTypeTestLists(), new TestRunTypeTimes(), new TestSettingsType { name = "Default", id = Guid.NewGuid().ToString(), Execution = new TestSettingsTypeExecution { TestTypeSpecific = new TestSettingsTypeExecutionTestTypeSpecific { } } } }; // Time taken is current time testRun.Items.GetInstance <TestRunTypeTimes>(VSTSExtensions.TestRunItemType.Times).creation = DateTime.Now.AddSeconds(-testFileSummary.TimeTaken).ToString("O"); testRun.Items.GetInstance <TestRunTypeTimes>(VSTSExtensions.TestRunItemType.Times).start = DateTime.Now.AddSeconds(-testFileSummary.TimeTaken).ToString("O"); testRun.Items.GetInstance <TestRunTypeTimes>(VSTSExtensions.TestRunItemType.Times).queuing = DateTime.Now.AddSeconds(-testFileSummary.TimeTaken).ToString("O"); var testList = new TestListType { name = "Results Not in a List", id = Guid.NewGuid().ToString() }; var testTypeId = Guid.NewGuid(); var currentTestCases = testFileSummary.Tests.Select(x => new VSTSTestCase().UpdateWith(x)); var testsHelper = currentTestCases.ToList(); testRun.Items.GetInstance <TestRunTypeTimes>(VSTSExtensions.TestRunItemType.Times).finish = DateTime.Now.ToString("O"); testRun.Items.GetInstance <TestRunTypeResultSummary>(VSTSExtensions.TestRunItemType.ResultSummary).outcome = testsHelper.Count(x => x.Passed) == testsHelper.Count() ? "Passed" : "Failed"; var counter = new CountersType { aborted = 0, completed = 0, disconnected = 0, error = 0, passed = testsHelper.Count(x => x.Passed), executed = testsHelper.Count, failed = testsHelper.Count(x => !x.Passed), total = testsHelper.Count, inProgress = 0, pending = 0, warning = 0, notExecuted = 0, notRunnable = 0, passedButRunAborted = 0, inconclusive = 0, timeout = 0 }; // total attribute is not written if totalSpecified is false counter.totalSpecified = true; testRun.Items.GetInstance <TestRunTypeResultSummary>(VSTSExtensions.TestRunItemType.ResultSummary).Items = new object[] { counter }; testRun.Items.GetInstance <TestDefinitionType>(VSTSExtensions.TestRunItemType.TestDefinition).Items = testsHelper .Select( (testCase) => new UnitTestType { id = testCase.Id.ToString(), name = testCase.TestName, storage = testCase.InputTestFile, Items = new[] { new BaseTestTypeExecution { id = testCase.ExecutionId.ToString() } }, TestMethod = new UnitTestTypeTestMethod { adapterTypeName = "Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapter", className = Path.GetFileNameWithoutExtension(testCase.InputTestFile), codeBase = testCase.InputTestFile, name = testCase.TestName } }).ToArray(); testRun.Items.GetInstance <TestDefinitionType>(VSTSExtensions.TestRunItemType.TestDefinition).ItemsElementName = testsHelper .Select( (testCase) => ItemsChoiceType4.UnitTest).ToArray(); testRun.Items.GetInstance <TestRunTypeTestLists>(VSTSExtensions.TestRunItemType.TestLists).TestList = new[] { testList, // This has to be hard-coded. new TestListType { name = "All Loaded Results", id = "19431567-8539-422a-85d7-44ee4e166bda" } }; testRun.Items.GetInstance <TestEntriesType1>(VSTSExtensions.TestRunItemType.TestEntries).TestEntry = testsHelper.Select(testCase => new TestEntryType { testId = testCase.Id.ToString(), executionId = testCase.ExecutionId.ToString(), testListId = testList.id }).ToArray(); testRun.Items.GetInstance <ResultsType>(VSTSExtensions.TestRunItemType.Results).Items = testsHelper.Select((testCase) => { var unitTestResultType = new UnitTestResultType { executionId = testCase.ExecutionId.ToString(), testId = testCase.Id.ToString(), testName = testCase.TestName, computerName = Environment.MachineName, duration = new TimeSpan(0, 0, testCase.TimeTaken).ToString("c"), // I tried adding this to StandardConsoleRunner, but it demanded too many changes. // Setting start to the creation date. startTime = DateTime.Now.AddSeconds(-testFileSummary.TimeTaken).ToString("O"), // Setting end time to creation date + time taken to run this test. endTime = DateTime.Now.AddSeconds((-testFileSummary.TimeTaken) + testCase.TimeTaken).ToString("O"), // This is for specific test type. testType = "13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b", outcome = testCase.Passed ? "Passed" : "Failed", testListId = testList.id, }; if (!testCase.Passed) { unitTestResultType.Items = new[] { new OutputType() { ErrorInfo = new OutputTypeErrorInfo { Message = testCase.exception != null ? testCase.exception.ToString(): string.Join(",", testCase.TestResults.Where(x => !x.Passed).Select(x => x.Message)) } } }; } return(unitTestResultType); }).ToArray(); testRun.Items.GetInstance <ResultsType>(VSTSExtensions.TestRunItemType.Results).ItemsElementName = testsHelper.Select(testCase => ItemsChoiceType3.UnitTestResult).ToArray(); var ns = new XmlSerializerNamespaces(); ns.Add("", "http://microsoft.com/schemas/VisualStudio/TeamTest/2010"); var stringStream = new StringWriter(); var xs = new XmlSerializer(typeof(TestRunType)); xs.Serialize(stringStream, testRun, ns); return(stringStream.ToString()); }
public TestRunType GenerateTestRun(string name, string description, DateTime start, DateTime finish, DateTime creation, DateTime queuing, List <HttpRequestResult> results) { if (results == null) { return(null); } var testRun = new TestRunType() { id = Guid.NewGuid().ToString(), name = name, runUser = System.Environment.UserName }; var testListId = Guid.NewGuid(); var unitTestTypeId = Guid.NewGuid(); var testSettings = GenerateTestSettings(name, description, unitTestTypeId); var testList = GenerateTestList("Web Crawl Test", testListId); var times = GenerateTimes(start, finish, creation, queuing); var summary = GenerateSummary(results); var unitTests = new List <UnitTestType>(); var testEntries = new List <TestEntryType>(); var testResults = new List <object>(); var testResultTypes = new List <ItemsChoiceType3>(); foreach (HttpRequestResult result in results) { var storage = string.Empty; var unitTestId = Guid.NewGuid(); var executionId = Guid.NewGuid(); unitTests.Add(GenerateUnitTest(string.Format("Browser = {0}, RequestUrl = {1}", result.BrowserUsed.Name, result.RequestUrl.AbsoluteUri), storage, unitTestId, executionId, result.GetType())); testEntries.Add(GenerateTestEntry(unitTestId, executionId, testListId)); testResults.Add(GenerateUnitTestResult(executionId, unitTestId, unitTestTypeId, testListId, result)); testResultTypes.Add(ItemsChoiceType3.UnitTestResult); } testRun.Items = new object[] { testSettings, // TODO: TestSettings! times, summary, new TestRunTypeTestLists() { TestList = new TestListType[] { testList } }, new TestEntriesType1() { TestEntry = testEntries.ToArray() }, new ResultsType() { Items = testResults.ToArray(), ItemsElementName = testResultTypes.ToArray() } }; return(testRun); }
/// <summary> /// Maps result types from TRX into instance of drop models with configuration /// </summary> /// <param name="source">Instance of test results from deserialised TRX input</param> /// <param name="destination">Instance to map and merge results into</param> /// <param name="inputConfiguration">User configured input for current source</param> public static void Map(TestRunType source, TestRunDrop destination, ReportInput inputConfiguration = null) { var times = source.Times.FirstOrDefault(); var started = DateTimeOffset.Parse(times.Start); var finished = DateTimeOffset.Parse(times.Finish); if (destination.Started is null || destination.Started > started) { destination.Started = started; } if (destination.Finished is null || destination.Finished < finished) { destination.Finished = finished; } var definitions = source.TestDefinitions.SelectMany(x => x.UnitTest).ToDictionary(k => k.Id, v => v); var unitTestResultsGroup = source.Results .SelectMany(r => r.UnitTestResult) .Select(r => (result: r, definition: definitions[r.TestId])) .GroupBy(t => inputConfiguration?.GroupTitle ?? StringFilters.PathSplit(t.definition.TestMethod.CodeBase).Last()) // Group by codebase if no title is provided .ToList(); foreach (var resultGroup in unitTestResultsGroup) { TestResultSetDrop drop; if (destination.ResultSets.TryGetValue(resultGroup.Key, out var existingDrop)) { drop = existingDrop; } else { drop = new TestResultSetDrop { Source = resultGroup.Key, Results = new List <TestResultDrop>(), }; destination.ResultSets.Add(drop); } foreach (var(result, definition) in resultGroup) { foreach (var unitTestResults in ExtractTestResults(result)) { var testCase = new TestCaseDrop { Source = definition.TestMethod.CodeBase, DisplayName = string.IsNullOrEmpty(inputConfiguration?.TestSuffix) ? unitTestResults.TestName : $"{unitTestResults.TestName}{inputConfiguration.TestSuffix}", FullyQualifiedName = $"{definition.TestMethod.ClassName}.{definition.TestMethod.Name}", Id = Guid.Parse(definition.Id), ExecutorUri = definition.TestMethod.AdapterTypeName, }; var startTime = DateTimeOffset.Parse(unitTestResults.StartTime); var endTime = DateTimeOffset.Parse(unitTestResults.EndTime); var duration = (endTime - startTime); var outcome = MapOutcome(unitTestResults.Outcome, drop, destination.TestRunStatistics); var resultDrop = new TestResultDrop { StartTime = startTime, EndTime = endTime, Duration = duration, Outcome = outcome, TestCase = testCase, ComputerName = unitTestResults.ComputerName, AttachmentSets = new List <AttachmentSetDrop>(unitTestResults.CollectorDataEntries.Select(rf => new AttachmentSetDrop { Attachments = new List <AttachmentDrop>(rf.Collector.Select(c => new AttachmentDrop { Description = c.CollectorDisplayName, Uri = c.Uri })) })), DisplayName = definition.TestMethod.Name }; MapOutputToResult(unitTestResults.Output, resultDrop); destination.TestRunStatistics.ExecutedTestsCount++; destination.ElapsedTimeInRunningTests += duration; drop.Duration += duration; drop.ExecutedTestsCount++; drop.Results.Add(resultDrop); } } } }
internal static ContentManagementClient CreateContentManagementClient(ContentManagementOptions options, TestRunType runType, string testName) { if (runType != TestRunType.LiveEndPoint) { var saveToFileSystem = runType == TestRunType.LiveEndPoint_SaveToFileSystem; var httpClient = new FileSystemHttpClientMock(options, saveToFileSystem, testName); var urlBuilder = new EndpointUrlBuilder(options); var actionInvoker = new ActionInvoker(httpClient, new MessageCreator(options.ApiKey)); return(new ContentManagementClient(urlBuilder, actionInvoker)); } return(new ContentManagementClient(options)); }
public override void SaveReport(IList <MutationDocumentResult> mutations, TimeSpan exectutionTime) { Log.Info("Saving TRX report.."); if (!mutations.Any()) { Log.Info("No mutations to report."); return; } try { var unitTestResults = CreateUnitTestResults(mutations); var results = new ResultsType { Items = new List <UnitTestResultType>(unitTestResults).ToArray(), }; results.ItemsElementName = new ItemsChoiceType3[results.Items.Length]; for (int n = 0; n < results.Items.Length; n++) { results.ItemsElementName[n] = ItemsChoiceType3.UnitTestResult; } var testRunType = new TestRunType { id = Guid.NewGuid().ToString(), name = "mutation", Items = new object[] { new TestRunTypeTimes { creation = DateTime.Now.ToString(), finish = DateTime.Now.ToString(), start = DateTime.Now.ToString() }, new TestRunTypeResultSummary { outcome = mutations.All(m => !m.Survived) ? "Passed" : "Failed", Items = new object[] { new CountersType { passed = mutations.Count(s => !s.Survived && s.CompilationResult != null && s.CompilationResult.IsSuccess), failed = mutations.Count(s => s.Survived && s.CompilationResult != null && s.CompilationResult.IsSuccess), completed = mutations.Count(s => s.CompilationResult != null && s.CompilationResult.IsSuccess), error = mutations.Count(s => s.CompilationResult == null || !s.CompilationResult.IsSuccess) } } }, results, CreateTestDefinitions(results), CreateTestEntries(results), new TestRunTypeTestLists() { TestList = new TestListType[] { new TestListType() { id = results.Items.Any() ? ((UnitTestResultType)results.Items[0]).testListId : "No result found", name = "All Loaded Results" } } } } }; var xmlSerializer = new XmlSerializer(typeof(TestRunType)); using (var textWriter = new StringWriter()) { xmlSerializer.Serialize(textWriter, testRunType); var xml = textWriter .ToString() .Replace(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"", string.Empty) .Replace(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"", string.Empty) .Replace(" xsi:type=\"xsd:string\"", string.Empty); File.WriteAllText(SavePath, xml); } } catch (Exception ex) { Log.Error("Failed to save TRX report", ex); throw; } Log.Info("TRX report saved successfully."); }
public void Generate(TestRunType testRunType) { //Output a file with the details of the test run. }
private Task <IRestResponse> ExecuteRequest(Method requestMethod, ResourceType resource, RootObject json = null, params object[] requestParams) { int buildId; int testRunId; int testResultId; int testSnapshotId; string endPoint = string.Empty; string content = string.Empty; string statusCode = string.Empty; BaseUtils baseUtils = new BaseUtils(); try { switch (resource) { case ResourceType.TestRuns: if (requestMethod == Method.GET) { TestRunType testRunType = (TestRunType)requestParams[0]; testRunId = baseUtils.ConvertToType <int>(requestParams[1]); if (testRunType == TestRunType.GetTest) { testSnapshotId = baseUtils.ConvertToType <int>(requestParams[3]); bool allTests = baseUtils.ConvertToType <bool>(requestParams[2]); endPoint = allTests ? $"/test_runs/{testRunId}/test_snapshots" : $"/test_runs/{testRunId}"; } else if (testRunType == TestRunType.Sync) { endPoint = $"/test_runs/{testRunId}?show_synchronization_information=true"; } } else { endPoint = "/test_runs"; } break; case ResourceType.TestResults: if (requestMethod == Method.POST) { testRunId = baseUtils.ConvertToType <int>(requestParams[0]); buildId = baseUtils.ConvertToType <int>(requestParams[1]); endPoint = $"/test_runs/{testRunId}/builds/{buildId}/test_results"; } else if (requestMethod == Method.PATCH) { testRunId = baseUtils.ConvertToType <int>(requestParams[0]); testSnapshotId = baseUtils.ConvertToType <int>(requestParams[1]); testResultId = baseUtils.ConvertToType <int>(requestParams[2]); endPoint = $"/test_runs/{testRunId}/test_snapshots/{testSnapshotId}/test_results/{testResultId}"; } else { testRunId = baseUtils.ConvertToType <int>(requestParams[0]); testSnapshotId = baseUtils.ConvertToType <int>(requestParams[1]); endPoint = $"/test_runs/{testRunId}/test_snapshots/{testSnapshotId}?include=last-result"; } break; case ResourceType.TestSnapshots: testRunId = baseUtils.ConvertToType <int>(requestParams[0]); endPoint = $"/test_runs/{testRunId}/test_snapshots?include=scenario"; break; } IRestRequest request = CreateRequest(requestMethod, endPoint); if (json != null) { request.AddJsonBody(json); } log.Info($"API Endpoint: {endPoint}"); IRestClient client = new RestClient(ApiBase); var responseTask = Task.Factory.StartNew(() => client.Execute(request)); Task.WaitAny(responseTask); var response = responseTask.Result; statusCode = response.StatusCode.ToString(); content = response.Content; return(responseTask); } catch (Exception e) { log.Debug($"ExecuteRequest StatusCode: {statusCode}\n{e.Message}"); log.Debug(content); throw; } }