private bool ValidateParameters(ITestListener listener, DataRow dataRow) { if(_expectedParameterNum == dataRow.Values.Length) { var parameters = MethodInfo.GetParameters(); var paramValues = new object[parameters.Length]; for(var i = 0; i < parameters.Length; i++) { try { paramValues[i] = Convert.ChangeType(dataRow.Values[i], parameters[i].ParameterType); } catch(InvalidCastException) { ReportError(listener, string.Format( "Parameter types don't match for DataRow({0}).", dataRow)); return false; } catch(FormatException) { ReportError(listener, string.Format( "Parameter types don't match for DataRow({0}).", dataRow)); return false; } catch(Exception ex) { ReportError(listener, "Failed to convert parameter." + ex.Message); return false; } } dataRow.Values = paramValues; return true; } ReportError(listener, string.Format("Each data row for {0} must have {1} values.", MethodInfo.Name, _expectedParameterNum)); return false; }
public void Add(DataRow dataRow) { _testRows.Add(dataRow); }
public void NullAsConstructorParameter() { var dataRow = new DataRow(null); Assert.Equals(new object[] { }, dataRow.Values); }