public void Compare_NoAndFalse_True() { var comparer = new BooleanComparer(); var result = comparer.Compare("No", false); Assert.That(result.AreEqual, Is.True); }
public void Compare_FalseAndValue_False() { var comparer = new BooleanComparer(); var result = comparer.Compare(false, "(value)"); Assert.That(result.AreEqual, Is.True); }
public void Compare_TrueAndTrue_True() { var comparer = new BooleanComparer(); var result = comparer.Compare(true, true); Assert.That(result.AreEqual, Is.True); }
public void Compare_1dot0AndStringTrue_True() { var comparer = new BooleanComparer(); var result = comparer.Compare(1.0, "True"); Assert.That(result.AreEqual, Is.True); }
public void Compare_TrueAndStringFalse_False() { var comparer = new BooleanComparer(); var result = comparer.Compare(true, "False"); Assert.That(result.AreEqual, Is.False); }
public void Compare_1DecimalAndStringTrue_True() { var comparer = new BooleanComparer(); var result = comparer.Compare(new decimal(1), "True"); Assert.That(result.AreEqual, Is.True); }
public void Compare_ZeroIntegerAndFalse_True() { var comparer = new BooleanComparer(); var result = comparer.Compare(0, false); Assert.That(result.AreEqual, Is.True); }
public void Compare_StringAndOtherString_False() { var comparer = new BooleanComparer(); var result = comparer.Compare("string", "other string"); Assert.That(result.AreEqual, Is.False); }
public void Compare_YesAndNull_False() { var comparer = new BooleanComparer(); var result = comparer.Compare("yes", null); Assert.That(result.AreEqual, Is.False); }
public void Compare_2AndStringFalse_False() { var comparer = new BooleanComparer(); var result = comparer.Compare(new decimal(2), "False"); Assert.That(result.AreEqual, Is.False); }
public void Compare_StringTrueLowerCaseAndStringTrueUpperCase_True() { var comparer = new BooleanComparer(); var result = comparer.Compare("true", "TRUE"); Assert.That(result.AreEqual, Is.True); }
private void CompareValues(List <CompareHelper> keyMatchingRows, List <DataRow> nonMatchingValueRows) { if (Settings.KeysDef != ResultSetComparisonSettings.KeysChoice.All) { foreach (var rxHelper in keyMatchingRows) { var ryHelper = yDict[rxHelper.Keys]; //if (ryHelper.ValuesHashed == rxHelper.ValuesHashed) //{ // // quick shortcut. If the hash of the values matches, then there is no further need to test // continue; //} var rx = rxHelper.DataRowObj; var ry = ryHelper.DataRowObj; var isRowOnError = false; for (int i = 0; i < rx.Table.Columns.Count; i++) { if (Settings.GetColumnRole(i) == ColumnRole.Value) { //Any management if (rx[i].ToString() != "(any)" && ry[i].ToString() != "(any)") { //Null management if (rx.IsNull(i) || ry.IsNull(i)) { if ((!rx.IsNull(i) && rx[i].ToString() != "(blank)") || (!ry.IsNull(i) && ry[i].ToString() != "(blank)")) { ry.SetColumnError(i, ry.IsNull(i) ? rx[i].ToString() : "(null)"); if (!isRowOnError) { isRowOnError = true; nonMatchingValueRows.Add(ry); } } } //(value) management else if (rx[i].ToString() == "(value)" || ry[i].ToString() == "(value)") { if (rx.IsNull(i) || ry.IsNull(i)) { ry.SetColumnError(i, rx[i].ToString()); if (!isRowOnError) { isRowOnError = true; nonMatchingValueRows.Add(ry); } } } //Not Null management else { ComparerResult result = null; //Numeric if (Settings.GetColumnType(i) == ColumnType.Numeric) { //Convert to decimal if (Settings.IsRounding(i)) { result = numericComparer.Compare(rx[i], ry[i], Settings.GetRounding(i)); } else { result = numericComparer.Compare(rx[i], ry[i], Settings.GetTolerance(i)); } } //Date and Time else if (Settings.GetColumnType(i) == ColumnType.DateTime) { //Convert to dateTime if (Settings.IsRounding(i)) { result = dateTimeComparer.Compare(rx[i], ry[i], Settings.GetRounding(i)); } else { result = dateTimeComparer.Compare(rx[i], ry[i], Settings.GetTolerance(i)); } } //Boolean else if (Settings.GetColumnType(i) == ColumnType.Boolean) { //Convert to bool result = booleanComparer.Compare(rx[i], ry[i]); } //Text else { result = textComparer.Compare(rx[i], ry[i]); } //If are not equal then we need to set the message in the ColumnError. if (!result.AreEqual) { ry.SetColumnError(i, result.Message); if (!isRowOnError) { isRowOnError = true; nonMatchingValueRows.Add(ry); } } } } } } } } }
public override bool Apply(object x) { var cpr = new BooleanComparer(); return(cpr.Compare(x, Reference).AreEqual); }
public bool Compare(object x, object y) { var cpr = new BooleanComparer(); return(cpr.Compare(x, y).AreEqual); }
public bool Apply(object x) { var cpr = new BooleanComparer(); return(cpr.Compare(x, true).AreEqual); }
protected override bool ApplyWithReference(object reference, object x) { var cpr = new BooleanComparer(); return(cpr.Compare(x, reference).AreEqual); }
protected override bool Apply(object x) { var cpr = new BooleanComparer(); return(cpr.Compare(x, true).AreEqual); }
protected ResultSetCompareResult doCompare(DataTable x, DataTable y) { var chrono = DateTime.Now; var columnsCount = Math.Max(y.Columns.Count, x.Columns.Count); if (Settings == null) { BuildDefaultSettings(columnsCount); } else { Settings.ApplyTo(columnsCount); } Settings.ConsoleDisplay(); WriteSettingsToDataTableProperties(y, Settings); WriteSettingsToDataTableProperties(x, Settings); CheckSettingsAndDataTable(y, Settings); CheckSettingsAndDataTable(x, Settings); CheckSettingsAndFirstRow(y, Settings); CheckSettingsAndFirstRow(x, Settings); var keyComparer = new DataRowKeysComparer(Settings, x.Columns.Count); CalculateHashValues(x, xDict, keyComparer, false); CalculateHashValues(y, yDict, keyComparer, true); chrono = DateTime.Now; List <CompareHelper> missingRows; { var missingRowKeys = xDict.Keys.Except(yDict.Keys); missingRows = new List <CompareHelper>(missingRowKeys.Count()); foreach (Int64 i in missingRowKeys) { missingRows.Add(xDict[i]); } } Trace.WriteLineIf(NBiTraceSwitch.TraceInfo, string.Format("Missing rows: {0} [{1}]", missingRows.Count(), DateTime.Now.Subtract(chrono).ToString(@"d\d\.hh\h\:mm\m\:ss\s\ \+fff\m\s"))); chrono = DateTime.Now; List <CompareHelper> unexpectedRows; { var unexpectedRowKeys = yDict.Keys.Except(xDict.Keys); unexpectedRows = new List <CompareHelper>(unexpectedRowKeys.Count()); foreach (Int64 i in unexpectedRowKeys) { unexpectedRows.Add(yDict[i]); } } Trace.WriteLineIf(NBiTraceSwitch.TraceInfo, string.Format("Unexpected rows: {0} [{1}]", unexpectedRows.Count(), DateTime.Now.Subtract(chrono).ToString(@"d\d\.hh\h\:mm\m\:ss\s\ \+fff\m\s"))); chrono = DateTime.Now; List <CompareHelper> keyMatchingRows; { var keyMatchingRowKeys = xDict.Keys.Intersect(yDict.Keys); keyMatchingRows = new List <CompareHelper>(keyMatchingRowKeys.Count()); foreach (Int64 i in keyMatchingRowKeys) { keyMatchingRows.Add(xDict[i]); } } Trace.WriteLineIf(NBiTraceSwitch.TraceInfo, string.Format("Rows with a matching key and not duplicated: {0} [{1}]", keyMatchingRows.Count(), DateTime.Now.Subtract(chrono).ToString(@"d\d\.hh\h\:mm\m\:ss\s\ \+fff\m\s"))); chrono = DateTime.Now; var nonMatchingValueRows = new List <DataRow>(); // If all of the columns make up the key, then we already know which rows match and which don't. // So there is no need to continue testing if (Settings.KeysDef != ResultSetComparisonSettings.KeysChoice.All) { foreach (var rxHelper in keyMatchingRows) { var ryHelper = yDict[rxHelper.KeysHashed]; //if (ryHelper.ValuesHashed == rxHelper.ValuesHashed) //{ // // quick shortcut. If the hash of the values matches, then there is no further need to test // continue; //} var rx = rxHelper.DataRowObj; var ry = ryHelper.DataRowObj; for (int i = 0; i < rx.Table.Columns.Count; i++) { if (Settings.IsValue(i)) { //Null management if (rx.IsNull(i) || ry.IsNull(i)) { if (!rx.IsNull(i) || !ry.IsNull(i)) { ry.SetColumnError(i, ry.IsNull(i) ? rx[i].ToString() : "(null)"); if (!nonMatchingValueRows.Contains(ry)) { nonMatchingValueRows.Add(ry); } } } //(value) management else if (rx[i].ToString() == "(value)" || ry[i].ToString() == "(value)") { if (rx.IsNull(i) || ry.IsNull(i)) { ry.SetColumnError(i, rx[i].ToString()); if (!nonMatchingValueRows.Contains(ry)) { nonMatchingValueRows.Add(ry); } } } //Not Null management else { ComparerResult result = null; //Numeric if (Settings.IsNumeric(i)) { //Convert to decimal if (Settings.IsRounding(i)) { result = numericComparer.Compare(rx[i], ry[i], Settings.GetRounding(i)); } else { result = numericComparer.Compare(rx[i], ry[i], Settings.GetTolerance(i)); } } //Date and Time else if (Settings.IsDateTime(i)) { //Convert to dateTime if (Settings.IsRounding(i)) { result = dateTimeComparer.Compare(rx[i], ry[i], Settings.GetRounding(i)); } else { result = dateTimeComparer.Compare(rx[i], ry[i], Settings.GetTolerance(i)); } } //Boolean else if (Settings.IsBoolean(i)) { //Convert to bool result = booleanComparer.Compare(rx[i], ry[i]); } //Text else { result = textComparer.Compare(rx[i], ry[i]); } //If are not equal then we need to set the message in the ColumnError. if (!result.AreEqual) { ry.SetColumnError(i, result.Message); if (!nonMatchingValueRows.Contains(ry)) { nonMatchingValueRows.Add(ry); } } } } } } } Trace.WriteLineIf(NBiTraceSwitch.TraceInfo, string.Format("Rows with a matching key but without matching value: {0} [{1}]", nonMatchingValueRows.Count(), DateTime.Now.Subtract(chrono).ToString(@"d\d\.hh\h\:mm\m\:ss\s\ \+fff\m\s"))); var duplicatedRows = new List <DataRow>(); // Dummy place holder return(ResultSetCompareResult.Build( missingRows.Select(a => a.DataRowObj).ToList(), unexpectedRows.Select(a => a.DataRowObj).ToList(), duplicatedRows, keyMatchingRows.Select(a => a.DataRowObj).ToList(), nonMatchingValueRows )); }
private IEnumerable <DataRow> CompareValues(DataRow rx, DataRow ry) { var nonMatchingValueRows = new List <DataRow>(); var isRowOnError = false; for (int i = 0; i < rx.Table.Columns.Count; i++) { if (Settings.GetColumnRole(i) == ColumnRole.Value) { //Null management if (rx.IsNull(i) || ry.IsNull(i)) { if (!rx.IsNull(i) || !ry.IsNull(i)) { ry.SetColumnError(i, ry.IsNull(i) ? rx[i].ToString() : "(null)"); if (!isRowOnError) { isRowOnError = true; nonMatchingValueRows.Add(ry); } } } //(value) management else if (rx[i].ToString() == "(value)" || ry[i].ToString() == "(value)") { if (rx.IsNull(i) || ry.IsNull(i)) { ry.SetColumnError(i, rx[i].ToString()); if (!isRowOnError) { isRowOnError = true; nonMatchingValueRows.Add(ry); } } } //Not Null management else { ComparerResult result = null; //Numeric if (Settings.GetColumnType(i) == ColumnType.Numeric) { //Convert to decimal if (Settings.IsRounding(i)) { result = numericComparer.Compare(rx[i], ry[i], Settings.GetRounding(i)); } else { result = numericComparer.Compare(rx[i], ry[i], Settings.GetTolerance(i)); } } //Date and Time else if (Settings.GetColumnType(i) == ColumnType.DateTime) { //Convert to dateTime if (Settings.IsRounding(i)) { result = dateTimeComparer.Compare(rx[i], ry[i], Settings.GetRounding(i)); } else { result = dateTimeComparer.Compare(rx[i], ry[i], Settings.GetTolerance(i)); } } //Boolean else if (Settings.GetColumnType(i) == ColumnType.Boolean) { //Convert to bool result = booleanComparer.Compare(rx[i], ry[i]); } //Text else { result = textComparer.Compare(rx[i], ry[i]); } //If are not equal then we need to set the message in the ColumnError. if (!result.AreEqual) { ry.SetColumnError(i, result.Message); if (!isRowOnError) { isRowOnError = true; nonMatchingValueRows.Add(ry); } } } } } return(nonMatchingValueRows); }