Exemple #1
0
        /// <summary>Creates the column to property mapper</summary>
        protected override void CreateMappings()
        {
            ColumnMapList.Clear();
            var mapper = new ColumnToPropertyMapper <T>(Configuration, DefaultConverterFactory, ColumnIndexDefaultValue);

            ColumnMapList.AddRange(mapper.CreateWriteMap());
        }
        public void IgnoreWhenWriting_WhenSpecifiedWith_IgnoreWhenReading_InOneAttribute_NoMapIsCreated()
        {
            // Arrange
            var classUnderTest = new ColumnToPropertyMapper <ColumnToPropertyMapperTestsData1>(
                new CsvConverterConfiguration(), new DefaultTypeConverterFactory(), -1);

            // Act
            List <ColumnToPropertyMap> maps = classUnderTest.CreateWriteMap();

            // Assert
            ColumnToPropertyMap map = maps.Where(w => w.ColumnName == "Length").FirstOrDefault();

            Assert.IsNull(map);
        }
        public void IgnoreWhenWriting_WhenSpecifiedWithBothAsFalse_OneMapIsCreatedAndIgnoreWhenWritingIsFalse()
        {
            // It's a stupid thing to do, but it's legal.

            // Arrange
            var classUnderTest = new ColumnToPropertyMapper <ColumnToPropertyMapperTestsData1>(
                new CsvConverterConfiguration(), new DefaultTypeConverterFactory(), -1);

            // Act
            List <ColumnToPropertyMap> maps = classUnderTest.CreateWriteMap();

            // Assert
            ColumnToPropertyMap map = maps.Where(w => w.ColumnName == "HasJumperCables").SingleOrDefault();

            Assert.IsNotNull(map);
            Assert.IsFalse(map.IgnoreWhenWriting);
            Assert.IsNotNull(map.WriteConverter);
        }
        public void IgnoreWhenWriting_WhenSpecifiedWith_IgnoreWhenWriting_InTwoAttributes_OneMapIsCreatedAndIgnoreWhenWritingIsFalse()
        {
            // Why?
            // You got both a READ and WRITE converter here!  You basically told the mapper that you wanted the
            // the CsvConverterNumber converter for reading and writing on this property type.  The purpose behind letting a user
            // specify two converter attributes is so that they could be DIFFERENT for reading and writing.  If your intent
            // is to tell the mapper to ignore it use  [CsvConverterNumber(IgnoreWhenReading = true, IgnoreWhenWriting = true)] instead!

            // Arrange
            var classUnderTest = new ColumnToPropertyMapper <ColumnToPropertyMapperTestsData1>(
                new CsvConverterConfiguration(), new DefaultTypeConverterFactory(), -1);

            // Act
            List <ColumnToPropertyMap> maps = classUnderTest.CreateWriteMap();

            // Assert
            ColumnToPropertyMap map = maps.Where(w => w.ColumnName == "PercentageMuscle").SingleOrDefault();

            Assert.IsNotNull(map);
            Assert.IsFalse(map.IgnoreWhenWriting);
            Assert.IsNotNull(map.WriteConverter);
        }