public void AddTestStep(ResultTestCase resultTestCase, ResultTestInfo resultTestInfo = null) { resultTestInfo.AttrTotalCases += 1; resultTestCase.NodeStepNumber += 1;//new object every time, so it would always be 1 and do the next step. resultTestCase.NodeStepNumber = resultTestInfo.AttrTotalCases; var thisDoc = XDoc ?? XDocument.Load(PathReportXml); if (thisDoc?.Root != null) { var testCases = thisDoc.Root.Elements(NodeTestcase); var xElement = AssembleElement(resultTestCase); if (!testCases.Any()) { thisDoc.Root.Add(xElement); } else { testCases.Last().AddAfterSelf(xElement); } } thisDoc?.Save(PathReportXml); if (resultTestInfo != null) { if (resultTestCase.NodeResult.Equals(Reporter.Result.FAIL)) { resultTestInfo.AttrFailures += 1; } else if (resultTestCase.NodeResult.Equals(Reporter.Result.BLOCK)) { resultTestInfo.AttrBlocks += 1; } else if (resultTestCase.NodeResult.Equals(Reporter.Result.PASS)) { resultTestInfo.AttrPasses += 1; } else if (resultTestCase.NodeResult.Equals(Reporter.Result.TBD)) { resultTestInfo.AttrTbds += 1; } resultTestInfo.AttrTime += resultTestCase.AttrTime; resultTestInfo.AttrPassesPercent = GetResultPercent(resultTestInfo.AttrPasses, resultTestInfo.AttrTotalCases, 1); resultTestInfo.AttrFailuresPercent = GetResultPercent(resultTestInfo.AttrFailures, resultTestInfo.AttrTotalCases, 1); resultTestInfo.AttrErrorsPercent = GetResultPercent(resultTestInfo.AttrErrors, resultTestInfo.AttrTotalCases, 1); resultTestInfo.AttrBlocksPercent = GetResultPercent(resultTestInfo.AttrBlocks, resultTestInfo.AttrTotalCases, 1); resultTestInfo.AttrTbdsPercent = GetResultPercent(resultTestInfo.AttrTbds, resultTestInfo.AttrTotalCases, 1); ModifyResultTestInfo(resultTestInfo); } }
private XElement AssembleElement(ResultTestCase resultTestCase) //(string classname, string stepTime, string functionName, string stepNumber, string description, string expectedResult, string needToCheck, string result) { return (new XElement( NodeTestcase, new XAttribute(AttrClassname, resultTestCase.AttrClassname ?? Reporter.DefaultContent), new XAttribute(AttrTime, resultTestCase.AttrTime), new XAttribute(AttrName, resultTestCase.AttrName ?? Reporter.DefaultContent), new XElement(NodeStep, resultTestCase.NodeStepNumber), new XElement(NodeDescription, resultTestCase.NodeDescription ?? Reporter.DefaultContent), // new XElement(NodeErrorMessage, resultTestCase.NodeErrorMessage ?? Reporter.DefaultContent), new XElement(NodeExpectedResult, resultTestCase.NodeExpectedResult ?? Reporter.DefaultContent), new XElement(NodeNeedToCheck, resultTestCase.NodeNeedToCheck ?? ""), new XElement(NodeResult, resultTestCase.NodeResult ?? Reporter.DefaultContent), new XElement( NodeFailure, new XAttribute(AttrMessage, resultTestCase.AttrMessage ?? Reporter.DefaultContent), new XAttribute(AttrType, Reporter.DefaultContent) ) )); }
public void Exec(Action action) { var xunitInfo = new TestFunctionInfo(3, _iReporter); _resultTestInfo.AttrName = xunitInfo.ClassName; var stepInfo = new TestFunctionInfo(2, _iReporter); var resultTestCase = new ResultTestCase(); var result = string.Empty; var dt = DateTime.Now; try { if (stepInfo.DoNotBlock) { _needToBlockAllTests = false; } if (_needToBlockAllTests) { result = Result.BLOCK; _resultTestInfo.AttrBlocks += 1; } else { Execute(action); result = Result.PASS; _resultTestInfo.AttrPasses += 1; } } catch (Exception) { result = Result.FAIL; _resultTestInfo.AttrFailures += 1; _needToBlockAllTests = true; throw; } finally { Capture("End Shot", ""); _resultTestInfo.AttrTotalCases += 1; resultTestCase.AttrClassname = xunitInfo.ClassFullName; resultTestCase.AttrName = xunitInfo.FunctionName; resultTestCase.AttrTime = DateDiff(dt, DateTime.Now); resultTestCase.NodeStepNumber = _stepNumber++; resultTestCase.NodeDescription = stepInfo.Descriptions; resultTestCase.NodeExpectedResult = stepInfo.ExpectedResults; resultTestCase.NodeNeedToCheck = _manualCheckLink; resultTestCase.NodeResult = result; _iReporter.AddTestStep(resultTestCase); _resultTestInfo.AttrTestName = xunitInfo.ClassName; _resultTestInfo.AttrTime += resultTestCase.AttrTime; _resultTestInfo.AttrPassesPercent = _iReporter.GetResultPercent(_resultTestInfo.AttrPasses, _resultTestInfo.AttrTotalCases, 1); _resultTestInfo.AttrFailuresPercent = _iReporter.GetResultPercent(_resultTestInfo.AttrFailures, _resultTestInfo.AttrTotalCases, 1); _resultTestInfo.AttrErrorsPercent = _iReporter.GetResultPercent(_resultTestInfo.AttrErrors, _resultTestInfo.AttrTotalCases, 1); _resultTestInfo.AttrBlocksPercent = _iReporter.GetResultPercent(_resultTestInfo.AttrBlocks, _resultTestInfo.AttrTotalCases, 1); _resultTestInfo.AttrTbdsPercent = _iReporter.GetResultPercent(_resultTestInfo.AttrTbds, _resultTestInfo.AttrTotalCases, 1); _iReporter.ModifyResultTestInfo(_resultTestInfo); } }