public ObjectReader(Stream stream, Serializer.ReadMethods readMethods, SwapList objectsForSurrogates, IDictionary <Type, Recipe> recipes, Action <object> postDeserializationCallback, bool treatCollectionAsUserObject, VersionToleranceLevel versionToleranceLevel, bool useBuffering, bool disableStamping, ReferencePreservation referencePreservation, bool forceStampVerification) { this.readMethods = readMethods; this.postDeserializationCallback = postDeserializationCallback; this.treatCollectionAsUserObject = treatCollectionAsUserObject; this.referencePreservation = referencePreservation; this.objectsForSurrogates = objectsForSurrogates; this.recipes = recipes; VersionToleranceLevel = versionToleranceLevel; types = new List <TypeDescriptor>(); Methods = new IdentifiedElementsList <MethodDescriptor>(this); Assemblies = new IdentifiedElementsList <AssemblyDescriptor>(this); Modules = new IdentifiedElementsList <ModuleDescriptor>(this); HashCodeBasedWaitingValues = new Dictionary <int, (object Dictionary, object Value)>(); latePostDeserializationHooks = new List <Action>(); reader = new PrimitiveReader(stream, useBuffering); surrogatesWhileReading = new OneToOneMap <int, object>(); readTypeMethod = disableStamping ? (Func <TypeDescriptor>)ReadSimpleTypeDescriptor : ReadFullTypeDescriptor; ForceStampVerification = forceStampVerification; }
public void WithDateFormats_NullableEmptyFormats_ThrowsArgumentException() { OneToOneMap <DateTime?> propertyMap = Map(t => t.NullableDateValue); Assert.Throws <ArgumentException>("formats", () => propertyMap.WithDateFormats(new string[0])); Assert.Throws <ArgumentException>("formats", () => propertyMap.WithDateFormats(new List <string>())); }
public void Ctor_MemberNotFieldOrProperty_ThrowsArgumentException() { MemberInfo eventInfo = typeof(ClassWithEvent).GetEvent(nameof(ClassWithEvent.Event)); var map = new OneToOneMap <int>(new ColumnNameValueReader("Property")); Assert.Throws <ArgumentException>("member", () => new ExcelPropertyMap(eventInfo, map)); }
public ObjectReader(Stream stream, Serializer.ReadMethods readMethods, SwapList objectsForSurrogates = null, Action <object> postDeserializationCallback = null, bool treatCollectionAsUserObject = false, VersionToleranceLevel versionToleranceLevel = 0, bool useBuffering = true, bool disableStamping = false, ReferencePreservation referencePreservation = ReferencePreservation.Preserve, bool forceStampVerification = false) { this.readMethods = readMethods; this.postDeserializationCallback = postDeserializationCallback; this.treatCollectionAsUserObject = treatCollectionAsUserObject; this.referencePreservation = referencePreservation; this.objectsForSurrogates = objectsForSurrogates ?? new SwapList(); VersionToleranceLevel = versionToleranceLevel; types = new List <TypeDescriptor>(); Methods = new IdentifiedElementsList <MethodDescriptor>(this); Assemblies = new IdentifiedElementsList <AssemblyDescriptor>(this); Modules = new IdentifiedElementsList <ModuleDescriptor>(this); latePostDeserializationHooks = new List <Action>(); reader = new PrimitiveReader(stream, useBuffering); surrogatesWhileReading = new OneToOneMap <int, object>(); readTypeMethod = disableStamping ? (Func <TypeDescriptor>)ReadSimpleTypeDescriptor : ReadFullTypeDescriptor; ForceStampVerification = forceStampVerification; }
public void Ctor_PropertyReadOnly_ThrowsArgumentException() { MemberInfo propertyInfo = typeof(ClassWithEvent).GetProperty(nameof(ClassWithEvent.ReadOnlyProperty)); var map = new OneToOneMap <int>(new ColumnNameValueReader("Property")); Assert.Throws <ArgumentException>("member", () => new ExcelPropertyMap(propertyInfo, map)); }
public void WithDateFormats_NullFormats_ThrowsArgumentNullException() { OneToOneMap <DateTime> propertyMap = Map(t => t.DateValue); Assert.Throws <ArgumentNullException>("formats", () => propertyMap.WithDateFormats(null)); Assert.Throws <ArgumentNullException>("formats", () => propertyMap.WithDateFormats((IEnumerable <string>)null)); }
public void WithDateFormats_NullableNullFormats_ThrowsArgumentNullException() { OneToOneMap <DateTime?> mapping = Map(t => t.NullableDateValue); Assert.Throws <ArgumentNullException>("formats", () => mapping.WithDateFormats(null)); Assert.Throws <ArgumentNullException>("formats", () => mapping.WithDateFormats((IEnumerable <string>)null)); }
public void WithColumnNameMatching_ValidColumnName_Success() { OneToOneMap <string> propertyMap = Map(t => t.Value).WithColumnNameMatching(e => e == "ColumnName"); Assert.Same(propertyMap, propertyMap.WithColumnNameMatching(e => e == "ColumnName")); Assert.IsType <ColumnNameMatchingValueReader>(propertyMap.CellReader); }
public void WithConverter_NullConverter_ThrowsArgumentNullException() { OneToOneMap <string> propertyMap = Map(t => t.Value); ConvertUsingSimpleMapperDelegate <string> converter = null; Assert.Throws <ArgumentNullException>("converter", () => propertyMap.WithConverter(converter)); }
public void WithThrowingInvalidFallback_Invoke_Success() { OneToOneMap <string> propertyMap = Map(t => t.Value); Assert.Same(propertyMap, propertyMap.WithThrowingInvalidFallback()); Assert.IsType <ThrowFallback>(propertyMap.Pipeline.InvalidFallback); }
public void WithInvalidFallbackItem_ValidFallbackItem_Success() { IFallbackItem fallback = new FixedValueFallback(10); OneToOneMap <string> propertyMap = Map(t => t.Value); Assert.Same(propertyMap, propertyMap.WithInvalidFallbackItem(fallback)); Assert.Same(fallback, propertyMap.Pipeline.InvalidFallback); }
public void WithCellValueMappers_ValidMappers_ThrowsArgumentNullException() { OneToOneMap <string> propertyMap = Map(t => t.Value); ICellValueMapper mapper1 = Assert.Single(propertyMap.Pipeline.CellValueMappers); ICellValueMapper mapper2 = new BoolMapper();; Assert.Same(propertyMap, propertyMap.WithCellValueMappers(mapper2)); Assert.Equal(new ICellValueMapper[] { mapper1, mapper2 }, propertyMap.Pipeline.CellValueMappers); }
public void WithMapper_ValidMapper_Success() { var reader = new ColumnNameValueReader("ColumnName"); OneToOneMap <string> propertyMap = Map(t => t.Value); Assert.Same(propertyMap, propertyMap.WithReader(reader)); Assert.Same(reader, propertyMap.CellReader); }
public void WithInvalidFallback_Invoke_Success() { OneToOneMap <string> propertyMap = Map(t => t.Value); Assert.Same(propertyMap, propertyMap.WithInvalidFallback("abc")); FixedValueFallback fallback = Assert.IsType <FixedValueFallback>(propertyMap.Pipeline.InvalidFallback); Assert.Equal("abc", fallback.Value); }
public void WithColumnIndex_ValidColumnIndex_Success(int columnIndex) { OneToOneMap <string> propertyMap = Map(t => t.Value); Assert.Same(propertyMap, propertyMap.WithColumnIndex(columnIndex)); ColumnIndexValueReader reader = Assert.IsType <ColumnIndexValueReader>(propertyMap.CellReader); Assert.Equal(columnIndex, reader.ColumnIndex); }
public void MakeOptional_HasMapper_ReturnsExpected() { var innerReader = new ColumnIndexValueReader(1); OneToOneMap <string> propertyMap = Map(t => t.Value).WithReader(innerReader); Assert.False(propertyMap.Optional); Assert.Same(propertyMap, propertyMap.MakeOptional()); Assert.True(propertyMap.Optional); Assert.Same(innerReader, propertyMap.CellReader); }
public void WithColumnName_ValidColumnName_Success() { OneToOneMap <string> propertyMap = Map(t => t.Value); Assert.Same(propertyMap, propertyMap.WithColumnName("ColumnName")); ColumnNameValueReader reader = Assert.IsType <ColumnNameValueReader>(propertyMap.CellReader); Assert.Equal("ColumnName", reader.ColumnName); }
public void WithDateFormats_NullableAutoMappedIEnumerableString_Success(IEnumerable <string> formats) { OneToOneMap <DateTime?> propertyMap = Map(t => t.NullableDateValue); Assert.Same(propertyMap, propertyMap.WithDateFormats(formats)); DateTimeMapper item = propertyMap.Pipeline.CellValueMappers.OfType <DateTimeMapper>().Single(); Assert.Equal(formats, item.Formats); }
public void WithReader_OptionalColumn_Success() { var innerReader = new ColumnNameValueReader("ColumnName"); OneToOneMap <string> propertyMap = Map(t => t.Value).MakeOptional(); Assert.True(propertyMap.Optional); Assert.Same(propertyMap, propertyMap.WithReader(innerReader)); Assert.True(propertyMap.Optional); Assert.Same(innerReader, propertyMap.CellReader); }
public void WithTrim_Invoke_Success() { OneToOneMap <string> propertyMap = Map(t => t.Value); Assert.Same(propertyMap, propertyMap.WithTrim()); ICellValueTransformer transformer = Assert.Single(propertyMap.Pipeline.CellValueTransformers); Assert.IsType <TrimCellValueTransformer>(transformer); }
public void Item_SetNull_ThrowsArgumentNullException() { MemberInfo propertyInfo = typeof(TestClass).GetProperty(nameof(TestClass.Property)); var map = new OneToOneMap <int>(new ColumnNameValueReader("Property")); var propertyMap = new ExcelPropertyMap(propertyInfo, map); ExcelPropertyMapCollection mappings = new TestClassMap().Properties; mappings.Add(propertyMap); Assert.Throws <ArgumentNullException>("item", () => mappings[0] = null); }
public void WithColumnIndex_OptionalColumn_Success() { OneToOneMap <string> propertyMap = Map(t => t.Value).MakeOptional(); Assert.True(propertyMap.Optional); Assert.Same(propertyMap, propertyMap.WithColumnIndex(1)); Assert.True(propertyMap.Optional); ColumnIndexValueReader innerReader = Assert.IsType <ColumnIndexValueReader>(propertyMap.CellReader); Assert.Equal(1, innerReader.ColumnIndex); }
public void WithDateFormats_NullableAutoMappedStringArray_Success(IEnumerable <string> formats) { var formatsArray = formats.ToArray(); OneToOneMap <DateTime?> propertyMap = Map(t => t.NullableDateValue); Assert.Same(propertyMap, propertyMap.WithDateFormats(formatsArray)); DateTimeMapper item = propertyMap.Pipeline.CellValueMappers.OfType <DateTimeMapper>().Single(); Assert.Same(formatsArray, item.Formats); }
protected ProcedureCommand(Bulka.CommandLine.CommandLine commandLine, string[] argumentNames) : base(commandLine) { _argumentIndexes = new OneToOneMap <string, int>(); for (var i = 0; i < argumentNames.Length; i++) { var name = argumentNames[i]; if (_argumentIndexes.ContainsKey(name)) { throw new Exception($"Duplicate argument '{name}'"); } _argumentIndexes.Add(name, i); } }
public CommandLine(IEqualityComparer <string> nameComparer = null) { _commands = new OneToOneMap <string, Command>(nameComparer); _listener = new Interpreter(this); _lexer = new CommandLineLexer(null); _parser = new CommandLineParser(null); _lexer.RemoveErrorListeners(); _parser.RemoveErrorListeners(); _lexer.AddErrorListener(this); _parser.AddErrorListener(this); }
public void Item_SetValidItem_GetReturnsExpected() { MemberInfo propertyInfo = typeof(TestClass).GetProperty(nameof(TestClass.Property)); var map1 = new OneToOneMap <int>(new ColumnNameValueReader("Property")); var propertyMap1 = new ExcelPropertyMap(propertyInfo, map1); var map2 = new OneToOneMap <int>(new ColumnNameValueReader("Property")); var propertyMap2 = new ExcelPropertyMap(propertyInfo, map2); ExcelPropertyMapCollection mappings = new TestClassMap().Properties; mappings.Add(propertyMap1); mappings[0] = propertyMap2; Assert.Same(propertyMap2, mappings[0]); }
public void Ctor_FieldInfoMember_Success() { MemberInfo fieldInfo = typeof(ClassWithEvent).GetField(nameof(ClassWithEvent._field)); var map = new OneToOneMap <int>(new ColumnNameValueReader("Property")); var propertyMap = new ExcelPropertyMap(fieldInfo, map); Assert.Same(fieldInfo, propertyMap.Member); Assert.Same(map, propertyMap.Map); var instance = new ClassWithEvent(); propertyMap.SetValueFactory(instance, 10); Assert.Equal(10, instance._field); }
internal static bool TryCreatePrimitiveMap <T>(MemberInfo member, FallbackStrategy emptyValueStrategy, out OneToOneMap <T> map) { if (!TryGetWellKnownMap(typeof(T), emptyValueStrategy, out ICellValueMapper mapper, out IFallbackItem emptyFallback, out IFallbackItem invalidFallback)) { map = null; return(false); } ISingleCellValueReader defaultReader = GetDefaultSingleCellValueReader(member); map = new OneToOneMap <T>(defaultReader) .WithCellValueMappers(mapper) .WithEmptyFallbackItem(emptyFallback) .WithInvalidFallbackItem(invalidFallback); return(true); }
public void WithMapping_ValidReader_Success() { var dictionaryMapping = new Dictionary <string, DateTime> { { "key", DateTime.MinValue } }; StringComparer comparer = StringComparer.CurrentCultureIgnoreCase; OneToOneMap <DateTime> propertyMap = Map(t => t.DateValue); Assert.Same(propertyMap, propertyMap.WithMapping(dictionaryMapping, comparer)); DictionaryMapper <DateTime> item = propertyMap.Pipeline.CellValueMappers.OfType <DictionaryMapper <DateTime> >().Single(); Assert.NotSame(dictionaryMapping, item.MappingDictionary); Assert.Equal(dictionaryMapping, item.MappingDictionary); Assert.Same(comparer, Assert.IsType <Dictionary <string, DateTime> >(item.MappingDictionary).Comparer); }
public void WithConverter_InvalidConverter_ReturnsExpected() { ConvertUsingSimpleMapperDelegate <string> converter = stringValue => { Assert.Equal("stringValue", stringValue); throw new NotSupportedException(); }; OneToOneMap <string> propertyMap = Map(t => t.Value); Assert.Same(propertyMap, propertyMap.WithConverter(converter)); ConvertUsingMapper item = propertyMap.Pipeline.CellValueMappers.OfType <ConvertUsingMapper>().Single(); object value = 1; PropertyMapperResultType result = item.Converter(new ReadCellValueResult(-1, "stringValue"), ref value); Assert.Equal(PropertyMapperResultType.Invalid, result); Assert.Equal(1, value); }