Пример #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);
        }
Пример #2
0
        public void BooleanValue_True_CanBeSerializedAsYesNo()
        {
            var expected = $"yes{NewLine}";
            var result   = WriteCsv.ToString(new[]  { new ItemWithBoolean {
                                                          BooleanProperty = true
                                                      } });

            Assert.AreEqual(expected, result);
        }
Пример #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);
        }
Пример #4
0
        private void btnExportCsv_Click(object sender, EventArgs e)
        {
            dlgFileSave.Filter           = "CSV format|*.csv";
            dlgFileSave.Title            = "Export to CSV";
            dlgFileSave.FileName         = "Export";
            dlgFileSave.DefaultExt       = "csv";
            dlgFileSave.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory;
            dlgFileSave.RestoreDirectory = true;
            DialogResult result = dlgFileSave.ShowDialog();

            if (dlgFileSave.FileName != "" && result != DialogResult.Cancel)
            {
                WriteCsv.writeCSV(grdData, dlgFileSave.FileName);
                FileInfo fileInfo = new FileInfo(dlgFileSave.FileName);
            }
        }
Пример #5
0
        public void WriteCsv()
        {
            //var result = WriteCsv<DtoTestClass4>.Write(_loggerFactory, "DtoTestClass");

            //Assert.NotNull(result);
            //var item1 = new DtoTestClass4(1, /*Guid.NewGuid(),*/ 2, "Test", "0.0.0.0", true, "ahh");
            //var item2 = new DtoTestClass4(2, /*Guid.NewGuid(),*/ 2, "Test", "0.0.0.0", true, "ahh");
            var array = "yyy";//new char[] {'i', 'i'};
            var item1 = new DtoTestClass5(array);
            //var item2 = new DtoTestClass5( array);
            var list = new List <DtoTestClass5> {
                item1                                /*, item2*/
            };
            var test = WriteCsv <DtoTestClass5> .Export(_loggerFactory, @"C:\temp\Test.csv", list);

            Assert.True(test);
        }
Пример #6
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);
        }
Пример #7
0
        public void WriteCsv_StringWithQuotesAndDelimiters_GetsQuotedAndEscapesQuotes()
        {
            var result = WriteCsv.ToString(new[] { new { Value = "ab\"c,def" } });

            Assert.AreEqual($"\"ab\"\"c,def\"{NewLine}", result);
        }
Пример #8
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);
        }
Пример #9
0
 public async ValueTask ExportCsvAsync(string fileName, CancellationToken cancellationToken = default)
 {
     //Logger.LogTrace("RepositoryBase ExportCsvAsync: " + GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod()?.Name);
     await WriteCsv <TEntity> .ExportAsync(_loggerFactory, fileName, FindAll()).ConfigureAwait(false);
 }
Пример #10
0
 public void ExportCsv(string fileName)
 {
     //Logger.LogTrace("RepositoryBase ExportCsv: " + GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod()?.Name);
     WriteCsv <TEntity> .Export(_loggerFactory, fileName, FindAll());
 }
Пример #11
0
        public void ExportCsvPrivateSetter()
        {
            var result = WriteCsv <Dto.TestClassPrivateSetter> .Export(_loggerFactory, @"C:\temp\Test.csv", _list);

            Assert.NotNull(result);
        }