public void GetColumnType_EqualToAndColumnsDefinedName_CorrectResult() { var builder = new SettingsEquivalerBuilder(); builder.Setup(new[] { "Zero", "Three", "Six", "Seven", "Eight" }, new[] { "Nine" }); builder.Setup(BuildColumns()); builder.Build(); //Get the Settings var settings = builder.GetSettings(); Assert.That(settings, Is.TypeOf <SettingsNameResultSet>()); var actual = settings as SettingsNameResultSet; //Assertion Assert.That(actual.GetColumnType("Zero"), Is.EqualTo(ColumnType.Text)); Assert.That(actual.GetColumnType("One"), Is.EqualTo(ColumnType.Numeric)); Assert.That(actual.GetColumnType("Two"), Is.EqualTo(ColumnType.Text)); //By Default a column is Text Assert.That(actual.GetColumnType("Three"), Is.EqualTo(ColumnType.Text)); Assert.That(actual.GetColumnType("Four"), Is.EqualTo(ColumnType.Numeric)); Assert.That(actual.GetColumnType("Five"), Is.EqualTo(ColumnType.Text)); Assert.That(actual.GetColumnType("Six"), Is.EqualTo(ColumnType.Text)); Assert.That(actual.GetColumnType("Seven"), Is.EqualTo(ColumnType.Text)); Assert.That(actual.GetColumnType("Eight"), Is.EqualTo(ColumnType.Text)); Assert.That(actual.GetColumnType("Nine"), Is.EqualTo(ColumnType.Numeric)); }
public void GetTolerance_EqualToAndColumnsDefinedName_CorrectResult() { var builder = new SettingsEquivalerBuilder(); builder.Setup(new[] { "Zero", "Three", "Six", "Seven", "Eight" }, new[] { "Nine" }); builder.Setup(BuildColumns()); builder.Setup(ColumnType.Numeric, "100"); builder.Build(); //Get the Settings var settings = builder.GetSettings(); Assert.That(settings, Is.TypeOf <SettingsNameResultSet>()); var actual = settings as SettingsNameResultSet; //Assertion //apply specific value Assert.That(actual.GetTolerance("One"), Is.TypeOf <NumericAbsoluteTolerance>()); Assert.That((actual.GetTolerance("One") as NumericAbsoluteTolerance).Side, Is.EqualTo(SideTolerance.Both)); Assert.That((actual.GetTolerance("One") as NumericAbsoluteTolerance).Value, Is.EqualTo(1)); //apply default value Assert.That(Tolerance.IsNullOrNone(actual.GetTolerance("Two"))); //We haven't a Numeric column Assert.That(actual.GetTolerance("Four"), Is.TypeOf <NumericAbsoluteTolerance>()); Assert.That((actual.GetTolerance("Four") as NumericAbsoluteTolerance).Side, Is.EqualTo(SideTolerance.Both)); Assert.That((actual.GetTolerance("Four") as NumericAbsoluteTolerance).Value, Is.EqualTo(100)); Assert.That(actual.GetTolerance("Nine"), Is.TypeOf <NumericAbsoluteTolerance>()); Assert.That((actual.GetTolerance("Nine") as NumericAbsoluteTolerance).Side, Is.EqualTo(SideTolerance.Both)); Assert.That((actual.GetTolerance("Nine") as NumericAbsoluteTolerance).Value, Is.EqualTo(100)); }
public void GetColumnRole_EqualToAndColumnsDefinedCorrectResult() { var builder = new SettingsEquivalerBuilder(); builder.Setup(SettingsOrdinalResultSet.KeysChoice.AllExpectLast, SettingsOrdinalResultSet.ValuesChoice.Last); builder.Setup(BuildColumns()); builder.Build(); //Get the Settings var settings = builder.GetSettings(); Assert.That(settings, Is.TypeOf <SettingsOrdinalResultSet>()); var actual = settings as SettingsOrdinalResultSet; actual.ApplyTo(10); //Assertion Assert.That(actual.GetColumnRole(0), Is.EqualTo(ColumnRole.Key)); Assert.That(actual.GetColumnRole(1), Is.EqualTo(ColumnRole.Value)); Assert.That(actual.GetColumnRole(2), Is.EqualTo(ColumnRole.Value)); Assert.That(actual.GetColumnRole(3), Is.EqualTo(ColumnRole.Key)); Assert.That(actual.GetColumnRole(4), Is.EqualTo(ColumnRole.Value)); Assert.That(actual.GetColumnRole(5), Is.EqualTo(ColumnRole.Ignore)); Assert.That(actual.GetColumnRole(6), Is.EqualTo(ColumnRole.Key)); Assert.That(actual.GetColumnRole(7), Is.EqualTo(ColumnRole.Key)); Assert.That(actual.GetColumnRole(8), Is.EqualTo(ColumnRole.Key)); Assert.That(actual.GetColumnRole(9), Is.EqualTo(ColumnRole.Value)); }
public void GetTolerance_EqualToAndColumnsDefinedCorrectResult() { var builder = new SettingsEquivalerBuilder(); builder.Setup(SettingsOrdinalResultSet.KeysChoice.AllExpectLast, SettingsOrdinalResultSet.ValuesChoice.Last); builder.Setup(BuildColumns()); builder.Setup(ColumnType.Numeric, "100"); builder.Build(); //Get the Settings var settings = builder.GetSettings(); Assert.That(settings, Is.TypeOf <SettingsOrdinalResultSet>()); var actual = settings as SettingsOrdinalResultSet; actual.ApplyTo(10); //apply specific value Assert.That(actual.GetTolerance(1), Is.TypeOf <NumericAbsoluteTolerance>()); Assert.That((actual.GetTolerance(1) as NumericAbsoluteTolerance).Side, Is.EqualTo(SideTolerance.Both)); Assert.That((actual.GetTolerance(1) as NumericAbsoluteTolerance).Value, Is.EqualTo(1)); //apply default value Assert.That(Tolerance.IsNullOrNone(actual.GetTolerance(2))); //We haven't a Numeric column Assert.That(actual.GetTolerance(4), Is.TypeOf <NumericAbsoluteTolerance>()); Assert.That((actual.GetTolerance(4) as NumericAbsoluteTolerance).Side, Is.EqualTo(SideTolerance.Both)); Assert.That((actual.GetTolerance(4) as NumericAbsoluteTolerance).Value, Is.EqualTo(100)); Assert.That(actual.GetTolerance(9), Is.TypeOf <NumericAbsoluteTolerance>()); Assert.That((actual.GetTolerance(9) as NumericAbsoluteTolerance).Side, Is.EqualTo(SideTolerance.Both)); Assert.That((actual.GetTolerance(9) as NumericAbsoluteTolerance).Value, Is.EqualTo(100)); }
public void GetColumnType_EqualToAndColumnsDefinedCorrectResult() { var builder = new SettingsEquivalerBuilder(); builder.Setup(SettingsIndexResultSet.KeysChoice.AllExpectLast, SettingsIndexResultSet.ValuesChoice.Last); builder.Setup(BuildColumns()); builder.Build(); //Get the Settings var settings = builder.GetSettings(); Assert.That(settings, Is.TypeOf <SettingsIndexResultSet>()); var actual = settings as SettingsIndexResultSet; actual.ApplyTo(10); //Assertion Assert.That(actual.GetColumnType(0), Is.EqualTo(ColumnType.Text)); Assert.That(actual.GetColumnType(1), Is.EqualTo(ColumnType.Numeric)); Assert.That(actual.GetColumnType(2), Is.EqualTo(ColumnType.Text)); //By Default a key column is Text Assert.That(actual.GetColumnType(3), Is.EqualTo(ColumnType.Text)); Assert.That(actual.GetColumnType(4), Is.EqualTo(ColumnType.Numeric)); Assert.That(actual.GetColumnType(5), Is.EqualTo(ColumnType.Text)); Assert.That(actual.GetColumnType(6), Is.EqualTo(ColumnType.Text)); Assert.That(actual.GetColumnType(7), Is.EqualTo(ColumnType.Text)); Assert.That(actual.GetColumnType(8), Is.EqualTo(ColumnType.Text)); Assert.That(actual.GetColumnType(9), Is.EqualTo(ColumnType.Numeric)); }
private IGroupBy Instantiate(IEnumerable <IColumnDefinitionLight> columns, Context context) { if ((columns?.Count() ?? 0) == 0) { return(new NoneGrouping()); } var definitions = new List <ColumnDefinition>(); foreach (var column in columns) { var definition = new ColumnDefinition() { Identifier = column.Identifier, Type = column.Type }; definitions.Add(definition); } var builder = new SettingsEquivalerBuilder(); builder.Setup(KeysChoice.None, ValuesChoice.None); builder.Setup(definitions); builder.Build(); var settings = builder.GetSettings(); if (settings is SettingsOrdinalResultSet) { return(new OrdinalColumnGrouping(settings as SettingsOrdinalResultSet, context)); } else if (settings is SettingsNameResultSet) { return(new NameColumnGrouping(settings as SettingsNameResultSet, context)); } throw new ArgumentOutOfRangeException(nameof(settings)); }
protected NBiConstraint InstantiateConstraint() { BaseResultSetComparisonConstraint ctr = null; //Manage transformations var transformationProvider = new TransformationProvider(); foreach (var columnDef in ConstraintXml.ColumnsDef) { if (columnDef.Transformation != null) { transformationProvider.Add(columnDef.Index, columnDef.Transformation); } } if (ConstraintXml.GetCommand() != null) { ctr = InstantiateConstraint(((QueryXml)(ConstraintXml.BaseItem)), ConstraintXml.Settings, transformationProvider); } else if (ConstraintXml.ResultSet != null) { ctr = InstantiateConstraint(ConstraintXml.ResultSet, ConstraintXml.Settings, transformationProvider); } else if (ConstraintXml.XmlSource != null) { ctr = InstantiateConstraint(ConstraintXml.XmlSource, ConstraintXml.Settings, transformationProvider); } if (ctr == null) { throw new ArgumentException(); } //Manage settings for comparaison var builder = new SettingsEquivalerBuilder(); if (ConstraintXml.Behavior == EqualToXml.ComparisonBehavior.SingleRow) { builder.Setup(false); builder.Setup(ConstraintXml.ValuesDefaultType, ConstraintXml.Tolerance); builder.Setup(ConstraintXml.ColumnsDef); } else { builder.Setup(ConstraintXml.KeysDef, ConstraintXml.ValuesDef); builder.Setup( ConstraintXml.KeyName?.Replace(" ", "").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Distinct(), ConstraintXml.ValueName?.Replace(" ", "").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Distinct()); builder.Setup(ConstraintXml.ValuesDefaultType, ConstraintXml.Tolerance); builder.Setup(ConstraintXml.ColumnsDef); } builder.Build(); var settings = builder.GetSettings(); var factory = new EquivalerFactory(); var comparer = factory.Instantiate(settings, EquivalenceKind); ctr = ctr.Using(comparer); ctr = ctr.Using(settings); //Manage parallelism if (ConstraintXml.ParallelizeQueries) { ctr = ctr.Parallel(); } else { ctr = ctr.Sequential(); } return(ctr); }