public void IgnoreWhenReading_WhenSpecifiedWith_IgnoreWhenWriting_InTwoAttributes_OneMapIsCreatedAndIgnoreWhenReadingIsFalse() { // 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); var listOfHeaders = new List <string>() { "Data1", "Data2", "PercentageMuscle" }; // Act List <ColumnToPropertyMap> maps = classUnderTest.CreateReadMap(listOfHeaders); // Assert ColumnToPropertyMap map = maps.Where(w => w.ColumnName == "PercentageMuscle").SingleOrDefault(); Assert.IsNotNull(map); Assert.IsFalse(map.IgnoreWhenReading); Assert.IsNotNull(map.ReadConverter); }
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 IgnoreWhenReading_WhenSpecifiedWith_IgnoreWhenWriting_InOneAttribute_OneMapIsCreatedAndIgnoreWhenReadingIsTrue() { // Arrange var classUnderTest = new ColumnToPropertyMapper <ColumnToPropertyMapperTestsData1>( new CsvConverterConfiguration(), new DefaultTypeConverterFactory(), -1); var listOfHeaders = new List <string>() { "Data1", "Data2", "Length" }; // Act List <ColumnToPropertyMap> maps = classUnderTest.CreateReadMap(listOfHeaders); // Assert ColumnToPropertyMap map = maps.Where(w => w.ColumnName == "Length").SingleOrDefault(); Assert.IsNotNull(map); Assert.IsTrue(map.IgnoreWhenReading); Assert.IsNull(map.ReadConverter); }