예제 #1
0
        public void Read_ExistsEmptyString_ReadEmptyString()
        {
            // Arrange
            const string INPUT_STR = "123\n\n456";

            using (var stream = INPUT_STR.ToStream())
            {
                // Act
                using (var reader = new CsvReader(stream, DELIMETER_AS_SPACE))
                {
                    // Assert
                    string[] values = null;
                    values = reader.Read();
                    Assert.IsNotNull(values);
                    Assert.AreEqual(1, values.Count());
                    Assert.AreEqual("123", values[0]);

                    values = reader.Read();
                    Assert.IsNotNull(values);
                    Assert.AreEqual(1, values.Count());
                    Assert.AreEqual(string.Empty, values[0]);

                    values = reader.Read();
                    Assert.IsNotNull(values);
                    Assert.AreEqual(1, values.Count());
                    Assert.AreEqual("456", values[0]);

                    reader.Close();
                }
            }
        }
예제 #2
0
        public void Read_ReaderDisposed_ThrowException()
        {
            // Arrange
            var str = "123 4567\n89 10";

            using (var inputStream = str.ToStream())
            {
                // Act
                var inputReader = new CsvReader(inputStream);

                inputReader.Read();
                inputReader.Close();
                inputReader.Read();
            }
        }
예제 #3
0
        public void Read_TwoStringsWithSemicolonDelimeter_Success()
        {
            // Arrange
            const char DELIMETER_AS_SEMICOLON = ';';
            var str = "123;4567\nabc;grs";

            using (var stream = str.ToStream())
            {
                // Act
                using (var reader = new CsvReader(stream, DELIMETER_AS_SEMICOLON))
                {
                    // Assert
                    string[] values = null;
                    values = reader.Read();
                    Assert.IsNotNull(values);
                    Assert.AreEqual(2, values.Count());
                    Assert.AreEqual("123", values[0]);
                    Assert.AreEqual("4567", values[1]);

                    values = reader.Read();
                    Assert.IsNotNull(values);
                    Assert.AreEqual(2, values.Count());
                    Assert.AreEqual("abc", values[0]);
                    Assert.AreEqual("grs", values[1]);

                    values = reader.Read();
                    Assert.IsNull(values);

                    reader.Close();
                }
            }
        }
예제 #4
0
        public void Read_TwoStringsAndTwoFields_Success()
        {
            // Arrange
            var str = "123 4567\nabc grs";

            using (var stream = str.ToStream())
            {
                // Act
                using (var reader = new CsvReader(stream, ' '))
                {
                    // Assert
                    string[] values = null;
                    values = reader.Read();
                    Assert.IsNotNull(values);
                    Assert.AreEqual(2, values.Count());
                    Assert.AreEqual("123", values[0]);
                    Assert.AreEqual("4567", values[1]);

                    values = reader.Read();
                    Assert.IsNotNull(values);
                    Assert.AreEqual(2, values.Count());
                    Assert.AreEqual("abc", values[0]);
                    Assert.AreEqual("grs", values[1]);

                    values = reader.Read();
                    Assert.IsNull(values);

                    reader.Close();
                }
            }
        }