Example #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);
            }
        }
Example #2
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
     }
 }
Example #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
     }
 }
Example #4
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);
            }
        }
Example #5
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);
            }
        }
Example #6
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);
            }
        }
Example #7
0
        public void op_Save_IEnumerableOfKeyStringDictionary_FuncNull()
        {
            var data = new List<KeyStringDictionary>();

            Assert.Throws<ArgumentNullException>(() => Tsv.Save(data, null as Func<KeyStringDictionary, FileInfo>));
        }
Example #8
0
        public void op_Save_IEnumerableOfKeyStringDictionary_FileInfoNull_FileMode()
        {
            var data = new List<KeyStringDictionary>();

            Assert.Throws<ArgumentNullException>(() => Tsv.Save(data, null, FileMode.Append));
        }