public void Ctor_WithProperties() { var fca = new FileColumnAttribute() { Name = "Name", Text = "Text", Order = 1, Width = 2, IsMandatory = true, IsLineNumber = true, TextValueConverterKey = "Key", WriteFormatString = "000" }; Assert.AreEqual("Name", fca.Name); Assert.AreEqual("Text", fca.Text); Assert.AreEqual(1, fca.Order); Assert.AreEqual(2, fca.Width); Assert.AreEqual(ColumnWidthOverflow.Error, fca.WidthOverflow); Assert.IsFalse(fca.HasWidthOverflowBeenSet); Assert.IsTrue(fca.IsMandatory); Assert.IsTrue(fca.IsLineNumber); Assert.AreEqual(StringTrim.End, fca.StringTrim); Assert.IsFalse(fca.HasStringTrimBeenSet); Assert.AreEqual(StringTransform.EmptyToNull, fca.StringTransform); Assert.IsFalse(fca.HasStringTransformBeenSet); Assert.AreEqual("Key", fca.TextValueConverterKey); Assert.AreEqual("000", fca.WriteFormatString); }
/// <summary> /// Initializes a new instance of the <see cref="FileColumnReflector"/> class. /// </summary> /// <param name="index">The <see cref="Index"/>.</param> /// <param name="fc">The <see cref="FileColumn"/>.</param> /// <param name="pi">The <see cref="PropertyInfo"/>.</param> /// <param name="ff">The <see cref="FileFormat"/>.</param> internal FileColumnReflector(int index, FileColumnAttribute fc, PropertyInfo pi, FileFormatBase ff) { Index = index; Order = fc.Order < 0 ? int.MaxValue : fc.Order; Name = string.IsNullOrEmpty(fc.Name) ? pi.Name : fc.Name; FileColumn = fc; PropertyInfo = pi; FileFormat = ff; // Get the property type being mindful of nullables. if (PropertyInfo.PropertyType.GetTypeInfo().IsGenericType&& PropertyInfo.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>)) { PropertyTypeCode = GetTypeCode(PropertyInfo.PropertyType.GetGenericArguments()[0]); PropertyIsNullable = true; } else { PropertyTypeCode = GetTypeCode(PropertyInfo.PropertyType); } _valueConverter = FileFormat.Converters.Get(PropertyInfo.PropertyType, FileColumn.TextValueConverterKey, FileColumn.TextValueConverterType); if (!string.IsNullOrEmpty(FileColumn.TextValueConverterKey) && _valueConverter == null) { throw new InvalidOperationException(string.Format("FileColumnAttribute has TextValueConverterKey of '{0}' is not found within the FileFormat.Converters.", FileColumn.TextValueConverterKey)); } if (FileColumn.IsLineNumber && PropertyTypeCode != TypeCode.Int32 && PropertyTypeCode != TypeCode.Int64) { throw new InvalidOperationException("FileColumnAttribute has IsLineNumber set to true; the underlying property type must be either Int32 or Int64."); } }
public void Prop_StringTransform() { var fca = new FileColumnAttribute(); Assert.AreEqual(StringTransform.EmptyToNull, fca.StringTransform); Assert.IsFalse(fca.HasStringTransformBeenSet); fca.StringTransform = StringTransform.None; Assert.AreEqual(StringTransform.None, fca.StringTransform); Assert.IsTrue(fca.HasStringTransformBeenSet); }
public void Prop_StringTrim() { var fca = new FileColumnAttribute(); Assert.AreEqual(StringTrim.End, fca.StringTrim); Assert.IsFalse(fca.HasStringTrimBeenSet); fca.StringTrim = StringTrim.Both; Assert.AreEqual(StringTrim.Both, fca.StringTrim); Assert.IsTrue(fca.HasStringTrimBeenSet); }
public void Prop_WidthOverflow() { var fca = new FileColumnAttribute(); Assert.AreEqual(ColumnWidthOverflow.Error, fca.WidthOverflow); Assert.IsFalse(fca.HasWidthOverflowBeenSet); fca.WidthOverflow = ColumnWidthOverflow.Truncate; Assert.AreEqual(ColumnWidthOverflow.Truncate, fca.WidthOverflow); Assert.IsTrue(fca.HasWidthOverflowBeenSet); }
public void Ctor_Default() { var fca = new FileColumnAttribute(); Assert.IsNull(fca.Name); Assert.IsNull(fca.Text); Assert.AreEqual(-1, fca.Order); Assert.AreEqual(0, fca.Width); Assert.AreEqual(ColumnWidthOverflow.Error, fca.WidthOverflow); Assert.IsFalse(fca.HasWidthOverflowBeenSet); Assert.IsFalse(fca.IsMandatory); Assert.IsFalse(fca.IsLineNumber); Assert.AreEqual(StringTrim.End, fca.StringTrim); Assert.IsFalse(fca.HasStringTrimBeenSet); Assert.AreEqual(StringTransform.EmptyToNull, fca.StringTransform); Assert.IsFalse(fca.HasStringTransformBeenSet); Assert.IsNull(fca.TextValueConverterKey); Assert.IsNull(fca.WriteFormatString); }