Example #1
0
        public void ToStringTest()
        {
            var document = new CsvDocument(new string[] { "name", "age" });

            document.Write("Light", 18);
            document.Write("Misa", 20);

            Assert.AreEqual("name,age\r\nLight,18\r\nMisa,20\r\n", document.ToString());
        }
Example #2
0
        public void WriteTest()
        {
            var document = new CsvDocument(new string[] { "name", "age" });

            document.Write("Light", 18);
            document.Write("Misa", 20);

            Assert.IsFalse(document.IsEmpty);
            Assert.AreEqual(2, document.Count);
        }
Example #3
0
        public void ToStringTest1()
        {
            var format   = new CsvFormat(';', '\"');
            var document = new CsvDocument(new string[] { "name", "age" }, format);

            document.Write("Light", 18);
            document.Write("Misa", 20);

            Assert.AreEqual("name;age\r\nLight;18\r\nMisa;20\r\n", document.ToString(format));
        }
Example #4
0
        public void MutateAtTest()
        {
            var document = new CsvDocument(new string[] { "name", "age" });

            document.Write("Light", 18);
            document.Write("Misa", 20);

            document.MutateAt(0, record => record.Update("name", "Light Yagami"));
            Assert.AreEqual("Light Yagami,18", document[0].ToString());
        }
Example #5
0
        public void WithFormatTest()
        {
            var document = new CsvDocument(new string[] { "name", "age" });

            document.Write("Light", 18);
            document.Write("Misa", 20);

            var copy = document.WithFormat(new CsvFormat(';', '"'));

            Assert.AreEqual("name;age\r\nLight;18\r\nMisa;20\r\n", copy.ToString());
        }
Example #6
0
        public void WriteWithAtTest()
        {
            var document = new CsvDocument(new string[] { "name", "age" });

            document.Write("Light", 18);
            document.Write("Misa", 20);

            document.WriteAtWith(0, new { Name = "Ryuk", Age = 999 });

            Assert.IsFalse(document.IsEmpty);
            Assert.AreEqual(3, document.Count);
        }
Example #7
0
        public void WriteContentsToFileTest()
        {
            var document = new CsvDocument(new string[] { "name", "age" });

            document.Write("Light", 18);
            document.Write("Misa", 20);

            using (var tempFile = new TempFile())
            {
                document.WriteContentsToFile(tempFile.FullName);

                using var reader = new StreamReader(tempFile.FullName);
                Assert.AreEqual("name,age\r\nLight,18\r\nMisa,20\r\n", reader.ReadToEnd());
            }
        }
Example #8
0
        public void WriteTest()
        {
            var document = new CsvDocument <Person>();

            document.Write(new Person {
                Name = "Akari", Age = 20
            });
            document.Write(new Person {
                Name = "Mirakurun", Age = 19
            });

            Assert.AreEqual(2, document.Count);
            Assert.IsFalse(document.IsEmpty);

            Assert.AreEqual(new CsvRecord(document.Header, new string[] { "Akari", "20" }), document[0]);
            Assert.AreEqual(new CsvRecord(document.Header, new string[] { "Mirakurun", "19" }), document[1]);
        }
Example #9
0
        public void GetEnumeratorTest()
        {
            var document = new CsvDocument(new string[] { "name", "age" });

            document.Write("Light", 18);
            document.Write("Misa", 20);

            var enumerator = document.GetEnumerator();

            Assert.IsTrue(enumerator.MoveNext());
            Assert.AreEqual("Light,18", enumerator.Current.ToString());

            Assert.IsTrue(enumerator.MoveNext());
            Assert.AreEqual("Misa,20", enumerator.Current.ToString());

            Assert.IsFalse(enumerator.MoveNext());
        }
Example #10
0
        public void IndexerTest()
        {
            var document = new CsvDocument(new string[] { "name", "age" });

            document.Write("Light", 18);
            document.Write("Misa", 20);

            var record1 = new CsvRecord(document.Header, new string[] { "Light", "18" });

            Assert.AreEqual(record1, document[0]);

            var record2 = new CsvRecord(document.Header, new string[] { "Misa", "20" });

            Assert.AreEqual(record2, document[1]);

            Assert.Throws <ArgumentOutOfRangeException>(() =>
            {
                var _ = document[3];
            });
        }
Example #11
0
        public void RemoveAtTest()
        {
            var document = new CsvDocument(new string[] { "name", "age" });

            document.Write("Light", 18);
            document.Write("Misa", 20);

            document.RemoveAt(0);

            Assert.Throws <ArgumentOutOfRangeException>(() =>
            {
                document.RemoveAt(-1);
            });

            Assert.Throws <ArgumentOutOfRangeException>(() =>
            {
                document.RemoveAt(1);
            });

            Assert.IsFalse(document.IsEmpty);
            Assert.AreEqual(1, document.Count);
        }