/// <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); }
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 static TestRunType GetVSTestRun(TestRunInfo testRunInfo) { var results = new ResultsType() { Items = testRunInfo.Tests.Select(MapTestResult).ToArray(), ItemsElementName = testRunInfo.Tests.Select(_ => ItemsChoiceType3.UnitTestResult).ToArray() }; var testDefinitions = new TestDefinitionType() { Items = testRunInfo.Tests.Select(MapTestDefinition).ToArray(), ItemsElementName = testRunInfo.Tests.Select(_ => ItemsChoiceType4.UnitTest).ToArray() }; var testEntries = new TestEntriesType1() { TestEntry = testRunInfo.Tests.Select(MapTestEntry).ToArray(), }; var testLists = new TestRunTypeTestLists() { TestList = new[] { new TestListType() { name = "Results Not in a List", id = TestListId }, new TestListType() { name = "All Loaded Results", id = "19431567-8539-422a-85d7-44ee4e166bda" } } }; var resultsSummary = MapSummary(testRunInfo); return(new TestRunType() { id = Guid.NewGuid().ToString(), Items = new object[] { results, testDefinitions, testEntries, testLists, resultsSummary } }); }