コード例 #1
0
        public void AddRow_Error_AdditionalElement_DefineOnce()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.DefineOnce);
            dynamic row;

            //add values
            row = new ExpandoObject();
            row.FirstName = "Hans";
            row.LastName = "Mueller";
            row.Age = 30;
            table.AddRow(row);

            try
            {
                row = new ExpandoObject();
                row.FirstName = "Hans";
                row.LastName = "Meier";
                row.Age = 30;
                row.Street = "Main street";
                table.AddRow(row);

                Assert.Fail();
            }
            catch (ArgumentException)
            {
            }
        }
コード例 #2
0
        public void AddRows_Error_Rollback()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.Expandable);
            dynamic row;
            dynamic rowB;

            //add values
            row = new ExpandoObject();
            row.FirstName = "Hans";
            row.LastName = "Mueller";
            row.Age = 30;
            table.AddRow(row);

            try
            {
                row = new ExpandoObject();
                row.FirstName = "Hans";
                row.LastName = "Meier";
                row.Age = 30;

                rowB = new ExpandoObject();
                rowB.LastName = 50;
                rowB.Street = "Main street";

                table.AddRows(new List<dynamic>(){ row, rowB});

                Assert.Fail();
            }
            catch (ArgumentException)
            {
            }

            //compare
            Assert.AreEqual(1, table.Rows.Count);
        }
コード例 #3
0
        private static void ImportTableCsvFile()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.Expandable);

            //pre define columns
            table.PreDefineColumns(
                new List<IDynamicTableColumn>()
                {
                    new DynamicTableColumn<string>("FirstName"),
                    new DynamicTableColumn<string>("LastName"),
                    new DynamicTableColumn<int>("Age"),
                    new DynamicTableColumn<string>("Street")
                });

            //import
            using (StreamReader reader = new StreamReader("test.csv"))
            {
                table.FromCsv(ReadFile(reader));
            }

            foreach (dynamic actualRow in table.Rows)
            {
                Console.WriteLine(
                    string.Format("{0} {1} is {2} years old.",
                        actualRow.FirstName,
                        actualRow.LastName,
                        actualRow.Age));
            }
        }
コード例 #4
0
        static void Main(string[] args)
        {
            dynamic element = new ExpandoObject();
            element.FirstName = "John";
            element.LastName = "Doe";
            element.Age = 30;

            using (StreamWriter writer = new StreamWriter("test.csv"))
            {
                writer.Write(ExpandoObjectSerializer.AsCsv(element));
            }

            ImportElementCsvFile();

            IDynamicTable table = new DynamicTable(DynamicTableType.Expandable);
            dynamic row;

            row = new ExpandoObject();
            row.FirstName = "John";
            row.LastName = "Doe";
            row.Age = 30;
            table.AddRow(row);

            row = new ExpandoObject();
            row.FirstName = "Jane";
            row.LastName = "Doe";
            row.Street = "Main street";
            table.AddRow(row);

            foreach (dynamic actualRow in table.Rows)
            {
                Console.WriteLine(
                    string.Format("{0} {1} is {2} years old.",
                        actualRow.FirstName,
                        actualRow.LastName,
                        actualRow.Age));
            }

            using (StreamWriter writer = new StreamWriter("test.csv"))
            {
                writer.Write(table.AsCsv());
            }

            using (StreamWriter writer = new StreamWriter("test.xml"))
            {
                writer.Write(table.AsXml());
            }

            ImportTableCsvFile();

            Console.ReadKey();
        }
コード例 #5
0
        public void FromCsv_WrongColumnNames()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.Expandable);

            List<string> csvContent = new List<string>()
            {
                "FirstName,Abc,Age,Street",
                "\"Hans\",\"Mueller\",30,\"\"",
                 "\"\",\"Meier\",0,\"Main street\""
            };

            //columns
            table.PreDefineColumns(
                new List<IDynamicTableColumn>()
                {
                    new DynamicTableColumn<string>("FirstName"),
                    new DynamicTableColumn<string>("LastName"),
                    new DynamicTableColumn<int>("Age", -1),
                    new DynamicTableColumn<string>("Street"),
                });

            //import
            try
            {
                table.FromCsv(csvContent, true, ',', true);
                Assert.Fail();
            }
            catch (FormatException)
            {
            }
        }
コード例 #6
0
        public void FromCsv_Standard()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.Expandable);
            dynamic row;

            List<string> csvContent = new List<string>()
            {
                "\"Hans\",\"Mueller\",30,\"\"",
                 "\"\",\"Meier\",0,\"Main street\""
            };

            //columns
            table.PreDefineColumns(
                new List<IDynamicTableColumn>()
                {
                    new DynamicTableColumn<string>("FirstName"),
                    new DynamicTableColumn<string>("LastName"),
                    new DynamicTableColumn<int>("Age", -1),
                    new DynamicTableColumn<string>("Street"),
                });

            //import
            table.FromCsv(csvContent);

            //compare
            Assert.AreEqual(2, table.Rows.Count);

            row = table.Rows[0];
            Assert.AreEqual("Hans", row.FirstName);
            Assert.AreEqual("Mueller", row.LastName);
            Assert.AreEqual(30, row.Age);
            Assert.AreEqual("", row.Street);

            row = table.Rows[1];
            Assert.AreEqual("", row.FirstName);
            Assert.AreEqual("Meier", row.LastName);
            Assert.AreEqual(0, row.Age);
            Assert.AreEqual("Main street", row.Street);
        }
コード例 #7
0
        public void FromCsv_Null()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.Expandable);

            List<string> csvContent = new List<string>();

            //columns
            table.PreDefineColumns(
                new List<IDynamicTableColumn>()
                {
                    new DynamicTableColumn<string>("FirstName"),
                    new DynamicTableColumn<string>("LastName"),
                    new DynamicTableColumn<int>("Age", -1),
                    new DynamicTableColumn<string>("Street"),
                });

            //import
            table.FromCsv(null);

            //compare
            Assert.AreEqual(0, table.Rows.Count);
        }
コード例 #8
0
        public void AsXml_Standard()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.Expandable);
            dynamic row;
            string csvContent;
            string expectedContent;

            //add values
            row = new ExpandoObject();
            row.FirstName = "Hans";
            row.LastName = "Mueller";
            row.Age = 30;
            table.AddRow(row);

            row = new ExpandoObject();
            row.LastName = "Meier";
            row.Street = "Main street";
            table.AddRow(row);

            //get csv
            csvContent = table.AsXml();

            //compare
            expectedContent =
                "<DynamicTable>" + Environment.NewLine +
                "  <Rows>" + Environment.NewLine +
                "    <Row>" + Environment.NewLine +
                "      <FirstName value=\"Hans\" />" + Environment.NewLine +
                "      <LastName value=\"Mueller\" />" + Environment.NewLine +
                "      <Age value=\"30\" />" + Environment.NewLine +
                "      <Street value=\"\" />" + Environment.NewLine +
                "    </Row>" + Environment.NewLine +
                "    <Row>" + Environment.NewLine +
                "      <FirstName value=\"\" />" + Environment.NewLine +
                "      <LastName value=\"Meier\" />" + Environment.NewLine +
                "      <Age value=\"0\" />" + Environment.NewLine +
                "      <Street value=\"Main street\" />" + Environment.NewLine +
                "    </Row>" + Environment.NewLine +
                "  </Rows>" + Environment.NewLine +
                "</DynamicTable>";

            Assert.AreEqual(expectedContent, csvContent);
        }
コード例 #9
0
        public void AsXml_Empty()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.Expandable);
            string csvContent;
            string expectedContent;

            //set columns
            table.PreDefineColumns(
                new List<IDynamicTableColumn>()
                {
                    new DynamicTableColumn<string>("FirstName", ""),
                    new DynamicTableColumn<string>("LastName"),
                    new DynamicTableColumn<int>("Age", -1)
                });

            //get csv
            csvContent = table.AsXml();

            //compare
            expectedContent =
                 "<DynamicTable>" + Environment.NewLine +
                 "  <Rows />" + Environment.NewLine +
                 "</DynamicTable>";

            Assert.AreEqual(expectedContent, csvContent);
        }
コード例 #10
0
        public void PreDefineColumns_Null()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.Expandable);

            //set columns
            try
            {
                table.PreDefineColumns(null);

                Assert.Fail();
            }
            catch (ArgumentNullException)
            {
            }
        }
コード例 #11
0
        public void PreDefineColumns_Error_NameNull()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.Expandable);

            //set columns
            try
            {
                table.PreDefineColumns(
                    new List<IDynamicTableColumn>()
                {
                    new DynamicTableColumn<string>(null, ""),
                    new DynamicTableColumn<string>("FirstName"),
                    new DynamicTableColumn<int>("Age", -1)
                });

                Assert.Fail();
            }
            catch (ArgumentException)
            {
            }
        }
コード例 #12
0
        public void AsCsv_Empty_WithoutHeaders()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.Expandable);
            string csvContent;

            //set columns
            table.PreDefineColumns(
                new List<IDynamicTableColumn>()
                {
                    new DynamicTableColumn<string>("FirstName", ""),
                    new DynamicTableColumn<string>("LastName"),
                    new DynamicTableColumn<int>("Age", -1)
                });

            //get csv
            csvContent = table.AsCsv(false, ',', false);

            //compare
            Assert.AreEqual("", csvContent);
        }
コード例 #13
0
        public void PreDefineColumns_Empty()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.Expandable);

            //set columns
            try
            {
                table.PreDefineColumns(new List<IDynamicTableColumn>());

                Assert.Fail();
            }
            catch (ArgumentException)
            {
            }
        }
コード例 #14
0
        public void PreDefineColumns_AlreadyDefined()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.Expandable);

            //set columns
            table.PreDefineColumns(
                new List<IDynamicTableColumn>()
                {
                    new DynamicTableColumn<string>("FirstName", ""),
                    new DynamicTableColumn<string>("LastName"),
                    new DynamicTableColumn<int>("Age", -1)
                });

            //compare
            Assert.AreEqual(3, table.Columns.Count);

            //set columns again
            try
            {
                table.PreDefineColumns(
                    new List<IDynamicTableColumn>()
                    {
                        new DynamicTableColumn<string>("FirstName", ""),
                        new DynamicTableColumn<string>("LastName"),
                        new DynamicTableColumn<int>("Age", -1)
                    });

                Assert.Fail();
            }
            catch (NotSupportedException)
            {
            }
        }
コード例 #15
0
        public void GetColumn_Standard()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.Expandable);
            dynamic row;

            IDynamicTableColumn column;

            //add values
            row = new ExpandoObject();
            row.FirstName = "Hans";
            row.LastName = "Mueller";
            row.Age = 30;
            table.AddRow(row);

            //compare
            column = table.GetColumn("LastName");
            Assert.AreEqual("LastName", column.Name);

            column = table.GetColumn("Age");
            Assert.AreEqual("Age", column.Name);
        }
コード例 #16
0
        public void AsDataTable_Standard()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.Expandable);
            dynamic row;
            DataTable dataTable;

            //add values
            row = new ExpandoObject();
            row.FirstName = "Hans";
            row.LastName = "Mueller";
            row.Age = 30;
            table.AddRow(row);

            row = new ExpandoObject();
            row.LastName = "Meier";
            row.Street = "Main street";
            row.Birthday = new DateTime(2001, 12, 20);
            table.AddRow(row);

            //get data table
            dataTable = table.AsDataTable();

            //compare
            Assert.AreEqual(5, dataTable.Columns.Count);
            Assert.AreEqual("FirstName", dataTable.Columns[0].ColumnName);
            Assert.AreEqual("LastName", dataTable.Columns[1].ColumnName);
            Assert.AreEqual("Age", dataTable.Columns[2].ColumnName);
            Assert.AreEqual("Street", dataTable.Columns[3].ColumnName);
            Assert.AreEqual("Birthday", dataTable.Columns[4].ColumnName);
            Assert.AreEqual("System.String", dataTable.Columns[0].DataType.ToString());
            Assert.AreEqual("System.String", dataTable.Columns[1].DataType.ToString());
            Assert.AreEqual("System.Int32", dataTable.Columns[2].DataType.ToString());
            Assert.AreEqual("System.String", dataTable.Columns[3].DataType.ToString());
            Assert.AreEqual("System.DateTime", dataTable.Columns[4].DataType.ToString());

            Assert.AreEqual(2, dataTable.Rows.Count);

            Assert.AreEqual("Hans", dataTable.Rows[0].ItemArray[0]);
            Assert.AreEqual("Mueller", dataTable.Rows[0].ItemArray[1]);
            Assert.AreEqual(30, dataTable.Rows[0].ItemArray[2]);
            Assert.AreEqual(DBNull.Value, dataTable.Rows[0].ItemArray[3]);
            Assert.AreEqual(new DateTime(0), dataTable.Rows[0].ItemArray[4]);

            Assert.AreEqual(DBNull.Value, dataTable.Rows[1].ItemArray[0]);
            Assert.AreEqual("Meier", dataTable.Rows[1].ItemArray[1]);
            Assert.AreEqual(0, dataTable.Rows[1].ItemArray[2]);
            Assert.AreEqual("Main street", dataTable.Rows[1].ItemArray[3]);
            Assert.AreEqual(new DateTime(2001, 12, 20), dataTable.Rows[1].ItemArray[4]);
        }
コード例 #17
0
        public void AsDataTable_Standard_PreDefineColumns()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.Expandable);
            dynamic row;
            DataTable dataTable;

            //set columns
            table.PreDefineColumns(
                new List<IDynamicTableColumn>()
                {
                    new DynamicTableColumn<string>("FirstName", ""),
                    new DynamicTableColumn<string>("LastName"),
                    new DynamicTableColumn<int>("Age", -1)
                });

            //add values
            row = new ExpandoObject();
            row.FirstName = "Hans";
            row.LastName = "Mueller";
            row.Age = 30;
            table.AddRow(row);

            row = new ExpandoObject();
            row.LastName = "Meier";
            table.AddRow(row);

            //get data table
            dataTable = table.AsDataTable();

            //compare
            Assert.AreEqual(3, dataTable.Columns.Count);
            Assert.AreEqual("FirstName", dataTable.Columns[0].ColumnName);
            Assert.AreEqual("LastName", dataTable.Columns[1].ColumnName);
            Assert.AreEqual("Age", dataTable.Columns[2].ColumnName);
            Assert.AreEqual("System.String", dataTable.Columns[0].DataType.ToString());
            Assert.AreEqual("System.String", dataTable.Columns[1].DataType.ToString());
            Assert.AreEqual("System.Int32", dataTable.Columns[2].DataType.ToString());

            Assert.AreEqual(2, dataTable.Rows.Count);

            Assert.AreEqual("Hans", dataTable.Rows[0].ItemArray[0]);
            Assert.AreEqual("Mueller", dataTable.Rows[0].ItemArray[1]);
            Assert.AreEqual(30, dataTable.Rows[0].ItemArray[2]);

            Assert.AreEqual("", dataTable.Rows[1].ItemArray[0]);
            Assert.AreEqual("Meier", dataTable.Rows[1].ItemArray[1]);
            Assert.AreEqual(-1, dataTable.Rows[1].ItemArray[2]);
        }
コード例 #18
0
        public void PreDefineColumns_Standard()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.Expandable);

            //set columns
            table.PreDefineColumns(
                new List<IDynamicTableColumn>()
                {
                    new DynamicTableColumn<string>("FirstName", ""),
                    new DynamicTableColumn<string>("LastName"),
                    new DynamicTableColumn<int>("Age", -1)
                });

            //compare
            Assert.AreEqual(3, table.Columns.Count);

            Assert.AreEqual("FirstName", table.Columns[0].Name);
            Assert.AreEqual("", table.Columns[0].DefaultValue);

            Assert.AreEqual("LastName", table.Columns[1].Name);
            Assert.AreEqual(null, table.Columns[1].DefaultValue);

            Assert.AreEqual("Age", table.Columns[2].Name);
            Assert.AreEqual(-1, table.Columns[2].DefaultValue);
        }
コード例 #19
0
        public void AsXml_NotInitialized()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.Expandable);
            string csvContent;

            //get csv
            csvContent = table.AsXml();

            //compare
            Assert.AreEqual("", csvContent);
        }
コード例 #20
0
        public void ResetTable_NotInitialized()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.Expandable);

            //reset
            table.ResetTable();

            //compare
            Assert.AreEqual(null, table.Rows);
            Assert.AreEqual(null, table.Columns);
        }
コード例 #21
0
        public void FromCsv_AlreadyContainsRows()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.Expandable);

            List<string> csvContent = new List<string>()
            {
                "\"Hans\",\"Mueller\",30,\"\"",
                 "\"\",\"Meier\",0,\"Main street\""
            };

            //columns
            table.PreDefineColumns(
                new List<IDynamicTableColumn>()
                {
                    new DynamicTableColumn<string>("FirstName"),
                    new DynamicTableColumn<string>("LastName"),
                    new DynamicTableColumn<int>("Age", -1),
                    new DynamicTableColumn<string>("Street"),
                });

            //import
            table.FromCsv(csvContent);

            //compare
            Assert.AreEqual(2, table.Rows.Count);

            //import again
            try
            {
                table.FromCsv(csvContent);
                Assert.Fail();
            }
            catch (NotSupportedException)
            {
            }
        }
コード例 #22
0
        public void ResetTable_Standard()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.Expandable);
            dynamic row;

            //add values
            row = new ExpandoObject();
            row.FirstName = "Hans";
            row.LastName = "Mueller";
            row.Age = 30;
            table.AddRow(row);

            //compare
            Assert.AreEqual(1, table.Rows.Count);
            Assert.AreEqual(3, table.Columns.Count);

            //reset
            table.ResetTable();

            //compare
            Assert.AreEqual(null, table.Rows);
            Assert.AreEqual(null, table.Columns);
        }
コード例 #23
0
        public void FromCsv_NoColumns()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.Expandable);

            List<string> csvContent = new List<string>()
            {
                "\"Hans\",\"Mueller\",30,\"\"",
                 "\"\",\"Meier\",0,\"Main street\""
            };

            //import
            try
            {
                table.FromCsv(csvContent);
                Assert.Fail();
            }
            catch (NotSupportedException)
            {
            }
        }
コード例 #24
0
        public void AsCsv_Semicolon_WithoutHeaders_WithoutQuotes()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.Expandable);
            dynamic row;
            string csvContent;
            string expectedContent;

            //add values
            row = new ExpandoObject();
            row.FirstName = "Hans";
            row.LastName = "Mueller";
            row.Age = 30;
            table.AddRow(row);

            row = new ExpandoObject();
            row.LastName = "Meier";
            row.Street = "Main street";
            table.AddRow(row);

            //get csv
            csvContent = table.AsCsv(false, ';', false);

            //compare
            expectedContent = "Hans;Mueller;30;" + Environment.NewLine +
                 ";Meier;0;Main street" + Environment.NewLine;

            Assert.AreEqual(expectedContent, csvContent);
        }
コード例 #25
0
        public void FromCsv_Semicolon_WithoutHeaders_WithoutQuotes()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.Expandable);
            dynamic row;

            List<string> csvContent = new List<string>()
            {
                 "Hans;Mueller;30;",
                 ";Meier;0;Main street"
            };

            //columns
            table.PreDefineColumns(
                new List<IDynamicTableColumn>()
                {
                    new DynamicTableColumn<string>("FirstName"),
                    new DynamicTableColumn<string>("LastName"),
                    new DynamicTableColumn<int>("Age", -1),
                    new DynamicTableColumn<string>("Street"),
                });

            //import
            table.FromCsv(csvContent, false, ';', false);

            //compare
            Assert.AreEqual(2, table.Rows.Count);

            row = table.Rows[0];
            Assert.AreEqual("Hans", row.FirstName);
            Assert.AreEqual("Mueller", row.LastName);
            Assert.AreEqual(30, row.Age);
            Assert.AreEqual("", row.Street);

            row = table.Rows[1];
            Assert.AreEqual("", row.FirstName);
            Assert.AreEqual("Meier", row.LastName);
            Assert.AreEqual(0, row.Age);
            Assert.AreEqual("Main street", row.Street);
        }
コード例 #26
0
        public void AsCsv_Standard()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.Expandable);
            dynamic row;
            string csvContent;
            string expectedContent;

            //add values
            row = new ExpandoObject();
            row.FirstName = "Hans";
            row.LastName = "Mueller";
            row.Age = 30;
            table.AddRow(row);

            row = new ExpandoObject();
            row.LastName = "Meier";
            row.Street = "Main street";
            table.AddRow(row);

            //get csv
            csvContent = table.AsCsv();

            //compare
            expectedContent = "\"Hans\",\"Mueller\",30,\"\"" + Environment.NewLine +
                 "\"\",\"Meier\",0,\"Main street\"" + Environment.NewLine;

            Assert.AreEqual(expectedContent, csvContent);
        }
コード例 #27
0
        public void FromCsv_WithHeaders_OtherSortOrderInFile()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.Expandable);
            dynamic row;

            List<string> csvContent = new List<string>()
            {
                 "Street,FirstName,Age,LastName",
                 ",Hans,30,Mueller",
                 "Main street,,0,Meier"
            };

            //columns
            table.PreDefineColumns(
                new List<IDynamicTableColumn>()
                {
                    new DynamicTableColumn<string>("FirstName"),
                    new DynamicTableColumn<string>("LastName"),
                    new DynamicTableColumn<int>("Age", -1),
                    new DynamicTableColumn<string>("Street"),
                });

            //import
            table.FromCsv(csvContent, true, ',', false);

            //compare
            Assert.AreEqual(2, table.Rows.Count);

            row = table.Rows[0];
            Assert.AreEqual("Hans", row.FirstName);
            Assert.AreEqual("Mueller", row.LastName);
            Assert.AreEqual(30, row.Age);
            Assert.AreEqual("", row.Street);

            row = table.Rows[1];
            Assert.AreEqual("", row.FirstName);
            Assert.AreEqual("Meier", row.LastName);
            Assert.AreEqual(0, row.Age);
            Assert.AreEqual("Main street", row.Street);
        }
コード例 #28
0
        public void AsDataTable_Empty()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.Expandable);
            DataTable dataTable;

            //set columns
            table.PreDefineColumns(
                new List<IDynamicTableColumn>()
                {
                    new DynamicTableColumn<string>("FirstName", ""),
                    new DynamicTableColumn<string>("LastName"),
                    new DynamicTableColumn<int>("Age", -1)
                });

            //get csv
            dataTable = table.AsDataTable();

            //compare
            Assert.AreEqual(3, dataTable.Columns.Count);
            Assert.AreEqual("FirstName", dataTable.Columns[0].ColumnName);
            Assert.AreEqual("LastName", dataTable.Columns[1].ColumnName);
            Assert.AreEqual("Age", dataTable.Columns[2].ColumnName);
            Assert.AreEqual("System.String", dataTable.Columns[0].DataType.ToString());
            Assert.AreEqual("System.String", dataTable.Columns[1].DataType.ToString());

            Assert.AreEqual(0, dataTable.Rows.Count);
        }
コード例 #29
0
        public void FromCsv_WrongNumberOfElements()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.Expandable);

            List<string> csvContent = new List<string>()
            {
                "\"Hans\",\"Mueller\",30,\"\"",
                 "\"\",\"Meier\",0"
            };

            //columns
            table.PreDefineColumns(
                new List<IDynamicTableColumn>()
                {
                    new DynamicTableColumn<string>("FirstName"),
                    new DynamicTableColumn<string>("LastName"),
                    new DynamicTableColumn<int>("Age", -1),
                    new DynamicTableColumn<string>("Street"),
                });

            //import
            try
            {
                table.FromCsv(csvContent);
                Assert.Fail();
            }
            catch (FormatException)
            {
            }

            //compare
            Assert.AreEqual(0, table.Rows.Count);
        }
コード例 #30
0
        public void AsDataTable_NotInitialized()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.Expandable);
            DataTable dataTable;

            //get csv
            dataTable = table.AsDataTable();

            //compare
            Assert.AreEqual(null, dataTable);
        }