Ejemplo n.º 1
0
        public void AutoMap_WithCultureInfoAttributes_ConfiguresParameterMaps()
        {
            var context = new CsvContext(new CsvConfiguration(CultureInfo.InvariantCulture));
            var map     = context.AutoMap <Foo>();

            Assert.Equal(2, map.ParameterMaps.Count);
            Assert.Null(map.ParameterMaps[0].Data.TypeConverterOptions.Formats);
            Assert.Single(map.ParameterMaps[1].Data.TypeConverterOptions.Formats);
            Assert.Equal(FORMAT, map.ParameterMaps[1].Data.TypeConverterOptions.Formats[0]);
        }
Ejemplo n.º 2
0
        public void AutoMapWithDefaultConstructor()
        {
            var      config  = new CsvHelper.Configuration.CsvConfiguration(CultureInfo.InvariantCulture);
            var      context = new CsvContext(config);
            ClassMap map     = context.AutoMap <SimpleReferenceHasNoDefaultConstructor>();

            Assert.AreEqual("Id", map.MemberMaps[0].Data.Names[0]);
            Assert.AreEqual("Name", map.ReferenceMaps[0].Data.Mapping.MemberMaps[0].Data.Names[0]);
            Assert.AreEqual("name", map.ReferenceMaps[0].Data.Mapping.ParameterMaps[0].Data.Names[0]);
        }
Ejemplo n.º 3
0
        public void AutoMap_WithBooleanFalseValuesAttribute_CreatesParameterMaps()
        {
            var context = new CsvContext(new CsvConfiguration(CultureInfo.InvariantCulture));
            var map     = context.AutoMap <Foo>();

            Assert.Equal(2, map.ParameterMaps.Count);
            Assert.Empty(map.ParameterMaps[0].Data.TypeConverterOptions.NullValues);
            Assert.Single(map.ParameterMaps[1].Data.TypeConverterOptions.NullValues);
            Assert.Equal("NULL", map.ParameterMaps[1].Data.TypeConverterOptions.NullValues[0]);
        }
Ejemplo n.º 4
0
        public void AutoMap_WithIgnoreAttributes_ConfiguresParameterMaps()
        {
            var context = new CsvContext(new CsvConfiguration(CultureInfo.InvariantCulture));
            var map     = context.AutoMap <Foo>();

            Assert.AreEqual(2, map.ParameterMaps.Count);
            Assert.AreEqual("id", map.ParameterMaps[0].Data.Names.First());
            Assert.AreEqual("name", map.ParameterMaps[1].Data.Names.First());
            Assert.IsTrue(map.ParameterMaps[1].Data.Ignore);
        }
Ejemplo n.º 5
0
        public void AutoMap_WithEnumIgnoreCaseAttributes_ConfiguresParameterMaps()
        {
            var context = new CsvContext(new CsvConfiguration(CultureInfo.InvariantCulture));
            var map     = context.AutoMap <Foo>();

            Assert.Equal(2, map.ParameterMaps.Count);
            Assert.Equal("id", map.ParameterMaps[0].Data.Names.First());
            Assert.Equal("bar", map.ParameterMaps[1].Data.Names.First());
            Assert.True(map.ParameterMaps[1].Data.TypeConverterOptions.EnumIgnoreCase.GetValueOrDefault());
        }
Ejemplo n.º 6
0
        public void AutoMap_UsesContext()
        {
            var context = new CsvContext(new CsvConfiguration(CultureInfo.InvariantCulture));

            context.TypeConverterOptionsCache.GetOptions <string>().NullValues.Add("Bar");

            var map = context.AutoMap <Foo>();

            Assert.Contains("Bar", map.MemberMaps.Find <Foo>(x => x.Name).Data.TypeConverterOptions.NullValues);
        }
Ejemplo n.º 7
0
        public void AutoMapEnumerableTest()
        {
            var context = new CsvContext(new CsvConfiguration(CultureInfo.InvariantCulture));

            try
            {
                context.AutoMap(typeof(List <string>));
                Assert.Fail();
            }
            catch (ConfigurationException) { }
        }
Ejemplo n.º 8
0
        public void AutoMap_WithDefaultAttributes_ConfiguresParameterMaps()
        {
            var context = new CsvContext(new CsvConfiguration(CultureInfo.InvariantCulture));
            var map     = context.AutoMap <Foo>();

            Assert.AreEqual(2, map.ParameterMaps.Count);
            Assert.IsFalse(map.ParameterMaps[0].Data.IsDefaultSet);
            Assert.IsNull(map.ParameterMaps[0].Data.Default);
            Assert.IsTrue(map.ParameterMaps[1].Data.IsDefaultSet);
            Assert.AreEqual("Bar", map.ParameterMaps[1].Data.Default);
        }
Ejemplo n.º 9
0
        public void AutoMap_WithConstantAttributes_ConfiguresParameterMaps()
        {
            var config  = new CsvConfiguration(CultureInfo.InvariantCulture);
            var context = new CsvContext(config);
            var map     = context.AutoMap <Foo>();

            Assert.Equal(2, map.ParameterMaps.Count);
            Assert.False(map.ParameterMaps[0].Data.IsConstantSet);
            Assert.Null(map.ParameterMaps[0].Data.Constant);
            Assert.True(map.ParameterMaps[1].Data.IsConstantSet);
            Assert.Equal("Bar", map.ParameterMaps[1].Data.Constant);
        }
Ejemplo n.º 10
0
        public void CircularDependencyTest()
        {
            var config  = new CsvHelper.Configuration.CsvConfiguration(CultureInfo.InvariantCulture);
            var context = new CsvContext(config);
            var map     = context.AutoMap <ACircular>();

            Assert.IsNotNull(map);
            Assert.AreEqual(1, map.MemberMaps.Count);
            Assert.AreEqual(1, map.ReferenceMaps.Count);
            Assert.AreEqual(1, map.ReferenceMaps[0].Data.Mapping.MemberMaps.Count);
            Assert.AreEqual(0, map.ReferenceMaps[0].Data.Mapping.ReferenceMaps.Count);
        }
        public void AutoMap_WithBooleanFalseValuesAttribute_CreatesParameterMaps()
        {
            var config  = new CsvConfiguration(CultureInfo.InvariantCulture);
            var context = new CsvContext(config);
            var map     = context.AutoMap <Foo>();

            Assert.AreEqual(2, map.ParameterMaps.Count);
            Assert.AreEqual(0, map.ParameterMaps[0].Data.TypeConverterOptions.BooleanTrueValues.Count);
            Assert.AreEqual(0, map.ParameterMaps[0].Data.TypeConverterOptions.BooleanFalseValues.Count);
            Assert.AreEqual(0, map.ParameterMaps[1].Data.TypeConverterOptions.BooleanTrueValues.Count);
            Assert.AreEqual(1, map.ParameterMaps[1].Data.TypeConverterOptions.BooleanFalseValues.Count);
            Assert.AreEqual("Bar", map.ParameterMaps[1].Data.TypeConverterOptions.BooleanFalseValues[0]);
        }
Ejemplo n.º 12
0
        public void AutoMapWithNestedHeaders()
        {
            var config = new CsvHelper.Configuration.CsvConfiguration(CultureInfo.InvariantCulture)
            {
                ReferenceHeaderPrefix = args => $"{args.MemberName}."
            };
            var context = new CsvContext(config);
            var map     = context.AutoMap <Nested>();

            Assert.AreEqual("Simple1.Id", map.ReferenceMaps[0].Data.Mapping.MemberMaps[0].Data.Names[0]);
            Assert.AreEqual("Simple1.Name", map.ReferenceMaps[0].Data.Mapping.MemberMaps[1].Data.Names[0]);
            Assert.AreEqual("Simple2.Id", map.ReferenceMaps[1].Data.Mapping.MemberMaps[0].Data.Names[0]);
            Assert.AreEqual("Simple2.Name", map.ReferenceMaps[1].Data.Mapping.MemberMaps[1].Data.Names[0]);
        }
Ejemplo n.º 13
0
        public void AutoMapEnumerableTest()
        {
            var context = new CsvContext(new CsvConfiguration(CultureInfo.InvariantCulture));

            Assert.Throws <ConfigurationException>(() => context.AutoMap(typeof(List <string>)));
        }
Ejemplo n.º 14
0
 public void SelfCircularDependencyTest()
 {
     var config  = new CsvHelper.Configuration.CsvConfiguration(CultureInfo.InvariantCulture);
     var context = new CsvContext(config);
     var map     = context.AutoMap <SelfCircularA>();
 }