public void TestDataRowValues(DataRowValues drv, int number1, int number2, int result, int mult=1, params int[] moreNumbers) { Assert.IsTrue(drv.Values.Length >= 3); int moreNumbersSum = moreNumbers.Length > 0 ? moreNumbers.Aggregate((x,y) => x+y) : 0; Assert.AreEqual(result, (number1 + number2) * mult + moreNumbersSum); }
internal RowTestContext(DataRowValues dataRowValues) { Contract.Requires(dataRowValues != null); this.dataRowValues = dataRowValues; this.properties = dataRowValues.Properties != null ? new Dictionary<string, object>(dataRowValues.Properties) : new Dictionary<string, object>(); this.customValues = new Dictionary<string, string>(); }
private static DataRowValues ReadRow(HelperTestGridResults results, XPathNavigator rowNode) { List<object> rowValuesList = new List<object>(); DataRowValues dataRowValues = new DataRowValues(); rowValuesList.Clear(); for (var elementNodes = rowNode.Select("*"); elementNodes.MoveNext(); ) { var elementNode = elementNodes.Current; switch (elementNode.Name) { case "Desc": dataRowValues.Desc = elementNode.Value; break; case "Ignore": dataRowValues.Ignore = elementNode.ValueAsBoolean; break; // Parse Bug also for back compat before we renamed it to Defect case "Bug": case "Defect": dataRowValues.Defect = elementNode.ValueAsInt; break; case "Id": dataRowValues.Id = elementNode.Value; break; case "Properties": dataRowValues.Properties = new Dictionary<string, object>(); for (var propertyNodes = elementNode.Select("*"); propertyNodes.MoveNext(); ) { var propertyNode = propertyNodes.Current; dataRowValues.Properties[propertyNode.Name] = propertyNode.Value; } break; default: // Each value is typed according to the test method formal args // If params are present in the signature, then the type of every optional value is the params element type Type dataType; if (rowValuesList.Count < results.NonParamsArgCount) { dataType = results.FormalArgs[rowValuesList.Count].ParameterType; } else { dataType = results.ParamArgElementType; } object value = elementNode.ValueAs(dataType, null); rowValuesList.Add(value); break; } } dataRowValues.Values = rowValuesList.ToArray(); return dataRowValues; }
protected bool Matches(TestMethodInvokerContext invokerContext, DataRowValues dataRowValues) { if (this.idValues != null && (this.idValues.Contains(dataRowValues.Id) || this.idValues.Contains("*") || this.idValues.Contains(invokerContext.TestMethodInfo.Name + "." + dataRowValues.Id) || this.idValues.Contains(invokerContext.TestMethodInfo.Name + ".*"))) { return true; } return false; }
public override FilterInfo GetFilterInfo(TestMethodInvokerContext invokerContext, DataRowValues dataRowValues) { FilterInfo result = FilterInfo.None; if (this.Matches(invokerContext, dataRowValues)) { result |= FilterInfo.Exclude; if (this.ShowSkipped) { result |= FilterInfo.ShowSkipped; } else { result |= FilterInfo.HideSkipped; } } return result; }
public virtual FilterInfo GetFilterInfo(TestMethodInvokerContext invokerContext, DataRowValues dataRowValues) { return FilterInfo.None; }
/// <summary> /// Enumerate row data. /// Each row this attribute represents is yielded. /// </summary> /// <param name="resourceAssembly">The assembly containing the resource stream to use. Used by derived row classes.</param> /// <param name="results">The helper to access param and formal arg type info. Used by derived row classes.</param> /// <returns>The data row values for this row to drive the test method.</returns> public virtual IEnumerable<DataRowValues> GetRowEnumerator(Assembly resourceAssembly, HelperTestGridResults results) { // The base RowAttribute just returns one row for any values it specifies // plus any metadata about the data row specified (Desc, Ignore, Defect, etc.). // Derived versions may open a data soruce and enumerate those. DataRowValues dataRowValues = new DataRowValues(); dataRowValues.Values = this.RowValues; dataRowValues.Desc = this.Desc; dataRowValues.Ignore = this.Ignore; dataRowValues.Defect = this.Defect; dataRowValues.Id = Convert.ToString(this.Id); dataRowValues.ExpectedException = this.ExpectedException; dataRowValues.Properties = this.RetrieveProperties(this.Properties); yield return dataRowValues; }
public override IEnumerable<DataRowValues> GetRowEnumerator(System.Reflection.Assembly resourceAssembly, HelperTestGridResults results) { for (int i = 0; i < 10; i++) { DataRowValues dataRowValues = new DataRowValues(); dataRowValues.Id = (i + 1).ToString(); dataRowValues.Values = new object[] {i}; yield return dataRowValues; } }