public void RunFixtureCaughtException() { ResultHolder dataHolder = new ResultHolder("Testing exception", null, false); dataHolder.AddSingleRow(null, null, null, new Exception("Exception message")); XmlNode resultNode = parser.GetResultAsXml(dataHolder); System.Console.WriteLine(resultNode.OuterXml); XmlNode htmlNode = HtmlTransformer.ConvertToHtml(resultNode.OwnerDocument, resultNode); string expected = "<table border=\"0\" cellpadding=\"0\" class=\"step_error\"><tr><td><table width=\"100%\">"; expected += "<tr><th align=\"left\" bgcolor=\"#FF5555\" class=\"title\">Testing exception</th></tr></table></td></tr>"; expected += "<tr><td><table border=\"1\" cellpadding=\"3\" cellspacing=\"0\" width=\"100%\">"; expected += "<tr><td class=\"status_error\">Type</td><td class=\"time_value\">Time</td></tr>"; expected += "<tr><td bgcolor=\"#FF0000\" class=\"statusvalue_error\"><a href=\"#Exception1\">Exception1</a></td><td class=\"time_value\">(00:00:00)</td></tr>"; expected += "</table></td></tr></table>"; System.Console.WriteLine(htmlNode.OuterXml); NUnit.Framework.Assert.AreEqual(expected, htmlNode.OuterXml); }
public ResultHolder RunFixtureParam(XmlNode callNode, Object callFixture, string fixtureName) { activeDataHolder = null; string fixtureMethod = ""; try { XmlAttribute name = SeeFlaw.GetAttributeByName(callNode, "name"); XmlAttribute methodAttr = SeeFlaw.GetAttributeByName(callNode, "method"); fixtureMethod = methodAttr.Value; activeDataHolder = new ResultHolder("param", fixtureName, fixtureMethod, name.Value, false); MethodInfo methodInfo = callFixture.GetType().GetMethod(methodAttr.Value); string inputType = CheckMethodInfo(methodInfo); ParameterInfo[] infos = methodInfo.GetParameters(); if (infos.Length > 1) { throw new Exception("To many arguments in method"); } Dictionary<string, string> inputDic = new Dictionary<string, string>(); Dictionary<string, string> outputDic = new Dictionary<string, string>(); Dictionary<string, object> resultDic = new Dictionary<string, object>(); Object[] attributes = new Object[] { }; string paramValue = ""; if (infos.Length == 1) { XmlNode paramFixtureInputNode = HtmlTransformer.GetChildNodeByName(callNode, "input"); InputArguments inputArgs = ReadArgumentsFromNode(paramFixtureInputNode, inputType); inputDic = inputArgs.visibleArgDic; attributes = new Object[] { inputArgs.attribute }; } paramValue = (string)methodInfo.Invoke(callFixture, attributes); outputDic.Add("read_value", ""); resultDic.Add("read_value", paramValue); runDetails.AddParameter(name.Value, paramValue); activeDataHolder.AddSingleRow(inputDic, outputDic, resultDic, null); } catch (Exception ex) { activeDataHolder = new ResultHolder(fixtureName, fixtureMethod, null, true); activeDataHolder.AddSingleRow(null, null, null, ex); } return activeDataHolder; }
public ResultHolder RunFixtureMethodCall(XmlNode callNode, Object callFixture, string fixtureName) { activeDataHolder = null; Dictionary<string, string> toleranceDic = ReadToleranceFromNode(callNode); string fixtureMethod = ""; try { XmlAttribute methodAttr = SeeFlaw.GetAttributeByName(callNode, "method"); fixtureMethod = methodAttr.Value; activeDataHolder = new ResultHolder(fixtureName, fixtureMethod, toleranceDic, false); MethodInfo methodInfo = callFixture.GetType().GetMethod(methodAttr.Value); string inputType = CheckMethodInfo(methodInfo); if (methodInfo.ReturnType == typeof(void)) { bool calledWithInput = false; foreach (XmlNode childNode in callNode) { if (childNode.LocalName == "input") { calledWithInput = true; InputArguments inputArgs = ReadArgumentsFromNode(childNode, inputType); activeDataHolder.CreateSingleRow(inputArgs.visibleArgDic, null); Object[] attributes = PopulateAttributes(methodInfo, inputArgs, null); try { methodInfo.Invoke(callFixture, attributes); activeDataHolder.SetSingleRowResult(null, null); } catch (Exception ex) { activeDataHolder.SetSingleRowResult(null, ex); } } } if (!calledWithInput) { activeDataHolder.CreateSingleRow(null, null); Object[] attributes = new Object[]{}; try { methodInfo.Invoke(callFixture, attributes); activeDataHolder.SetSingleRowResult(null, null); } catch (Exception ex) { activeDataHolder.SetSingleRowResult(null, ex); } } } else if (methodInfo.ReturnType == typeof(Dictionary<string, object>)) { InputArguments inputArgs = null; Dictionary<string, string> outputDic = null; foreach (XmlNode childNode in callNode) { if (childNode.LocalName == "input") { inputArgs = ReadArgumentsFromNode(childNode, inputType); } else if (childNode.LocalName == "output") { outputDic = ReadDicFromNode(childNode, InputType.DIC); activeDataHolder.CreateSingleRow(inputArgs.visibleArgDic, outputDic); Object[] attributes = PopulateAttributes(methodInfo, inputArgs, outputDic.Keys.ToList()); try { Dictionary<string, object> result = (Dictionary<string, object>)methodInfo.Invoke(callFixture, attributes); activeDataHolder.SetSingleRowResult(result, null); } catch (Exception ex) { if (ex.InnerException != null) { System.Console.WriteLine(ex.InnerException.Message); } activeDataHolder.SetSingleRowResult(null, ex); } } } } else if (methodInfo.ReturnType == typeof(List<Dictionary<string, object>>)) { InputArguments inputArgs = ReadArguments(callNode, inputType); List<Dictionary<string, string>> outputList = ReadOutputList(callNode, runDetails); if (outputList.Count == 0) { List<string> outputKeys = ReadOutputKeys(callNode); bool allowSurplus = false; if (SeeFlaw.GetAttributeByName(callNode, "allowsurplus", true) != null) { allowSurplus = true; } activeDataHolder.CreateMultiRows(inputArgs.visibleArgDic, outputKeys, allowSurplus); } else { activeDataHolder.CreateMultiRows(inputArgs.visibleArgDic, outputList); } Object[] attributes = PopulateAttributes(methodInfo, inputArgs, activeDataHolder.multiRowKeys); try { List<Dictionary<string, object>> result = (List<Dictionary<string, object>>)methodInfo.Invoke(callFixture, attributes); activeDataHolder.SetMultiRowsResult(result, null); } catch (Exception ex) { activeDataHolder.SetMultiRowsResult(null, ex); } } else { throw new Exception("fixture method return type not supported"); } } catch (Exception ex) { activeDataHolder = new ResultHolder(fixtureName, fixtureMethod, null, true); activeDataHolder.AddSingleRow(null, null, null, ex); } return activeDataHolder; }
public ResultHolder RunFixtureParam(List<XmlNode> paramNodes) { ResultHolder dataHolder = new ResultHolder("param", true); foreach (XmlNode paramNode in paramNodes) { try { Exception fixEx = null; XmlAttribute name = SeeFlaw.GetAttributeByName(paramNode, "name"); Dictionary<string, string> inputDic = new Dictionary<string, string>(); Dictionary<string, string> outputDic = new Dictionary<string, string>(); Dictionary<string, object> resultDic = new Dictionary<string, object>(); inputDic.Add("name", name.Value); XmlAttribute valAttr = SeeFlaw.GetAttributeByName(paramNode, "value", true); XmlAttribute argAttr = SeeFlaw.GetAttributeByName(paramNode, "argument", true); if (valAttr == null && argAttr == null) { fixEx = new Exception("argument and value attributes missing in param node"); } string paramValue = ""; if (valAttr != null) { paramValue = valAttr.Value; inputDic.Add("value", valAttr.Value); } if (argAttr != null) { string val = runDetails.GetArgument(argAttr.Value); if (val != "") { paramValue = val; inputDic.Add("argument", argAttr.Value); outputDic.Add("read_value", ""); resultDic.Add("read_value", val); } else if (valAttr == null) { throw new Exception("Argument " + argAttr.Value + " in param node is missing in argument list"); } } if (!resultDic.ContainsKey("read_value")) { resultDic.Add("read_value", ""); } runDetails.AddParameter(name.Value, paramValue); dataHolder.AddSingleRow(inputDic, outputDic, resultDic, fixEx); } catch (Exception ex) { dataHolder.AddSingleRow(null, null, null, ex); } } return dataHolder; }
public ResultHolder RunFixtureInit(List<XmlNode> initNodes) { ResultHolder dataHolder = new ResultHolder("init", true); foreach (XmlNode initNode in initNodes) { try { Exception fixEx = null; XmlAttribute fixture = SeeFlaw.GetAttributeByName(initNode, "fixture"); XmlAttribute idNode = SeeFlaw.GetAttributeByName(initNode, "id"); Object fixtureObj = runDetails.InitFixture(fixture.Value, idNode.Value); Dictionary<string, string> initDic = new Dictionary<string, string>(); initDic.Add("fixture", fixture.Value); initDic.Add("id", idNode.Value); dataHolder.AddSingleRow(initDic, null, null, fixEx); } catch (Exception ex) { dataHolder.AddSingleRow(null, null, null, ex); } } return dataHolder; }