Esempio n. 1
0
        public void WriteCsv_Record_WithCultureInfo_ToString()
        {
            var cultureInfo = CultureInfo.CreateSpecificCulture("be");
            var result      = WriteCsv.ToString(recordItems, ';', '"', '\\', true, cultureInfo: cultureInfo);

            Assert.AreEqual(expected, result);
        }
Esempio n. 2
0
        public void BooleanValue_True_CanBeSerializedAsYesNo()
        {
            var expected = $"yes{NewLine}";
            var result   = WriteCsv.ToString(new[]  { new ItemWithBoolean {
                                                          BooleanProperty = true
                                                      } });

            Assert.AreEqual(expected, result);
        }
Esempio n. 3
0
        public void WriteCsv_ReadBack_ReturnsExpectedResult()
        {
            var cultureInfo = CultureInfo.CreateSpecificCulture("be");
            var schema      = new CsvSchemaBuilder(cultureInfo).From <Item>().Schema;
            var result      = WriteCsv.ToString(new[] { new Item {
                                                            Value = 123.5m
                                                        } }, cultureInfo: cultureInfo);

            Assert.AreEqual($"\"123,5\"{NewLine}", result);
            var readback = ReadCsv.FromString(result, schema: schema).AsEnumerable <Item>().Single().Value;

            Assert.AreEqual(123.5m, readback);
        }
Esempio n. 4
0
        public void Fields_Containing_LineBreak_Should_Be_Quoted()
        {
            var result = WriteCsv.ToString(new[] { new { Value = "abc\r\ndef" } });

            Assert.AreEqual($"\"abc\r\ndef\"{NewLine}", result);
        }
Esempio n. 5
0
        public void WriteCsv_StringWithQuotesAndDelimiters_GetsQuotedAndEscapesQuotes()
        {
            var result = WriteCsv.ToString(new[] { new { Value = "ab\"c,def" } });

            Assert.AreEqual($"\"ab\"\"c,def\"{NewLine}", result);
        }
Esempio n. 6
0
        public void Fields_Containing_Quote_Should_Be_Quoted_And_Quotes_In_Field_Should_Be_Escaped()
        {
            var result = WriteCsv.ToString(new[] { new { Value = "abc\"def" } });

            Assert.AreEqual($"\"abc\"\"def\"{NewLine}", result);
        }