protected override bool CheckKeysExist(DataRow dr) { var missingColumns = new List <string>(); foreach (var columnName in settings.GetKeyNames()) { if (!dr.Table.Columns.Contains(columnName)) { return(false); } } return(true); }
protected void CheckSettingsAndDataTable(DataTable dt, SettingsResultSetComparisonByName settings) { var missingColumns = new List <KeyValuePair <string, string> >(); foreach (var columnName in settings.GetKeyNames()) { if (!dt.Columns.Contains(columnName)) { missingColumns.Add(new KeyValuePair <string, string>(columnName, "key")); } } foreach (var columnName in settings.GetValueNames()) { if (!dt.Columns.Contains(columnName)) { missingColumns.Add(new KeyValuePair <string, string>(columnName, "value")); } } if (missingColumns.Count > 0) { var exception = string.Format("You've defined {0} column{1} named '{2}' as key{1} or value{1} but there is no column with {3} name{1} in the resultset. When using comparison by columns' name, you must ensure that all columns defined as keys and values are effectively available in the result-set." , missingColumns.Count > 1 ? "some" : "a" , missingColumns.Count > 1 ? "s" : string.Empty , string.Join("', '", missingColumns.Select(kv => kv.Key)) , missingColumns.Count > 1 ? "these" : "this" ); throw new ResultSetComparerException(exception); } }