private void UpdateAllAttributesOfTestObject(XmlNode testObject) { if (testObject.Name == NodeNames.testCase.String()) { ResultAttributeValues result = GetTestCaseOutcome(testObject); _iTestCaseCount++; _iTotal++; if (result == ResultAttributeValues.Passed) { _iTotalPassed++; } else if (result == ResultAttributeValues.Failed) { _iTotalFailed++; } else if (result == ResultAttributeValues.Inconclusive) { _iTotalInconclusive++; } else if (result == ResultAttributeValues.Skipped) { _iTotalSkipped++; } else { Debug.Assert(true, "Test case result type: " + result.String() + " is not handled"); } int iTempAsserts = 0; if (int.TryParse(testObject.GetAttributeValue(TestSuiteAttributes.asserts.String()), out iTempAsserts)) { _iTotalAsserts += iTempAsserts; } return; } var childTestObjects = testObject.ChildNodes.Shim <XmlNode>() .Where(x => x.Name == NodeNames.testSuite.String() || x.Name == NodeNames.testCase.String()); bool bUpdateTestSuiteAttributes = false; string strRunState = "Ignored"; string strResult = string.Empty; int testCaseCount = 0; int total = 0; int passed = 0; int failed = 0; int inconclusive = 0; int skipped = 0; int asserts = 0; double duration = 0.0; //bool bHasChildTestSuites = false; foreach (XmlNode childTestObject in childTestObjects) { bUpdateTestSuiteAttributes = true; UpdateAllAttributesOfTestObject(childTestObject); if (childTestObject.GetAttributeValue(TestSuiteAttributes.runstate.String()) == RunStateAttributes.Runnable.String()) { strRunState = RunStateAttributes.Runnable.String(); } ResultAttributeValues result = GetTestCaseOutcome(childTestObject); if (string.IsNullOrEmpty(strResult) || resultsAsPerTheirPriorityLevel.IndexOf(result) < resultsAsPerTheirPriorityLevel.IndexOf((ResultAttributeValues)Enum.Parse(typeof(ResultAttributeValues), strResult))) { strResult = result.String(); } int iTemp = 0; if (int.TryParse(childTestObject.GetAttributeValue(TestSuiteAttributes.testcasecount.String()), out iTemp)) { testCaseCount += iTemp; } if (int.TryParse(childTestObject.GetAttributeValue(TestSuiteAttributes.total.String()), out iTemp)) { total += iTemp; } if (result != ResultAttributeValues.Skipped) { double dTempDuration = 0.0; if (double.TryParse(childTestObject.GetAttributeValue(TestSuiteAttributes.duration.String()), out dTempDuration)) { duration += dTempDuration; if (childTestObject.Name == NodeNames.testCase.String()) { _dTotalDuration += dTempDuration; } } } else { if (int.TryParse(childTestObject.GetAttributeValue(TestSuiteAttributes.skipped.String()), out iTemp)) { skipped += iTemp; } } if (int.TryParse(childTestObject.GetAttributeValue(TestSuiteAttributes.passed.String()), out iTemp)) { passed += iTemp; } if (int.TryParse(childTestObject.GetAttributeValue(TestSuiteAttributes.failed.String()), out iTemp)) { failed += iTemp; } if (int.TryParse(childTestObject.GetAttributeValue(TestSuiteAttributes.inconclusive.String()), out iTemp)) { inconclusive += iTemp; } if (int.TryParse(childTestObject.GetAttributeValue(TestSuiteAttributes.asserts.String()), out iTemp)) { asserts += iTemp; } //if (!bHasChildTestSuites && childTestObject.Name == NodeNames.testSuite.String()) //{ // bHasChildTestSuites = true; //} if (childTestObject.Name == NodeNames.testCase.String()) { testCaseCount++; total++; if (result == ResultAttributeValues.Passed) { passed++; } else if (result == ResultAttributeValues.Failed) { failed++; } else if (result == ResultAttributeValues.Skipped) { skipped++; } else if (result == ResultAttributeValues.Inconclusive) { inconclusive++; } else { Debug.Assert(true, "Test case result type: " + result.String() + " is not handled"); } } } if (bUpdateTestSuiteAttributes) { if (string.IsNullOrEmpty(strResult)) { strResult = ResultAttributeValues.Inconclusive.String(); } testObject.SetAttributeValue(TestSuiteAttributes.runstate.String(), strRunState); testObject.SetAttributeValue(TestSuiteAttributes.result.String(), strResult); testObject.SetAttributeValue(TestSuiteAttributes.testcasecount.String(), testCaseCount.ToString()); testObject.SetAttributeValue(TestSuiteAttributes.total.String(), total.ToString()); testObject.SetAttributeValue(TestSuiteAttributes.passed.String(), passed.ToString()); testObject.SetAttributeValue(TestSuiteAttributes.failed.String(), failed.ToString()); testObject.SetAttributeValue(TestSuiteAttributes.inconclusive.String(), inconclusive.ToString()); testObject.SetAttributeValue(TestSuiteAttributes.skipped.String(), skipped.ToString()); testObject.SetAttributeValue(TestSuiteAttributes.asserts.String(), asserts.ToString()); testObject.SetAttributeValue(TestSuiteAttributes.duration.String(), duration.ToString()); if (testObject.GetAttributeValue(TestSuiteAttributes.result.String()) != ResultAttributeValues.Failed.String()) { if (testObject.HasChildNodes) { var failureNodes = testObject.ChildNodes.Shim <XmlNode>().Where(x => x.Name == NodeNames.failure.String()); if (failureNodes.Count() > 0) { failureNodes = failureNodes.ToList(); foreach (var failureNode in failureNodes) { failureNode.ParentNode.RemoveChild(failureNode); } } } } else if (testObject.HasChildNodes) { var failureNodes = testObject.ChildNodes.Shim <XmlNode>().Where(x => x.Name == NodeNames.failure.String()); if (failureNodes.Count() <= 0) { testObject.PrependChild(CreateANewFailureNode(testObject.OwnerDocument)); } } //if (bHasChildTestSuites) //{ // testObject.SetAttributeValue(TestSuiteAttributes.site.String(), SiteAttributes.Child.String()); //} } }
private void UpdateAllAttributesOfTestObject(XmlNode testObject) { if (testObject.Name == NodeNames.testCase.String()) { ResultAttributeValues result = GetTestCaseOutcome(testObject); _iTotal++; if (result == ResultAttributeValues.Failure) { _iTotalFailures++; } else if (result == ResultAttributeValues.Inconclusive) { _iTotalInconclusive++; } else if (result == ResultAttributeValues.Ignored) { _iTotalNotRun++; _iTotalIgnored++; } else { Debug.Assert(true); } return; } var childResultNode = GetChildResultsNode(testObject); var childTestObjects = childResultNode.ChildNodes.Shim <XmlNode>() .Where(x => x.Name == NodeNames.testSuite.String() || x.Name == NodeNames.testCase.String()); bool bUpdateTestSuiteAttributes = false; string strExecuted = "False"; string strResult = string.Empty; string strSuccess = "True"; double dTime = 0.0; int iAssert = 0; foreach (XmlNode childTestObject in childTestObjects) { UpdateAllAttributesOfTestObject(childTestObject); bUpdateTestSuiteAttributes = true; if (childTestObject.GetAttributeValue(TestSuiteAttributes.executed.String()) == "True") { strExecuted = "True"; } ResultAttributeValues result = GetTestCaseOutcome(childTestObject); if (string.IsNullOrEmpty(strResult) || resultsAsPerTheirPriorityLevel.IndexOf(result) < resultsAsPerTheirPriorityLevel.IndexOf((ResultAttributeValues)Enum.Parse(typeof(ResultAttributeValues), strResult))) { strResult = result.String(); } if (result != ResultAttributeValues.Ignored) { if (childTestObject.GetAttributeValue(TestSuiteAttributes.success.String()) == "False") { strSuccess = "False"; } double dTempTime = 0.0; if (double.TryParse(childTestObject.GetAttributeValue(TestSuiteAttributes.time.String()), out dTempTime)) { dTime += dTempTime; } int iTempAsserts = 0; if (int.TryParse(childTestObject.GetAttributeValue(TestSuiteAttributes.asserts.String()), out iTempAsserts)) { iAssert += iTempAsserts; } } } if (bUpdateTestSuiteAttributes) { if (string.IsNullOrEmpty(strResult)) { strResult = ResultAttributeValues.Inconclusive.String(); } if (strResult != ResultAttributeValues.Success.String()) { strSuccess = "False"; } testObject.SetAttributeValue(TestSuiteAttributes.executed.String(), strExecuted); testObject.SetAttributeValue(TestSuiteAttributes.result.String(), strResult); if (strResult != ResultAttributeValues.Ignored.String()) { testObject.SetAttributeValue(TestSuiteAttributes.success.String(), strSuccess); testObject.SetAttributeValue(TestSuiteAttributes.time.String(), dTime.ToString()); testObject.SetAttributeValue(TestSuiteAttributes.asserts.String(), iAssert.ToString()); } if (testObject.GetAttributeValue(TestSuiteAttributes.result.String()) != ResultAttributeValues.Failure.String()) { if (testObject.HasChildNodes) { var failureNodes = testObject.ChildNodes.Shim <XmlNode>().Where(x => x.Name == NodeNames.failure.String()); if (failureNodes.Count() > 0) { failureNodes = failureNodes.ToList(); foreach (var failureNode in failureNodes) { failureNode.ParentNode.RemoveChild(failureNode); } } } } else if (testObject.HasChildNodes) { var failureNodes = testObject.ChildNodes.Shim <XmlNode>().Where(x => x.Name == NodeNames.failure.String()); if (failureNodes.Count() <= 0) { testObject.PrependChild(CreateANewFailureNode(testObject.OwnerDocument)); } } } }