Esempio n. 1
0
        public Property Decimal_String_Should_Be_Parsed_As_Decimal(decimal x)
        {
            var csvRow = new CsvRow
            {
                RowNumber = 1,
                Fields    = new List <FieldValue> {
                    new FieldValue("ProductPrice", x.ToString(CultureInfo.InvariantCulture))
                }
            };

            return((CsvRowToObject <Sale> .Convert(csvRow).ProductPrice == x).ToProperty());
        }
Esempio n. 2
0
        public void Invalid_Date_Returns_ArgumentException()
        {
            var csvRow = new CsvRow
            {
                RowNumber = 1,
                Fields    = new List <FieldValue> {
                    new FieldValue("DeliveryDate", "0")
                }
            };

            Assert.Throws <ArgumentException>(() => CsvRowToObject <Sale> .Convert(csvRow));
        }
Esempio n. 3
0
        public Property Negative_Integer_Should_Be_Parsed_As_Negative_Integer(NegativeInt x)
        {
            var csvRow = new CsvRow
            {
                RowNumber = 1,
                Fields    = new List <FieldValue> {
                    new FieldValue("Volume", x.ToString())
                }
            };

            return((CsvRowToObject <Sale> .Convert(csvRow).Volume == x.Item).ToProperty());
        }
Esempio n. 4
0
        public void Integer_With_Space_Should_Be_Parsed_As_Integer_With_Space_Removed()
        {
            var csvRow = new CsvRow
            {
                RowNumber = 1,
                Fields    = new List <FieldValue> {
                    new FieldValue("Volume", "780 589")
                }
            };

            var sale = CsvRowToObject <Sale> .Convert(csvRow);

            Assert.Equal(780589, sale.Volume);
        }
Esempio n. 5
0
        public void Empty_String_For_Date_Translates_To_DateTime_Min()
        {
            var csvRow = new CsvRow
            {
                RowNumber = 1,
                Fields    = new List <FieldValue> {
                    new FieldValue("DeliveryDate", "")
                }
            };

            var sale = CsvRowToObject <Sale> .Convert(csvRow);

            Assert.Equal(DateTime.MinValue, sale.DeliveryDate);
        }
Esempio n. 6
0
        public void Invalid_Integer_Returns_Failed_To_Parse_As_Int32()
        {
            var csvRow = new CsvRow
            {
                RowNumber = 1,
                Fields    = new List <FieldValue> {
                    new FieldValue("Volume", "T")
                }
            };

            try
            {
                CsvRowToObject <Sale> .Convert(csvRow);
            }
            catch (Exception ex)
            {
                Assert.Equal("Failed to parse \"T\" as Int32 for field Volume", ex.Message);
            }
        }
Esempio n. 7
0
        public void CsvRow_Fields_Are_Mapped_To_Corresponding_Object_Properties()
        {
            var csvRow = new CsvRow
            {
                RowNumber = 1,
                Fields    =
                    new List <FieldValue>
                {
                    new FieldValue("AccountCode", "AC123456"),
                    new FieldValue("ProductCode", "1050"),
                    new FieldValue("DeliveryDate", "2015-01-01"),
                    new FieldValue("Volume", "100"),
                    new FieldValue("TotalMarketValue", "10000")
                }
            };

            var sale = CsvRowToObject <Sale> .Convert(csvRow);

            Assert.Equal("AC123456", sale.AccountCode);
            Assert.Equal("1050", sale.ProductCode);
            Assert.Equal(new DateTime(2015, 1, 1), sale.DeliveryDate);
            Assert.Equal(100, sale.Volume);
            Assert.Equal(10000, sale.TotalMarketValue);
        }