Exemplo n.º 1
0
        public void Write_RealFile_Success()
        {
            // Arrange
            if (File.Exists(fileName))
                File.Delete(fileName);

            try
            {
                // Act
                using (var writer = new CsvWriter(fileName, DELIMETER_AS_SPACE))
                {
                    string[] values1 = { "qw", "er" };
                    writer.Write(values1);
                    string[] values2 = { "ty", "ui" };
                    writer.Write(values2);
                    writer.Close();
                }

                // Assert
                var fileLines = File.ReadAllLines(fileName);
                Assert.AreEqual(2, fileLines.Count(), "Invalid file exported");
                Assert.AreEqual("qw er", fileLines[0]);
                Assert.AreEqual("ty ui", fileLines[1]);
            }
            finally
            {
                if (File.Exists(fileName))
                    File.Delete(fileName);
            }
        }
Exemplo n.º 2
0
        public void Write_TwoStringsWithSemicolonDelimeter_Success()
        {
            // Arrange
            using (var stream = new MemoryStream())
            {
                using (var streamWriter = new StreamWriter(stream))

                // Act
                using (var writerUnderTest = new CsvWriter(streamWriter, DELIMETER_AS_SEMICOLON))
                {
                    string[] values1 = { "qw", "er" };
                    writerUnderTest.Write(values1);
                    string[] values2 = { "ty", "ui" };
                    writerUnderTest.Write(values2);
                    writerUnderTest.Close();
                }

                // Assert
                var expectedLines = string.Format("qw;er{0}ty;ui{0}", Environment.NewLine);
                var actualLines = Encoding.UTF8.GetString(stream.ToArray());
                Assert.AreEqual(expectedLines, actualLines);
            }
        }
Exemplo n.º 3
0
        public void Write_WriterDisposed_ThrowException()
        {
            // Arrange
            using (var stream = new MemoryStream())
            {
                using (var streamWriter = new StreamWriter(stream))
                {
                    // Act
                    var writerUnderTest = new CsvWriter(streamWriter);

                    string[] values1 = { "qw" };
                    writerUnderTest.Write(values1);
                    writerUnderTest.Close();

                    string[] values2 = { "ty" };
                    writerUnderTest.Write(values2);
                }
            }
        }