Exemplo n.º 1
0
 public void TestParse_ValueBlank_NullReturned()
 {
     Int32Column column = new Int32Column("count");
     Int32? actual = (Int32?)column.Parse("    ");
     Int32? expected = null;
     Assert.AreEqual(expected, actual, "The value was not parsed as expected.");
 }
Exemplo n.º 2
0
 public Int32PropertyMapping(Int32Column column, IMemberAccessor member, int physicalIndex, int logicalIndex)
 {
     this.column   = column;
     Member        = member;
     PhysicalIndex = physicalIndex;
     LogicalIndex  = logicalIndex;
 }
Exemplo n.º 3
0
 public Int32PropertyMapping(Int32Column column, IMemberAccessor member, int fileIndex, int workIndex)
 {
     this.column    = column;
     this.member    = member;
     this.FileIndex = fileIndex;
     this.WorkIndex = workIndex;
 }
Exemplo n.º 4
0
        public void TestParse_ValueBlank_NullReturned()
        {
            Int32Column column   = new Int32Column("count");
            Int32?      actual   = (Int32?)column.Parse("    ");
            Int32?      expected = null;

            Assert.Equal(expected, actual);
        }
Exemplo n.º 5
0
 public void TestParse_FormatProviderProvided_UsesProvider()
 {
     Int32Column column = new Int32Column("count");
     column.FormatProvider = CultureInfo.CurrentCulture;
     int actual = (int)column.Parse("  -123 ");
     int expected = -123;
     Assert.AreEqual(expected, actual, "The value was not parsed correctly.");
 }
Exemplo n.º 6
0
        public void TestParse_ValueBlank_NullReturned()
        {
            Int32Column column   = new Int32Column("count");
            Int32?      actual   = (Int32?)column.Parse("    ");
            Int32?      expected = null;

            Assert.AreEqual(expected, actual, "The value was not parsed as expected.");
        }
Exemplo n.º 7
0
        public void TestParse_NotNullable_NullValue_Throws()
        {
            Int32Column column = new Int32Column("count")
            {
                IsNullable   = false,
                DefaultValue = DefaultValue.Disabled()
            };

            Assert.ThrowsException <InvalidCastException>(() => column.Parse(null, String.Empty));
        }
Exemplo n.º 8
0
        public void TestParse_FormatProviderProvided_UsesProvider()
        {
            Int32Column column = new Int32Column("count");

            column.FormatProvider = CultureInfo.CurrentCulture;
            int actual   = (int)column.Parse("  -123 ");
            int expected = -123;

            Assert.AreEqual(expected, actual, "The value was not parsed correctly.");
        }
Exemplo n.º 9
0
        public void TestParse_FormatProviderNull_UsesCurrentCulture()
        {
            Int32Column column = new Int32Column("count");

            column.FormatProvider = null;
            int actual   = (int)column.Parse("  -123 ");
            int expected = -123;

            Assert.Equal(expected, actual);
        }
Exemplo n.º 10
0
 public void TestColumnDefinitions_GetEnumerable_Explicit()
 {
     Schema schema = new Schema();
     ColumnDefinition id = new Int32Column("id");
     ColumnDefinition name = new StringColumn("name");
     ColumnDefinition created = new DateTimeColumn("created");
     schema.AddColumn(id).AddColumn(name).AddColumn(created);
     IEnumerable collection = schema.ColumnDefinitions;
     IEnumerator enumerator = collection.GetEnumerator();
 }
Exemplo n.º 11
0
        public void TestColumnDefinitions_GetEnumerable_Explicit()
        {
            SeparatedValueSchema schema  = new SeparatedValueSchema();
            ColumnDefinition     id      = new Int32Column("id");
            ColumnDefinition     name    = new StringColumn("name");
            ColumnDefinition     created = new DateTimeColumn("created");

            schema.AddColumn(id).AddColumn(name).AddColumn(created);
            IEnumerable collection = schema.ColumnDefinitions;
            IEnumerator enumerator = collection.GetEnumerator();
        }
Exemplo n.º 12
0
        public void TestParse_FormatProviderProvided_UsesProvider()
        {
            Int32Column column = new Int32Column("count")
            {
                FormatProvider = CultureInfo.CurrentCulture
            };
            int actual   = (int)column.Parse(null, "  -123 ");
            int expected = -123;

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 13
0
        public void TestParse_NotNullable_NullValue_DefaultProvided()
        {
            Int32Column column = new Int32Column("count")
            {
                IsNullable   = false,
                DefaultValue = DefaultValue.Use(0)
            };
            int value = (int)column.Parse(null, String.Empty);

            Assert.AreEqual(0, value, "A default was not provided.");
        }
        public void TestColumnDefinitions_GetEnumerable_Explicit()
        {
            FixedLengthSchema schema  = new FixedLengthSchema();
            ColumnDefinition  id      = new Int32Column("id");
            ColumnDefinition  name    = new StringColumn("name");
            ColumnDefinition  created = new DateTimeColumn("created");

            schema.AddColumn(id, 10).AddColumn(name, 25).AddColumn(created, 10);
            IEnumerable collection = schema.ColumnDefinitions;
            IEnumerator enumerator = collection.GetEnumerator();
        }
Exemplo n.º 15
0
 public void TestColumnDefinitions_FindByIndex()
 {
     Schema schema = new Schema();
     ColumnDefinition id = new Int32Column("id");
     ColumnDefinition name = new StringColumn("name");
     ColumnDefinition created = new DateTimeColumn("created");
     schema.AddColumn(id).AddColumn(name).AddColumn(created);
     ColumnCollection collection = schema.ColumnDefinitions;
     Assert.AreSame(id, collection[0], "The first column definition was wrong.");
     Assert.AreSame(name, collection[1], "The second column definition was wrong.");
     Assert.AreSame(created, collection[2], "The third column definition was wrong.");
 }
 public void TestColumnDefinitions_GetEnumerable_Explicit()
 {
     FixedLengthSchema schema = new FixedLengthSchema();
     ColumnDefinition id = new Int32Column("id");
     ColumnDefinition name = new StringColumn("name");
     ColumnDefinition created = new DateTimeColumn("created");
     schema.AddColumn(id, new Window(10))
         .AddColumn(name, new Window(25))
         .AddColumn(created, new Window(10));
     IEnumerable collection = schema.ColumnDefinitions;
     IEnumerator enumerator = collection.GetEnumerator();
 }
Exemplo n.º 17
0
        public void TestColumnDefinitions_FindByIndex()
        {
            SeparatedValueSchema schema  = new SeparatedValueSchema();
            ColumnDefinition     id      = new Int32Column("id");
            ColumnDefinition     name    = new StringColumn("name");
            ColumnDefinition     created = new DateTimeColumn("created");

            schema.AddColumn(id).AddColumn(name).AddColumn(created);
            ColumnCollection collection = schema.ColumnDefinitions;

            Assert.AreSame(id, collection[0], "The first column definition was wrong.");
            Assert.AreSame(name, collection[1], "The second column definition was wrong.");
            Assert.AreSame(created, collection[2], "The third column definition was wrong.");
        }
Exemplo n.º 18
0
        public void TestColumnDefinitions_FindByIndex()
        {
            SeparatedValueSchema schema  = new SeparatedValueSchema();
            IColumnDefinition    id      = new Int32Column("id");
            IColumnDefinition    name    = new StringColumn("name");
            IColumnDefinition    created = new DateTimeColumn("created");

            schema.AddColumn(id).AddColumn(name).AddColumn(created);
            ColumnCollection collection = schema.ColumnDefinitions;

            Assert.Same(id, collection[0]);
            Assert.Same(name, collection[1]);
            Assert.Same(created, collection[2]);
        }
        public void TestColumnDefinitions_FindByIndex()
        {
            FixedLengthSchema schema  = new FixedLengthSchema();
            IColumnDefinition id      = new Int32Column("id");
            IColumnDefinition name    = new StringColumn("name");
            IColumnDefinition created = new DateTimeColumn("created");

            schema.AddColumn(id, new Window(10))
            .AddColumn(name, new Window(25))
            .AddColumn(created, new Window(10));
            ColumnCollection collection = schema.ColumnDefinitions;

            Assert.AreSame(id, collection[0]);
            Assert.AreSame(name, collection[1]);
            Assert.AreSame(created, collection[2]);
        }
Exemplo n.º 20
0
        public void TestCtor_SetsName_LowerCase_Trimmed()
        {
            Int32Column column = new Int32Column(" Name   ");

            Assert.AreEqual("name", column.ColumnName, "The name was not set as expected.");
        }
Exemplo n.º 21
0
        public void TestCtor_SetsName_Trimmed()
        {
            Int32Column column = new Int32Column(" Name   ");

            Assert.AreEqual("Name", column.ColumnName);
        }
Exemplo n.º 22
0
 public Int32PropertyMapping(Int32Column column, PropertyInfo property)
 {
     this.column   = column;
     this.property = property;
 }
Exemplo n.º 23
0
 public void TestCtor_SetsName_LowerCase_Trimmed()
 {
     Int32Column column = new Int32Column(" Name   ");
     Assert.AreEqual("name", column.ColumnName, "The name was not set as expected.");
 }
        protected static IColumnDefinition CreateColumnDefinition(TextColumnDefinition definition)
        {
            if (definition == null)
            {
                throw new ArgumentNullException(nameof(definition), "Column definition is not provided.");
            }

            string columnName = definition.Caption ?? definition.ColumnName;

            if (string.IsNullOrWhiteSpace(columnName))
            {
                throw new ArgumentNullException(nameof(definition), $"{nameof(definition.ColumnName)} cannot be empty.");
            }

            if (definition.ColumnType == null)
            {
                return(new IgnoredColumn(columnName));
            }

            switch (Type.GetTypeCode(definition.ColumnType))
            {
            case TypeCode.Empty:
            case TypeCode.Object:
            case TypeCode.DBNull:
                throw new ArgumentException($"Invalid column type: {definition.ColumnType.FullName}");

            case TypeCode.Boolean:
                var boolColumn = new BooleanColumn(columnName)
                {
                    IsNullable = definition.IsNullable
                };
                if (definition.TrueString != null)
                {
                    boolColumn.TrueString = definition.TrueString;
                }
                if (definition.FalseString != null)
                {
                    boolColumn.FalseString = definition.FalseString;
                }
                if (definition.DefaultValue != null)
                {
                    boolColumn.DefaultValue = DefaultValue.Use(definition.DefaultValue);
                }
                if (definition.NullValues != null && definition.NullValues.Length > 0)
                {
                    boolColumn.NullFormatter = new NullFormatter(definition.NullValues, definition.NullComparison);
                }
                return(boolColumn);

            case TypeCode.Char:
                var charColumn = new CharColumn(columnName)
                {
                    IsNullable    = definition.IsNullable,
                    AllowTrailing = definition.AllowTrailing
                };
                if (definition.DefaultValue != null)
                {
                    charColumn.DefaultValue = DefaultValue.Use(definition.DefaultValue);
                }
                return(charColumn);

            case TypeCode.SByte:
                var sbyteColumn = new SByteColumn(columnName)
                {
                    IsNullable = definition.IsNullable
                };
                if (definition.NumberStyles.HasValue)
                {
                    sbyteColumn.NumberStyles = definition.NumberStyles.Value;
                }
                if (definition.DefaultValue != null)
                {
                    sbyteColumn.DefaultValue = DefaultValue.Use(definition.DefaultValue);
                }
                if (!string.IsNullOrWhiteSpace(definition.OutputFormat))
                {
                    sbyteColumn.OutputFormat = definition.OutputFormat;
                }
                if (!string.IsNullOrWhiteSpace(definition.Culture))
                {
                    sbyteColumn.FormatProvider = new CultureInfo(definition.Culture);
                }
                if (definition.NullValues != null && definition.NullValues.Length > 0)
                {
                    sbyteColumn.NullFormatter = new NullFormatter(definition.NullValues, definition.NullComparison);
                }
                return(sbyteColumn);

            case TypeCode.Byte:
                var byteColumn = new ByteColumn(columnName)
                {
                    IsNullable = definition.IsNullable
                };
                if (definition.NumberStyles.HasValue)
                {
                    byteColumn.NumberStyles = definition.NumberStyles.Value;
                }
                if (definition.DefaultValue != null)
                {
                    byteColumn.DefaultValue = DefaultValue.Use(definition.DefaultValue);
                }
                if (!string.IsNullOrWhiteSpace(definition.OutputFormat))
                {
                    byteColumn.OutputFormat = definition.OutputFormat;
                }
                if (!string.IsNullOrWhiteSpace(definition.Culture))
                {
                    byteColumn.FormatProvider = new CultureInfo(definition.Culture);
                }
                if (definition.NullValues != null && definition.NullValues.Length > 0)
                {
                    byteColumn.NullFormatter = new NullFormatter(definition.NullValues, definition.NullComparison);
                }
                return(byteColumn);

            case TypeCode.Int16:
                var shortColumn = new Int16Column(columnName)
                {
                    IsNullable = definition.IsNullable
                };
                if (definition.NumberStyles.HasValue)
                {
                    shortColumn.NumberStyles = definition.NumberStyles.Value;
                }
                if (definition.DefaultValue != null)
                {
                    shortColumn.DefaultValue = DefaultValue.Use(definition.DefaultValue);
                }
                if (!string.IsNullOrWhiteSpace(definition.OutputFormat))
                {
                    shortColumn.OutputFormat = definition.OutputFormat;
                }
                if (!string.IsNullOrWhiteSpace(definition.Culture))
                {
                    shortColumn.FormatProvider = new CultureInfo(definition.Culture);
                }
                if (definition.NullValues != null && definition.NullValues.Length > 0)
                {
                    shortColumn.NullFormatter = new NullFormatter(definition.NullValues, definition.NullComparison);
                }
                return(shortColumn);

            case TypeCode.UInt16:
                var ushortColumn = new UInt16Column(columnName)
                {
                    IsNullable = definition.IsNullable
                };
                if (definition.NumberStyles.HasValue)
                {
                    ushortColumn.NumberStyles = definition.NumberStyles.Value;
                }
                if (definition.DefaultValue != null)
                {
                    ushortColumn.DefaultValue = DefaultValue.Use(definition.DefaultValue);
                }
                if (!string.IsNullOrWhiteSpace(definition.OutputFormat))
                {
                    ushortColumn.OutputFormat = definition.OutputFormat;
                }
                if (!string.IsNullOrWhiteSpace(definition.Culture))
                {
                    ushortColumn.FormatProvider = new CultureInfo(definition.Culture);
                }
                if (definition.NullValues != null && definition.NullValues.Length > 0)
                {
                    ushortColumn.NullFormatter = new NullFormatter(definition.NullValues, definition.NullComparison);
                }
                return(ushortColumn);

            case TypeCode.Int32:
                var intColumn = new Int32Column(columnName)
                {
                    IsNullable = definition.IsNullable
                };
                if (definition.NumberStyles.HasValue)
                {
                    intColumn.NumberStyles = definition.NumberStyles.Value;
                }
                if (definition.DefaultValue != null)
                {
                    intColumn.DefaultValue = DefaultValue.Use(definition.DefaultValue);
                }
                if (!string.IsNullOrWhiteSpace(definition.OutputFormat))
                {
                    intColumn.OutputFormat = definition.OutputFormat;
                }
                if (!string.IsNullOrWhiteSpace(definition.Culture))
                {
                    intColumn.FormatProvider = new CultureInfo(definition.Culture);
                }
                if (definition.NullValues != null && definition.NullValues.Length > 0)
                {
                    intColumn.NullFormatter = new NullFormatter(definition.NullValues, definition.NullComparison);
                }
                return(intColumn);

            case TypeCode.UInt32:
                var uintColumn = new UInt32Column(columnName)
                {
                    IsNullable = definition.IsNullable
                };
                if (definition.NumberStyles.HasValue)
                {
                    uintColumn.NumberStyles = definition.NumberStyles.Value;
                }
                if (definition.DefaultValue != null)
                {
                    uintColumn.DefaultValue = DefaultValue.Use(definition.DefaultValue);
                }
                if (!string.IsNullOrWhiteSpace(definition.OutputFormat))
                {
                    uintColumn.OutputFormat = definition.OutputFormat;
                }
                if (!string.IsNullOrWhiteSpace(definition.Culture))
                {
                    uintColumn.FormatProvider = new CultureInfo(definition.Culture);
                }
                if (definition.NullValues != null && definition.NullValues.Length > 0)
                {
                    uintColumn.NullFormatter = new NullFormatter(definition.NullValues, definition.NullComparison);
                }
                return(uintColumn);

            case TypeCode.Int64:
                var longColumn = new Int64Column(columnName)
                {
                    IsNullable = definition.IsNullable
                };
                if (definition.NumberStyles.HasValue)
                {
                    longColumn.NumberStyles = definition.NumberStyles.Value;
                }
                if (definition.DefaultValue != null)
                {
                    longColumn.DefaultValue = DefaultValue.Use(definition.DefaultValue);
                }
                if (!string.IsNullOrWhiteSpace(definition.OutputFormat))
                {
                    longColumn.OutputFormat = definition.OutputFormat;
                }
                if (!string.IsNullOrWhiteSpace(definition.Culture))
                {
                    longColumn.FormatProvider = new CultureInfo(definition.Culture);
                }
                if (definition.NullValues != null && definition.NullValues.Length > 0)
                {
                    longColumn.NullFormatter = new NullFormatter(definition.NullValues, definition.NullComparison);
                }
                return(longColumn);

            case TypeCode.UInt64:
                var ulongColumn = new UInt64Column(columnName)
                {
                    IsNullable = definition.IsNullable
                };
                if (definition.NumberStyles.HasValue)
                {
                    ulongColumn.NumberStyles = definition.NumberStyles.Value;
                }
                if (definition.DefaultValue != null)
                {
                    ulongColumn.DefaultValue = DefaultValue.Use(definition.DefaultValue);
                }
                if (!string.IsNullOrWhiteSpace(definition.OutputFormat))
                {
                    ulongColumn.OutputFormat = definition.OutputFormat;
                }
                if (!string.IsNullOrWhiteSpace(definition.Culture))
                {
                    ulongColumn.FormatProvider = new CultureInfo(definition.Culture);
                }
                if (definition.NullValues != null && definition.NullValues.Length > 0)
                {
                    ulongColumn.NullFormatter = new NullFormatter(definition.NullValues, definition.NullComparison);
                }
                return(ulongColumn);

            case TypeCode.Single:
                var singleColumn = new SingleColumn(columnName)
                {
                    IsNullable = definition.IsNullable
                };
                if (definition.NumberStyles.HasValue)
                {
                    singleColumn.NumberStyles = definition.NumberStyles.Value;
                }
                if (definition.DefaultValue != null)
                {
                    singleColumn.DefaultValue = DefaultValue.Use(definition.DefaultValue);
                }
                if (!string.IsNullOrWhiteSpace(definition.OutputFormat))
                {
                    singleColumn.OutputFormat = definition.OutputFormat;
                }
                if (!string.IsNullOrWhiteSpace(definition.Culture))
                {
                    singleColumn.FormatProvider = new CultureInfo(definition.Culture);
                }
                if (definition.NullValues != null && definition.NullValues.Length > 0)
                {
                    singleColumn.NullFormatter = new NullFormatter(definition.NullValues, definition.NullComparison);
                }
                return(singleColumn);

            case TypeCode.Double:
                var doubleColumn = new DoubleColumn(columnName)
                {
                    IsNullable = definition.IsNullable
                };
                if (definition.NumberStyles.HasValue)
                {
                    doubleColumn.NumberStyles = definition.NumberStyles.Value;
                }
                if (definition.DefaultValue != null)
                {
                    doubleColumn.DefaultValue = DefaultValue.Use(definition.DefaultValue);
                }
                if (!string.IsNullOrWhiteSpace(definition.OutputFormat))
                {
                    doubleColumn.OutputFormat = definition.OutputFormat;
                }
                if (!string.IsNullOrWhiteSpace(definition.Culture))
                {
                    doubleColumn.FormatProvider = new CultureInfo(definition.Culture);
                }
                if (definition.NullValues != null && definition.NullValues.Length > 0)
                {
                    doubleColumn.NullFormatter = new NullFormatter(definition.NullValues, definition.NullComparison);
                }
                return(doubleColumn);

            case TypeCode.Decimal:
                var decimalColumn = new DecimalColumn(columnName)
                {
                    IsNullable = definition.IsNullable
                };
                if (definition.NumberStyles.HasValue)
                {
                    decimalColumn.NumberStyles = definition.NumberStyles.Value;
                }
                if (definition.DefaultValue != null)
                {
                    decimalColumn.DefaultValue = DefaultValue.Use(definition.DefaultValue);
                }
                if (!string.IsNullOrWhiteSpace(definition.OutputFormat))
                {
                    decimalColumn.OutputFormat = definition.OutputFormat;
                }
                if (!string.IsNullOrWhiteSpace(definition.Culture))
                {
                    decimalColumn.FormatProvider = new CultureInfo(definition.Culture);
                }
                if (definition.NullValues != null && definition.NullValues.Length > 0)
                {
                    decimalColumn.NullFormatter = new NullFormatter(definition.NullValues, definition.NullComparison);
                }
                return(decimalColumn);

            case TypeCode.DateTime:
                var datetimeColumn = new DateTimeColumn(columnName)
                {
                    IsNullable = definition.IsNullable
                };
                if (!string.IsNullOrWhiteSpace(definition.InputFormat))
                {
                    datetimeColumn.InputFormat = definition.InputFormat;
                }
                if (!string.IsNullOrWhiteSpace(definition.OutputFormat))
                {
                    datetimeColumn.OutputFormat = definition.OutputFormat;
                }
                if (definition.DefaultValue != null)
                {
                    datetimeColumn.DefaultValue = DefaultValue.Use(definition.DefaultValue);
                }
                if (!string.IsNullOrWhiteSpace(definition.Culture))
                {
                    datetimeColumn.FormatProvider = new CultureInfo(definition.Culture);
                }
                if (definition.NullValues != null && definition.NullValues.Length > 0)
                {
                    datetimeColumn.NullFormatter = new NullFormatter(definition.NullValues, definition.NullComparison);
                }
                return(datetimeColumn);

            case TypeCode.String:
                var stringColumn = new StringColumn(columnName)
                {
                    IsNullable = definition.IsNullable,
                    Trim       = definition.Trim
                };
                if (definition.DefaultValue != null)
                {
                    stringColumn.DefaultValue = DefaultValue.Use(definition.DefaultValue);
                }
                if (definition.NullValues != null && definition.NullValues.Length > 0)
                {
                    stringColumn.NullFormatter = new NullFormatter(definition.NullValues, definition.NullComparison);
                }
                return(stringColumn);

            default:
                throw new ArgumentException("Invalid column type for text import/export.");
            }
        }
Exemplo n.º 25
0
 public Int32PropertyMapping(Int32Column column, PropertyInfo property)
 {
     this.column = column;
     this.property = property;
 }