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));
        }
Exemple #2
0
        protected virtual void RenderColumns(IEnumerable <ExtendedMetadata> extendedMetadatas, JsonWriter writer)
        {
            writer.WritePropertyName("columns");
            writer.WriteStartArray();
            foreach (var extendedMetadata in extendedMetadatas)
            {
                writer.WriteStartObject();
                writer.WritePropertyName("position");
                writer.WriteValue(extendedMetadata.Ordinal);
                writer.WritePropertyName("name");
                writer.WriteValue(extendedMetadata.Name);

                var cpFormatter = new ColumnPropertiesFormatter();
                writer.WritePropertyName("role");
                writer.WriteValue(cpFormatter.GetRoleText(extendedMetadata.Role));
                writer.WritePropertyName("type");
                writer.WriteValue(cpFormatter.GetTypeText(extendedMetadata.Type));
                if (!Tolerance.IsNullOrNone(extendedMetadata.Tolerance))
                {
                    writer.WritePropertyName("tolerance");
                    writer.WriteValue(cpFormatter.GetToleranceText(extendedMetadata.Tolerance).Trim());
                }
                if (extendedMetadata.Rounding != null)
                {
                    writer.WritePropertyName("rounding");
                    writer.WriteValue(cpFormatter.GetRoundingText(extendedMetadata.Rounding));
                }
                writer.WriteEndObject();
            }
            writer.WriteEndArray(); //columns
        }
Exemple #3
0
        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));
        }
Exemple #4
0
        public void Execute(IEnumerable <DataRow> rows, ISampler <DataRow> sampler, JsonWriter writer)
        {
            rows = rows ?? new List <DataRow>();
            sampler.Build(rows);
            var sampled = sampler.GetResult();

            writer.WriteStartObject();
            writer.WritePropertyName("total-rows");
            writer.WriteValue(rows.Count());
            if (sampler.GetIsSampled())
            {
                writer.WritePropertyName("sampled-rows");
                writer.WriteValue(rows.Count() - sampler.GetExcludedRowCount());
            }

            if (sampled.Count() > 0)
            {
                writer.WritePropertyName("table");
                writer.WriteStartObject();

                writer.WritePropertyName("columns");
                writer.WriteStartArray();
                var formatters = new List <CellFormatter>();

                foreach (DataColumn column in sampled.ElementAt(0).Table.Columns)
                {
                    writer.WriteStartObject();
                    writer.WritePropertyName("position");
                    writer.WriteValue(column.Ordinal);
                    writer.WritePropertyName("name");
                    writer.WriteValue(column.ColumnName);

                    var cpFormatter = new ColumnPropertiesFormatter();
                    writer.WritePropertyName("role");
                    writer.WriteValue(cpFormatter.GetRoleText((ColumnRole)(column.ExtendedProperties["NBi::Role"] ?? ColumnRole.Key)));
                    writer.WritePropertyName("type");
                    writer.WriteValue(cpFormatter.GetTypeText((ColumnType)(column.ExtendedProperties["NBi::Type"] ?? ColumnType.Text)));
                    formatters.Add(new CellFormatterFactory().GetObject((ColumnType)(column.ExtendedProperties["NBi::Type"] ?? ColumnType.Text)));
                    var tolerance = (Tolerance)(column.ExtendedProperties["NBi::Tolerance"]);
                    if (!Tolerance.IsNullOrNone(tolerance))
                    {
                        writer.WritePropertyName("tolerance");
                        writer.WriteValue(cpFormatter.GetToleranceText(tolerance).Trim());
                    }
                    var rounding = (Rounding)(column.ExtendedProperties["NBi::Rounding"]);
                    if (rounding != null)
                    {
                        writer.WritePropertyName("rounding");
                        writer.WriteValue(cpFormatter.GetRoundingText(rounding));
                    }
                    writer.WriteEndObject();
                }
                writer.WriteEndArray(); //columns

                BuildRows(sampled, formatters, writer);

                writer.WriteEndObject(); //table
            }
            writer.WriteEndObject();
        }
Exemple #5
0
        public void Instantiate_NoToleranceDefined_InstantiatedToNullOrNone(ColumnRole columnRole)
        {
            var colDef = Mock.Of <IColumnDefinition>(
                x => x.Identifier == new ColumnOrdinalIdentifier(0) &&
                x.Role == columnRole &&
                x.Tolerance == string.Empty
                );
            var tolerance = new ToleranceFactory().Instantiate(colDef);

            Assert.That(Tolerance.IsNullOrNone(tolerance), Is.True);
        }
Exemple #6
0
        public void Instantiate_NoToleranceDefined_InstantiatedToNullOrNone(ColumnRole columnRole)
        {
            var colDef = new ColumnDefinitionXml()
            {
                Index     = 0,
                Role      = columnRole,
                Tolerance = string.Empty
            };
            var tolerance = ToleranceFactory.Instantiate(colDef);

            Assert.That(Tolerance.IsNullOrNone(tolerance), Is.True);
        }
Exemple #7
0
        protected void PerformToleranceChecks()
        {
            if (Tolerance.IsNullOrNone(defaultTolerance))
            {
                return;
            }

            if (defaultTolerance is NumericTolerance && valuesDefaultType != ColumnType.Numeric)
            {
                throw new InvalidOperationException($"You cannot define a default type for values as '{valuesDefaultType}' and setup a numeric default tolerance.");
            }
            if (defaultTolerance is TextTolerance && valuesDefaultType != ColumnType.Text)
            {
                throw new InvalidOperationException($"You cannot define a default type for values as '{valuesDefaultType}' and setup a text default tolerance.");
            }
            if (defaultTolerance is DateTimeTolerance && valuesDefaultType != ColumnType.DateTime)
            {
                throw new InvalidOperationException($"You cannot define a default type for values as '{valuesDefaultType}' and setup a dateTime default tolerance.");
            }
        }
Exemple #8
0
        public void Instantiate_NoToleranceDefined_InstantiatedToNullOrNone(ColumnType columnType)
        {
            var tolerance = ToleranceFactory.Instantiate(columnType, string.Empty);

            Assert.That(Tolerance.IsNullOrNone(tolerance), Is.True);
        }
Exemple #9
0
        public void Execute(IEnumerable <DataRow> rows, ISampler <DataRow> sampler, IEnumerable <ColumnMetadata> metadata, JsonWriter writer)
        {
            rows = rows ?? new List <DataRow>();
            sampler.Build(rows);
            var sampled = sampler.GetResult();

            writer.WriteStartObject();
            writer.WritePropertyName("total-rows");
            writer.WriteValue(rows.Count());
            if (sampler.GetIsSampled())
            {
                writer.WritePropertyName("sampled-rows");
                writer.WriteValue(rows.Count() - sampler.GetExcludedRowCount());
            }

            if (sampled.Count() > 0)
            {
                writer.WritePropertyName("table");
                writer.WriteStartObject();

                writer.WritePropertyName("columns");
                writer.WriteStartArray();
                var formatters = new List <IPresenter>();

                var columns = sampled.ElementAt(0).Table.Columns;
                for (var i = 0; i < columns.Count; i++)
                {
                    var meta = metadata.ElementAt(i);

                    writer.WriteStartObject();
                    writer.WritePropertyName("position");
                    writer.WriteValue(columns[i].Ordinal);
                    writer.WritePropertyName("name");
                    writer.WriteValue(columns[i].ColumnName);

                    var cpFormatter = new ColumnPropertiesFormatter();
                    writer.WritePropertyName("role");
                    writer.WriteValue(cpFormatter.GetRoleText(meta.Role));
                    writer.WritePropertyName("type");
                    writer.WriteValue(cpFormatter.GetTypeText(meta.Type));
                    if (!Tolerance.IsNullOrNone(meta.Tolerance))
                    {
                        writer.WritePropertyName("tolerance");
                        writer.WriteValue(cpFormatter.GetToleranceText(meta.Tolerance).Trim());
                    }
                    if (meta.Rounding != null)
                    {
                        writer.WritePropertyName("rounding");
                        writer.WriteValue(cpFormatter.GetRoundingText(meta.Rounding));
                    }

                    formatters.Add(new PresenterFactory().Instantiate(metadata.ElementAt(i).Type));
                    writer.WriteEndObject();
                }
                writer.WriteEndArray(); //columns

                BuildRows(sampled, formatters, writer);

                writer.WriteEndObject(); //table
            }
            writer.WriteEndObject();
        }