public void EngineShouldCallTypeConverterWhenConverterAttributeIsPresent() { var converter = A.Fake<ITypeConverter>(); A.CallTo(converter).WithReturnType<object>().Returns("foo"); A.CallTo(converter).WithReturnType<bool>().Returns(true); var attribute = A.Fake<IFixedFieldSettings>(); attribute.CallsTo(x => x.Index).Returns(1); attribute.CallsTo(x => x.Length).Returns(1); attribute.CallsTo(x => x.TypeConverter).Returns(converter); var properties = typeof (ConverterTestObject).GetProperties(BindingFlags.Instance | BindingFlags.Public).ToDictionary(info => info.Name); var container = new FieldsContainer<IFixedFieldSettingsContainer>(); container.AddOrUpdate(properties["Foo"], new FixedFieldSettings(properties["Foo"], attribute)); var descriptor = new LayoutDescriptorBase<IFixedFieldSettingsContainer>(container) {HasHeader = false}; var engine = fileEngineFactory.GetEngine(descriptor); using (var stream = new MemoryStream()) using (var writer = new StreamWriter(stream)) { writer.WriteLine("A"); writer.Flush(); stream.Seek(0, SeekOrigin.Begin); // Capture first result to force enumerable to be iterated var result = engine.Read<ConverterTestObject>(stream).FirstOrDefault(); } A.CallTo(converter).WithReturnType<object>().MustHaveHappened(); }
public ILayoutDescriptor <IFixedFieldSettingsContainer> GetDescriptor(Type t) { var container = new FieldsContainer <IFixedFieldSettingsContainer>(); var fileMappingType = t; var fileAttribute = fileMappingType.GetAttribute <FixedLengthFileAttribute>(); if (fileAttribute == null) { throw new NotSupportedException(string.Format("Mapping type {0} should be marked with {1} attribute", fileMappingType.Name, typeof(FixedLengthFileAttribute).Name)); } var properties = fileMappingType.GetTypeDescription <FixedLengthFieldAttribute>(); foreach (var p in properties) { var attribute = p.Attributes.FirstOrDefault() as IFixedFieldSettings; if (attribute != null) { container.AddOrUpdate(p.Property, new FixedFieldSettings(p.Property, attribute)); } } var descriptor = new LayoutDescriptorBase <IFixedFieldSettingsContainer>(container, t) { HasHeader = false }; return(descriptor); }
public void GivenIHaveSpecificationForType(string type, Table table) { var targetType = Assembly .GetExecutingAssembly() .GetTypes() .FirstOrDefault(x => x.FullName.EndsWith(type)); var properties = targetType .GetProperties(BindingFlags.Instance | BindingFlags.Public) .ToDictionary(info => info.Name); var typeMappings = table.CreateSet <FixedLengthTypeMapping>().ToArray(); var container = new FieldsContainer <IFixedFieldSettingsContainer>(); foreach (var typeMapping in typeMappings) { var propertyInfo = properties[typeMapping.Name]; var settings = new FixedFieldSettingsConstructor(propertyInfo); settings.WithLength(typeMapping.Length); if (!string.IsNullOrEmpty(typeMapping.NullValue)) { settings.AllowNull(typeMapping.NullValue); } switch (typeMapping.Padding) { case Padding.Right: settings.WithRightPadding(typeMapping.PaddingCharElement); break; case Padding.Left: settings.WithLeftPadding(typeMapping.PaddingCharElement); break; } container.AddOrUpdate(propertyInfo, settings); } var descriptor = new LayoutDescriptorBase <IFixedFieldSettingsContainer>(container) { HasHeader = false }; ScenarioContext.Current.Add(() => descriptor, descriptor); }
public void GivenIHaveSpecificationForType(string type, Table table) { var targetType = Assembly .GetExecutingAssembly() .GetTypes() .FirstOrDefault(x => x.FullName.EndsWith(type)); var properties = targetType .GetProperties(BindingFlags.Instance | BindingFlags.Public) .ToDictionary(info => info.Name); var typeMappings = table.CreateSet<FixedLengthTypeMapping>().ToArray(); var container = new FieldsContainer<IFixedFieldSettingsContainer>(); foreach (var typeMapping in typeMappings) { var propertyInfo = properties[typeMapping.Name]; var settings = new FixedFieldSettingsConstructor(propertyInfo); settings.WithLength(typeMapping.Length); if (!string.IsNullOrEmpty(typeMapping.NullValue)) { settings.AllowNull(typeMapping.NullValue); } switch (typeMapping.Padding) { case Padding.Right: settings.WithRightPadding(typeMapping.PaddingCharElement); break; case Padding.Left: settings.WithLeftPadding(typeMapping.PaddingCharElement); break; } container.AddOrUpdate(propertyInfo, settings); } var descriptor = new LayoutDescriptorBase<IFixedFieldSettingsContainer>(container) { HasHeader = false }; ScenarioContext.Current.Add(() => descriptor, descriptor); }
public void EngineShouldCallTypeConverterWhenConverterAttributeIsPresent() { var converter = A.Fake <ITypeConverter>(); A.CallTo(converter).WithReturnType <object>().Returns("foo"); A.CallTo(converter).WithReturnType <bool>().Returns(true); var attribute = A.Fake <IFixedFieldSettings>(); attribute.CallsTo(x => x.Index).Returns(1); attribute.CallsTo(x => x.Length).Returns(1); attribute.CallsTo(x => x.TypeConverter).Returns(converter); var properties = typeof(ConverterTestObject).GetProperties(BindingFlags.Instance | BindingFlags.Public).ToDictionary(info => info.Name); var container = new FieldsContainer <IFixedFieldSettingsContainer>(); container.AddOrUpdate(properties["Foo"], new FixedFieldSettings(properties["Foo"], attribute)); var descriptor = new LayoutDescriptorBase <IFixedFieldSettingsContainer>(container) { HasHeader = false }; var engine = fileEngineFactory.GetEngine(descriptor); using (var stream = new MemoryStream()) using (var writer = new StreamWriter(stream)) { writer.WriteLine("A"); writer.Flush(); stream.Seek(0, SeekOrigin.Begin); // Capture first result to force enumerable to be iterated var result = engine.Read <ConverterTestObject>(stream).FirstOrDefault(); } A.CallTo(converter).WithReturnType <object>().MustHaveHappened(); }