Beispiel #1
0
        public void op_Save_DataTable_FileInfo_whenAppend()
        {
            var table = new DataTable
                            {
                                Locale = CultureInfo.InvariantCulture
                            };
            table.Columns.Add("A");
            table.Columns.Add("B");
            var row = table.NewRow();
            row["A"] = "1";
            row["B"] = "2";
            table.Rows.Add(row);

            using (var temp = new TempDirectory())
            {
                var file = temp.Info.ToFile("example.tsv").AppendLine("A\tB");

                Tsv.Save(table, file);

                var expected = "A\tB{0}1\t2{0}".FormatWith(Environment.NewLine);
                var actual = file.ReadToEnd();

                Assert.Equal(expected, actual);
            }
        }
Beispiel #2
0
 public void op_Line_KeyStringDictionaryNull_IListOfString()
 {
     var columns = new List<string>
                       {
                           "A"
                       };
     Assert.Throws<ArgumentNullException>(() => Tsv.Line(null, columns));
 }
Beispiel #3
0
 public void op_Save_IEnumerableOfKeyStringDictionaryNull_FileInfo_FileMode()
 {
     using (var file = new TempFile())
     {
         // ReSharper disable AccessToDisposedClosure
         Assert.Throws<ArgumentNullException>(() => Tsv.Save(null as IEnumerable<KeyStringDictionary>, file.Info, FileMode.Append));
         // ReSharper restore AccessToDisposedClosure
     }
 }
Beispiel #4
0
 public void op_Save_IEnumerableOfKeyStringDictionaryNull_Func()
 {
     using (var file = new TempFile())
     {
         // ReSharper disable AccessToDisposedClosure
         Assert.Throws<ArgumentNullException>(() => Tsv.Save(null, new TestEntryFile(file.Info).GetFile));
         // ReSharper restore AccessToDisposedClosure
     }
 }
Beispiel #5
0
        public void op_Line_IEnumerableString_whenEmptyValue()
        {
            var obj = new List<string>
                          {
                              string.Empty,
                              "ABC"
                          };

            const string expected = "\tABC";
            var actual = Tsv.Line(obj);

            Assert.Equal(expected, actual);
        }
Beispiel #6
0
        public void op_Line_KeyStringDictionary()
        {
            var obj = new KeyStringDictionary
                          {
                              new KeyStringPair("A", "123"),
                              new KeyStringPair("B", "XYZ")
                          };

            const string expected = "123\tXYZ";
            var actual = Tsv.Line(obj);

            Assert.Equal(expected, actual);
        }
Beispiel #7
0
        public void op_Line_KeyStringDictionary_whenEmptyValue()
        {
            var obj = new KeyStringDictionary
                          {
                              new KeyStringPair("A", string.Empty),
                              new KeyStringPair("B", "XYZ")
                          };

            const string expected = "\tXYZ";
            var actual = Tsv.Line(obj);

            Assert.Equal(expected, actual);
        }
Beispiel #8
0
        public void op_Line_IEnumerableString()
        {
            var obj = new List<string>
                          {
                              "123",
                              "ABC"
                          };

            const string expected = "123\tABC";
            var actual = Tsv.Line(obj);

            Assert.Equal(expected, actual);
        }
Beispiel #9
0
        public void op_Header_KeyStringDictionary_whenEmptyValue()
        {
            var obj = new KeyStringDictionary
                          {
                              new KeyStringPair(string.Empty, "x"),
                              new KeyStringPair("ABC", "x")
                          };

            const string expected = "\tABC";
            var actual = Tsv.Header(obj);

            Assert.Equal(expected, actual);
        }
Beispiel #10
0
        public void op_Save_IEnumerableOfKeyStringDictionaryEmpty_FileInfo_FileMode()
        {
            using (var temp = new TempDirectory())
            {
                var file = temp.Info.ToFile("test.tsv");
                file.CreateNew();

                Tsv.Save(new List<KeyStringDictionary>(), file, FileMode.Create);

                file.Refresh();
                Assert.False(file.Exists);
            }
        }
Beispiel #11
0
        public void op_Header_KeyStringDictionary()
        {
            var obj = new KeyStringDictionary
                          {
                              new KeyStringPair("A", string.Empty),
                              new KeyStringPair("B", string.Empty)
                          };

            const string expected = "A\tB";
            var actual = Tsv.Header(obj);

            Assert.Equal(expected, actual);
        }
Beispiel #12
0
        public void op_Line_KeyStringDictionary_IListOfString()
        {
            var obj = new KeyStringDictionary
                          {
                              new KeyStringPair("A", "123"),
                              new KeyStringPair("B", "ignore"),
                              new KeyStringPair("C", "XYZ")
                          };

            const string expected = "123\tXYZ";
            var actual = Tsv.Line(obj, "A|C".Split('|').ToList());

            Assert.Equal(expected, actual);
        }
Beispiel #13
0
        public void op_Save_DataTableEmpty_FileInfo_FileMode()
        {
            var table = new DataTable
                            {
                                Locale = CultureInfo.InvariantCulture
                            };

            using (var temp = new TempDirectory())
            {
                var file = temp.Info.ToFile("test.tsv");

                Tsv.Save(table, file, FileMode.Create);

                file.Refresh();
                Assert.False(file.Exists);
            }
        }
Beispiel #14
0
        public void op_Save_IEnumerableOfKeyStringDictionary_Func()
        {
            var data = new[]
                           {
                               new KeyStringDictionary
                                   {
                                       new KeyStringPair("A", "1"),
                                       new KeyStringPair("B", "2")
                                   }
                           };

            using (var temp = new TempDirectory())
            {
                var file = temp.Info.ToDirectory("example").ToFile("test.tsv");
                Tsv.Save(data, new TestEntryFile(file).GetFile);

                var expected = "A\tB{0}1\t2{0}".FormatWith(Environment.NewLine);
                var actual = file.ReadToEnd();

                Assert.Equal(expected, actual);
            }
        }
Beispiel #15
0
 public void op_Line_IEnumerableStringEmpty()
 {
     Assert.Throws<ArgumentOutOfRangeException>(() => Tsv.Line(new List<string>()));
 }
Beispiel #16
0
        public void op_Save_IEnumerableOfKeyStringDictionary_FuncNull()
        {
            var data = new List<KeyStringDictionary>();

            Assert.Throws<ArgumentNullException>(() => Tsv.Save(data, null as Func<KeyStringDictionary, FileInfo>));
        }
Beispiel #17
0
 public void op_Header_KeyStringDictionaryNull()
 {
     Assert.Throws<ArgumentNullException>(() => Tsv.Header(null));
 }
Beispiel #18
0
 public void op_Line_KeyStringDictionary_IListOfStringEmpty()
 {
     Assert.Throws<ArgumentOutOfRangeException>(() => Tsv.Line(new KeyStringDictionary(), new List<string>()));
 }
Beispiel #19
0
 public void op_Line_KeyStringDictionaryNull()
 {
     Assert.Throws<ArgumentNullException>(() => Tsv.Line(null as KeyStringDictionary));
 }
Beispiel #20
0
 public void op_Line_KeyStringDictionary_IListOfStringNull()
 {
     Assert.Throws<ArgumentNullException>(() => Tsv.Line(new KeyStringDictionary(), null as IList<string>));
 }
Beispiel #21
0
 public void op_Line_IEnumerableStringNull()
 {
     Assert.Throws<ArgumentNullException>(() => Tsv.Line(null as IEnumerable<string>));
 }
Beispiel #22
0
        public void op_Save_IEnumerableOfKeyStringDictionary_FileInfoNull_FileMode()
        {
            var data = new List<KeyStringDictionary>();

            Assert.Throws<ArgumentNullException>(() => Tsv.Save(data, null, FileMode.Append));
        }
Beispiel #23
0
 public void op_Header_KeyStringDictionaryEmpty()
 {
     Assert.Throws<ArgumentOutOfRangeException>(() => Tsv.Header(new KeyStringDictionary()));
 }
Beispiel #24
0
 public void op_Line_KeyStringDictionary_IListOfString_whenColumnsNotFound()
 {
     Assert.Throws<KeyNotFoundException>(() => Tsv.Line(new KeyStringDictionary(), "A,B".Split(',').ToList()));
 }