public List<XmlNode> BuildRowNode(ResultHolder dataHolder, Result result) { List<XmlNode> resultNodes = new List<XmlNode>(); foreach (ResultHolder.RowResult rowResult in dataHolder.singleRows) { string partPassed = ResultType.PASS; XmlElement resultNode = doc.CreateElement("result"); resultNode.SetAttribute("status", ResultType.PASS); if (!dataHolder.skipTime) { resultNode.SetAttribute("time", GetTimeString(rowResult.partTime)); } XmlElement rowInputNode = doc.CreateElement("input"); resultNode.AppendChild(rowInputNode); foreach (string inputKey in dataHolder.inputKeys) { string input = GetInputData(inputKey, rowResult.inputDic); rowInputNode.SetAttribute(inputKey, input); } if (rowResult.fixException != null) { resultNode.SetAttribute("status", ResultType.ERROR); resultNode.AppendChild(errorParser.AddXmlError(doc, rowResult.fixException)); result.Error(); XmlElement rowOutputNode = doc.CreateElement("output"); resultNode.AppendChild(rowOutputNode); foreach (string outputKey in dataHolder.outputKeys) { XmlElement matchOutputNode = doc.CreateElement(outputKey); rowOutputNode.AppendChild(matchOutputNode); string outExpected = ""; if (rowResult.outputDic != null) { rowResult.outputDic.TryGetValue(outputKey, out outExpected); } matchOutputNode.SetAttribute("expected", outExpected); matchOutputNode.SetAttribute("actual", ""); matchOutputNode.SetAttribute("status", ResultType.UNPROCESSED); } } else { XmlElement rowOutputNode = doc.CreateElement("output"); resultNode.AppendChild(rowOutputNode); partPassed = BuildMatchingData(rowOutputNode, rowResult.outputDic, rowResult.resultDic, dataHolder.outputKeys, dataHolder.toleranceDic); if (partPassed != ResultType.PASS) { resultNode.SetAttribute("status", ResultType.FAIL); result.Fail(); } } resultNodes.Add(resultNode); } return resultNodes; }
public XmlElement BuildMultiRowNode(ResultHolder dataHolder, Result result) { XmlElement resultNode = doc.CreateElement("result"); ResultHolder.RowResult rowResult = dataHolder.singleRows[0]; if (rowResult != null) { if (!dataHolder.skipTime) { resultNode.SetAttribute("time", GetTimeString(rowResult.partTime)); } XmlElement rowInputNode = doc.CreateElement("input"); resultNode.AppendChild(rowInputNode); foreach (string inputKey in dataHolder.inputKeys) { string input = GetInputData(inputKey, rowResult.inputDic); rowInputNode.SetAttribute(inputKey, input); } if (rowResult.fixException != null) { resultNode.SetAttribute("status", ResultType.UNPROCESSED); resultNode.AppendChild(errorParser.AddXmlError(doc, rowResult.fixException)); result.Error(); foreach (Dictionary<string, string> outputDic in dataHolder.multiRows.multiOutput) { XmlElement resultOutputNode = doc.CreateElement("output"); resultOutputNode.SetAttribute("status", ResultType.UNPROCESSED); resultNode.AppendChild(resultOutputNode); foreach (string outputKey in dataHolder.multiRowKeys) { XmlElement matchOutputNode = doc.CreateElement(outputKey); resultOutputNode.AppendChild(matchOutputNode); string outExpected = ""; outputDic.TryGetValue(outputKey, out outExpected); matchOutputNode.SetAttribute("expected", outExpected); matchOutputNode.SetAttribute("actual", ""); matchOutputNode.SetAttribute("status", ResultType.UNPROCESSED); } } } } if (dataHolder.multiRows.multiResult != null) { List<Dictionary<string, object>> matchedResults = MatchOutputToResult(dataHolder); int matchIndex = 0; foreach (Dictionary<string, string> outputDic in dataHolder.multiRows.multiOutput) { Dictionary<string, object> resultDic = matchedResults[matchIndex]; XmlElement resultOutputNode = doc.CreateElement("output"); string partPassed = BuildMatchingData(resultOutputNode, outputDic, resultDic, dataHolder.multiRowKeys, dataHolder.toleranceDic); if (partPassed != ResultType.PASS) { result.Fail(); } resultOutputNode.SetAttribute("status", partPassed); resultNode.AppendChild(resultOutputNode); matchIndex++; } if (matchIndex < matchedResults.Count) { if (!dataHolder.allowSurplus) { result.Fail(); } while (matchIndex < matchedResults.Count) { Dictionary<string, object> surplusDic = matchedResults[matchIndex]; XmlElement surplusNode = doc.CreateElement("output"); surplusNode.SetAttribute("status", ResultType.SURPLUS); foreach (string outputKey in dataHolder.multiRowKeys) { object value = null; if (surplusDic.ContainsKey(outputKey)) { surplusDic.TryGetValue(outputKey, out value); } XmlElement outputNode = doc.CreateElement(outputKey); outputNode.SetAttribute("expected", ""); outputNode.SetAttribute("actual", GetObjStr(value)); outputNode.SetAttribute("status", ResultType.SURPLUS); surplusNode.AppendChild(outputNode); } resultNode.AppendChild(surplusNode); matchIndex++; } } } resultNode.SetAttribute("status", result.type); return resultNode; }