public void Should_Write_File_On_Same_Directory(string filePath)
        {
            // Arrange

            // Act
            var result = _csvFileWriter.Write(filePath, fileContent);

            // (Using Shouldly) Assert : Assert and Act together
            result.ShouldBe(true);

            // (Using NUnit) Assert : Assert and Act together
            // Assert.AreEqual(true, result);
        }
Ejemplo n.º 2
0
        public void WriteSameAsReaderCritical()
        {
            var writeFile = new CsvFile();

            writeFile.ID           = "Write";
            writeFile.FileName     = mimicReader.ReadSettings.FirstOrDefault(x => x.ID == "Read").FileName;
            writeFile.SqlStatement = "Read";
            writeFile.InOverview   = true;
            writeFile.FileFormat.FieldDelimiter = "|";
            try
            {
                var writer = new CsvFileWriter(writeFile, CancellationToken.None);

                var res = writer.Write();
                Assert.Fail("No Exception");
            }
            catch (ApplicationException)
            {
            }
            catch (System.IO.IOException)
            {
            }
            catch (Exception)
            {
                Assert.Fail("Wrong exception");
            }
        }
Ejemplo n.º 3
0
        public void WriteAllFormats()
        {
            var pd = new MockProcessDisplay();

            var writeFile = new CsvFile
            {
                ID       = "Write",
                FileName = Path.Combine(m_ApplicationDirectory, "BasicCSVOut2.txt")
            };

            FileSystemUtils.FileDelete(writeFile.FileName);
            var setting = Helper.ReaderGetAllFormats(ApplicationSetting.ToolSetting);

            mimicReader.AddSetting(setting);
            writeFile.SqlStatement = setting.ID;

            writeFile.FileFormat.FieldDelimiter = "|";
            var cf = writeFile.ColumnAdd(new Column {
                Name = "DateTime", DataType = DataType.DateTime
            });

            cf.DateFormat     = "yyyyMMdd";
            cf.TimePartFormat = @"hh:mm";
            cf.TimePart       = "Time";
            var writer = new CsvFileWriter(writeFile, CancellationToken.None);

            writer.Progress += pd.SetProcess;
            var res = writer.Write();

            Assert.IsTrue(FileSystemUtils.FileExists(writeFile.FileName));
            Assert.AreEqual(1065, res, "Records");
        }
Ejemplo n.º 4
0
        public Stream Compare(
            Stream source1,
            Stream source2,
            char reportValueDelimiter)
        {
            CsvDocument doc1 = Read(
                csvStream1Reader,
                1,
                source1);

            CsvDocument doc2 = Read(
                csvStream2Reader,
                2,
                source2);

            doc1 = TransformWithErrorHandling(doc1, transformer1, 1);
            doc2 = TransformWithErrorHandling(doc2, transformer2, 2);

            var comparer = BuildComparer(doc1.HeaderCells, doc2.HeaderCells);

            ComparisonResult result;

            try
            {
                result = comparer.Compare(
                    doc1.ContentRows,
                    doc2.ContentRows);
            }
            catch (InputParsingException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new DataComparisonException(e);
            }

            var stringyfyer = new Andy.Csv.Serialization.RowStringifier(
                new Andy.Csv.Serialization.CellValueEncoder());

            try
            {
                string[] lines = ResultStringification.StringyfyyResults(
                    result,
                    doc1.HeaderCells,
                    doc2.HeaderCells,
                    reportValueDelimiter,
                    stringyfyer);

                return(CsvFileWriter.Write(lines));
            }
            catch (Exception e)
            {
                throw new ReportProductionException(e);
            }
        }
Ejemplo n.º 5
0
        public void Object()
        {
            var ms = new MemoryStream();

            CsvFileWriter.Write(ms, new []
            {
                new { Int = 1, Double = 2.01 }
            });
            var str = Encoding.UTF8.GetString(ms.GetBuffer());

            Assert.Equal("Int,Double\r\n1,2.01\r\n", str.Trim('\0'));
        }
Ejemplo n.º 6
0
        public void WriteSameAsReader()
        {
            var writeFile = new CsvFile();

            writeFile.ID           = "Write";
            writeFile.FileName     = mimicReader.ReadSettings.FirstOrDefault(x => x.ID == "Read").FileName;
            writeFile.SqlStatement = "Read";
            writeFile.FileFormat.FieldDelimiter = "|";

            var writer = new CsvFileWriter(writeFile, CancellationToken.None);

            Assert.IsTrue(string.IsNullOrEmpty(writer.ErrorMessage));
            var res = writer.Write();

            Assert.IsFalse(string.IsNullOrEmpty(writer.ErrorMessage));
        }
        public static void ToCsv(this Print print, string path, string columnsSeparator, string decimalSeparator = null, bool?addCsvHeader = null)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            if (columnsSeparator == null)
            {
                throw new ArgumentNullException(nameof(columnsSeparator));
            }

            var raw = print.ToRaw();

            CsvFileWriter.Write(path, raw.Item2, raw.Item3, columnsSeparator, decimalSeparator, addCsvHeader ?? false);
        }
Ejemplo n.º 8
0
        public void SpecialChars()
        {
            var ms = new MemoryStream();

            CsvFileWriter.Write(ms, new List <IList>
            {
                new List <object> {
                    "a,b", "a\"b", "a\r\nb"
                },
                new List <object> {
                    1, 2, 3
                }
            });
            var str = Encoding.UTF8.GetString(ms.GetBuffer());

            Assert.Equal("\"a,b\",\"a\"\"b\",\"a\r\nb\"\r\n1,2,3\r\n", str.Trim('\0'));
        }
Ejemplo n.º 9
0
        public void NullWrite()
        {
            var ms = new MemoryStream();

            CsvFileWriter.Write(ms, new List <IList>
            {
                new List <object?> {
                    "1", null, "3"
                },
                new List <object?> {
                    1, 2, 3
                }
            });
            var str = Encoding.UTF8.GetString(ms.GetBuffer());

            Assert.Equal("1,,3\r\n1,2,3\r\n", str.Trim('\0'));
        }
Ejemplo n.º 10
0
        public void WriteCsvFile()
        {
            var cacheData = new[]
            {
                new ProcessedCacheData(
                    new CacheData("GC7WP8Y", new LatLng(43.550767, 16.51405), -23.896, 905.656),
                    new LatLng(43.558220, 16.509510)
                    )
            };

            var csvWriter = new CsvFileWriter();

            using (var writer = new StringWriter())
            {
                csvWriter.Write(cacheData, writer);
                var csvString = writer.ToString();

                var expected = "GC7WP8Y,43.55822,16.50951" + Environment.NewLine;

                csvString.Should().Be(expected);
            }
        }
Ejemplo n.º 11
0
        public void Write()
        {
            var pd = new MockProcessDisplay();

            var writeFile = new CsvFile
            {
                ID       = "Write",
                FileName = Path.Combine(m_ApplicationDirectory, "BasicCSVOut.txt")
            };

            FileSystemUtils.FileDelete(writeFile.FileName);

            writeFile.SqlStatement = "Read";
            writeFile.FileFormat.FieldDelimiter = "|";

            var writer = new CsvFileWriter(writeFile, CancellationToken.None);

            Assert.IsTrue(string.IsNullOrEmpty(writer.ErrorMessage));
            writer.Progress += pd.SetProcess;
            var res = writer.Write();

            Assert.IsTrue(FileSystemUtils.FileExists(writeFile.FileName));
            Assert.AreEqual(7, res);
        }