Ejemplo n.º 1
0
        public void ColumnsTest_SpecificValueConverterIsUsed()
        {
            using (var csv = new DelimitedRecordReader(new StringReader("a,b\n1.0,2.0")))
            {
                Assert.AreEqual(ReadResult.Success, csv.ReadColumnHeaders());
                Assert.AreEqual(ReadResult.Success, csv.Read());

                CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("en-US");

                csv.Columns["a"].ValueConverter = new StringValueConverter {
                    IntegerNumberStyles = NumberStyles.Integer
                };
                csv.Columns["b"].ValueConverter = new StringValueConverter {
                    IntegerNumberStyles = NumberStyles.Float
                };

                Assert.Throws <FormatException>(() => csv.GetValue("a", 0));
                Assert.AreEqual(2.0f, csv.GetValue("b", 0.0f));
            }
        }