public void ChangeMemberMapTest()
        {
            var config = new CsvHelper.Configuration.CsvConfiguration(CultureInfo.InvariantCulture);
            var map    = config.AutoMap <A>();

            map.Map(m => m.B.C.P3).Index(3);
        }
Пример #2
0
        public void AutoMapWithExistingMapTest()
        {
            var config      = new CsvHelper.Configuration.CsvConfiguration(CultureInfo.InvariantCulture);
            var existingMap = new SimpleMap();

            config.Maps.Add(existingMap);
            var data = new
            {
                Simple = new Simple
                {
                    Id   = 1,
                    Name = "one"
                }
            };
            var map = config.AutoMap(data.GetType());

            Assert.IsNotNull(map);
            Assert.AreEqual(0, map.MemberMaps.Count);
            Assert.AreEqual(1, map.ReferenceMaps.Count);

            // Since Simple is a reference on the anonymous object, the type won't
            // be re-used. Types which are created from automapping aren't added
            // to the list of registered maps either.
            Assert.IsNotInstanceOfType(map.ReferenceMaps[0].Data.Mapping, typeof(SimpleMap));
        }
Пример #3
0
        public void AutoMapWithDefaultConstructor()
        {
            var      config = new CsvHelper.Configuration.CsvConfiguration(CultureInfo.InvariantCulture);
            ClassMap map    = config.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.Name);
        }
Пример #4
0
        public void AutoMapEnumerableTest()
        {
            var config = new CsvHelper.Configuration.CsvConfiguration(CultureInfo.InvariantCulture);

            try
            {
                config.AutoMap(typeof(List <string>));
                Assert.Fail();
            }
            catch (ConfigurationException) { }
        }
Пример #5
0
        public void AutoMapWithNestedHeaders()
        {
            var config = new CsvHelper.Configuration.CsvConfiguration(CultureInfo.InvariantCulture)
            {
                ReferenceHeaderPrefix = (type, name) => $"{name}."
            };
            var map = config.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]);
        }