Esempio n. 1
0
        public void SplitName()
        {
            CSVImporter importer = new CSVImporter(/*isFirstRowHeader*/ true);

            Table Customers = importer.importFromFile(Path.Combine(filePath, "Customers.txt"));

            // Split the column CustomerName into First/LastName
            SplitColumn sc = new SplitColumn(Customers, Customers.Columns[2], /*delimiter*/ ' ');

            sc.Redo();

            Assert.IsTrue(Customers.Columns.Count == 12, "Column count is wrong");
        }
Esempio n. 2
0
        public void DeduceColumnConstraints()
        {
            CSVImporter       importer          = new CSVImporter(/*isFirstRowHeader*/ true);
            Table             table             = importer.importFromFile(Path.Combine(filePath, "Categories.txt"));
            ColumnConstraints columnConstraints = new ColumnConstraints();

            columnConstraints.DeducePrimaryKey(table);
            // We know that the first column Contains is a primary key
            bool isPrimaryKey =
                table.Columns[0].Meta.Constraints.ContainsKey(ConstraintKind.PrimaryKey);

            Assert.IsTrue(isPrimaryKey, "Column 0 not primary key!");
        }
Esempio n. 3
0
        public void DeduceColumnType()
        {
            CSVImporter importer   = new CSVImporter(/*isFirstRowHeader*/ true);
            Table       Categories = importer.importFromFile(Path.Combine(filePath, "Categories.txt"));

            foreach (Column column in Categories.Columns)
            {
                ColumnType.ResolveColumnType(column);
            }
            // ID
            Assert.IsTrue(Categories.Columns[0].Meta.Type == typeof(Int32), "Types differ.");
            // CategoryName
            Assert.IsTrue(Categories.Columns[1].Meta.Type == typeof(string), "Types differ.");
            // Description
            Assert.IsTrue(Categories.Columns[2].Meta.Type == typeof(string), "Types differ.");
            // Picture
            Assert.IsTrue(Categories.Columns[3].Meta.Type == typeof(string), "Types differ.");
        }
Esempio n. 4
0
        public void SortByColumnAction()
        {
            CSVImporter importer   = new CSVImporter(/*isFirstRowHeader*/ true);
            Table       Categories = importer.importFromFile(Path.Combine(filePath, "Categories.txt"));
            // Note that only the first and the last records are out of order. Thus we can
            // simply change them. A lot quicker at that point of development.
            string        expectedAfterUndo = Categories.ToString();
            List <string> expectedList      = new List <string>(expectedAfterUndo.Split('\n'));
            string        lastRec           = expectedList[8];

            expectedList[8] = expectedList[1];
            expectedList[1] = lastRec;
            string expected = String.Join("\n", expectedList);

            SortByColumnAction sort = new SortByColumnAction(Categories, /*colIndex*/ 0);

            sort.Redo();
            Assert.IsTrue(Categories.ToString() == expected.ToString(), "Sort not working.");
            // Now revert the action:
            sort.Undo();
            Assert.IsTrue(Categories.ToString() == expectedAfterUndo, "Undo Sort not working.");
        }
Esempio n. 5
0
        public void CheckCategories()
        {
            Table Categories = importer.importFromFile(Path.Combine(filePath, "Categories.txt"));

            CheckTable(Categories, "Categories", 8, 4);
        }