Beispiel #1
0
        public void Min()
        {
            TestDatabase.CreateNew();
            var database = new Database(TestDatabase.Path);

            var table = database.Tables["Table3"];

            table.Rows.Add(new Cell("Value7", new byte[] { }), new Cell("Value8", 42D), new Cell("Value9", 0));
            table.Rows.Add(new Cell("Value7", new byte[] { }), new Cell("Value8", 22.11D), new Cell("Value9", 0));

            var min = table.Rows.Min("Value8");

            Assert.AreEqual(22.11D, min);
        }
Beispiel #2
0
        public void Remove()
        {
            TestDatabase.CreateNew();
            var database = new Database(TestDatabase.Path);

            var table3 = database.Tables["Table3"];

            Assert.IsTrue(database.Tables.Remove(table3));
            Assert.IsTrue(database.Tables.Remove("Table4"));

            database = new Database(TestDatabase.Path);
            Assert.IsNull(database.Tables["Table3"]);
            Assert.IsNull(database.Tables["Table4"]);
        }
Beispiel #3
0
        public void UpdateValue()
        {
            TestDatabase.Delete();
            var database = new Database(TestDatabase.Path);
            var table    = database.Tables.Add("Table", new Column("IntList", ColumnType.Integer, ColumnQuantity.List));

            table.Rows.Add(new Cell("IntList", new long[] { 5, 2, 1, 8 }));

            var row = new Database(TestDatabase.Path).Tables["Table"].Rows.Single();

            row.Cells["IntList"].Value = new long[] { 198142, 15, -40 };

            row = new Database(TestDatabase.Path).Tables["Table"].Rows.Single();
            CollectionAssert.AreEqual(new long[] { 198142, 15, -40 }, (long[])row.Cells["IntList"].Value);
        }
Beispiel #4
0
        public void WhereMultiCondition()
        {
            TestDatabase.CreateNew();
            var database = new Database(TestDatabase.Path);

            var table1 = database.Tables["Table1"];

            table1.Rows.Add(new Cell("Value1", "test"), new Cell("Value2", 1.5));

            var whereRows = table1.Rows.Where(new Condition("Value2", Comparison.GreaterThanOrEqual, 8),
                                              new Condition("Value2", Comparison.LessThan, 13.5));

            Assert.AreEqual(1, whereRows.Count());
            Assert.AreEqual(8D, whereRows.First().Cells["Value2"].Value);
        }
Beispiel #5
0
        public void AddComplexName()
        {
            TestDatabase.Delete();
            var database = new Database(TestDatabase.Path);

            var table1 = new Table("Complex Table.Name*1");

            table1.Columns.Add("column1", ColumnType.Text);
            table1.Rows.Add(new Cell("column1", "test"));
            database.Tables.Add(table1);

            database = new Database(TestDatabase.Path);
            table1   = database.Tables["Complex Table.Name*1"];
            Assert.IsNotNull(table1);
        }
Beispiel #6
0
        public void Clear()
        {
            TestDatabase.CreateNew();

            var table = new Database(TestDatabase.Path).Tables["Table3"];
            var rows  = table.Rows.Copy();

            table.Rows.Clear();

            Assert.AreEqual(0, table.Rows.Count);
            Assert.IsTrue(rows.All(row => !row.IsAttached && row.RowId == null && row.Table == null));

            table = new Database(TestDatabase.Path).Tables["Table3"];
            Assert.AreEqual(0, table.Rows.Count);
        }
Beispiel #7
0
        public void AddAndRemove()
        {
            TestDatabase.CreateNew();

            var table = new Database(TestDatabase.Path).Tables["Table1"];
            var row   = new Row(new Cell("Value1", "example"), new Cell("Value2", 0.1));

            table.Rows.Add(row);
            table.Rows.Remove(row);
            Assert.IsFalse(row.IsAttached);

            table = new Database(TestDatabase.Path).Tables["Table1"];
            Assert.AreEqual(3, table.Rows.Count);
            Assert.IsNull(table.Rows.SingleOrDefault(x => (string)x.Cells["Value1"].Value == "test"));
        }
Beispiel #8
0
        public void Order()
        {
            TestDatabase.CreateNew();
            var database = new Database(TestDatabase.Path);

            var table1 = database.Tables["Table1"];

            table1.Rows.Add(new Cell("Value1", "xyz"), new Cell("Value2", 8D));

            var ordered = table1.Rows.Order(new Order("Value2", true), new Order("Value1", false)).ToArray();

            Assert.AreEqual("  ", ordered[0].Cells["Value1"].Value);
            Assert.AreEqual("xyz", ordered[1].Cells["Value1"].Value);
            Assert.AreEqual("record 2", ordered[2].Cells["Value1"].Value);
            Assert.AreEqual("Test", ordered[3].Cells["Value1"].Value);
        }
Beispiel #9
0
        public void WhereEqual()
        {
            TestDatabase.CreateNew();
            var database = new Database(TestDatabase.Path);

            var table1 = database.Tables["Table1"];

            table1.Rows.Add(new Cell("Value1", "record 2"), new Cell("Value2", null));

            var whereRows = table1.Rows.Where("Value1", Comparison.Equal, "record 2");

            Assert.AreEqual(2, whereRows.Count());
            Assert.AreEqual("record 2", whereRows.First().Cells["Value1"].Value);
            Assert.AreEqual("record 2", whereRows.Last().Cells["Value1"].Value);
            Assert.AreEqual(8D, whereRows.First().Cells["Value2"].Value);
            Assert.AreEqual(null, whereRows.Last().Cells["Value2"].Value);
        }
Beispiel #10
0
        public void CreateAndLoad()
        {
            TestDatabase.Delete();
            var database = new Database(TestDatabase.Path);

            database.Tables.Add(new Table("Table0", new Column("Value", ColumnType.Real)));
            database.Tables.Add(new Table("Table1",
                                          new Column("Id", ColumnType.Integer, false, true),
                                          new Column("ListColumn", ColumnType.Integer, ColumnQuantity.List)));

            database = new Database(TestDatabase.Path);
            var listColumn = database.Tables["Table1"].Columns["ListColumn"];

            Assert.AreEqual(ColumnQuantity.List, listColumn.Quantity);
            Assert.AreEqual(ColumnType.Integer, listColumn.Type);
            Assert.AreNotEqual(ColumnQuantity.List, database.Tables["Table1"].Columns["Id"].Quantity);
            Assert.AreNotEqual(ColumnQuantity.List, database.Tables["Table0"].Columns["Value"].Quantity);
        }
Beispiel #11
0
        public void CreateComplexName()
        {
            TestDatabase.Delete();
            var database = new Database(TestDatabase.Path);

            var table1 = new Table {
                Name = "table1"
            };

            table1.Columns.Add("Complex1Column &Name_", ColumnType.Integer);
            table1.Rows.Add(new Cell("Complex1Column &Name_"));
            database.Tables.Add(table1);

            database = new Database(TestDatabase.Path);
            var column1 = database.Tables["table1"].Columns["Complex1Column &Name_"];

            Assert.IsNotNull(column1);
        }
Beispiel #12
0
        public void CreateForeignKeyToNewTable()
        {
            TestDatabase.Delete();
            var database = new Database(TestDatabase.Path);

            var table1 = new Table("Table1", new Column("Id", ColumnType.Integer, false, true),
                                   new Column("Value", ColumnType.Text));
            var table2 = new Table("Table2", new Column("Value2", ColumnType.Text));

            table2.Columns.AddForeignKey("Table1Id", table1.Columns["Id"]);

            database.Tables.Add(table1);
            database.Tables.Add(table2);

            database = new Database(TestDatabase.Path);
            var table1Fk = database.Tables["Table2"].Columns["Table1Id"].ForeignKeys.FirstOrDefault();

            Assert.IsNotNull(table1Fk);
        }
        public void Load()
        {
            TestDatabase.CreateNew();
            var database = new Database(TestDatabase.Path);

            var table1 = database.Tables["Table1"];

            Assert.AreEqual(1, table1.PrimaryKey.Count);
            Assert.AreSame(table1.Columns["Id"], table1.PrimaryKey.Single());

            var table2 = database.Tables["Table2"];

            Assert.AreEqual(1, table2.PrimaryKey.Count);
            Assert.AreSame(table2.Columns["Value3"], table2.PrimaryKey.Single());

            var table3 = database.Tables["Table3"];

            Assert.AreEqual(1, table3.PrimaryKey.Count);
            Assert.AreSame(table3.Columns["Value5"], table3.PrimaryKey.Single());
        }
Beispiel #14
0
        public void CreateInExistingTable()
        {
            TestDatabase.CreateNew();
            var database = new Database(TestDatabase.Path);

            var table1 = database.Tables["Table1"];

            table1.Columns.Add("NewColumn", ColumnType.Integer);
            table1.Columns.Add("NotNullColumn", ColumnType.Real, ColumnQuantity.Single, false, false, 14.2);

            database = new Database(TestDatabase.Path);
            table1   = database.Tables["Table1"];

            Assert.IsNotNull(table1.Columns["NewColumn"]);
            Assert.AreEqual(ColumnType.Integer, table1.Columns["NewColumn"].Type);

            Assert.IsNotNull(table1.Columns["NotNullColumn"]);
            Assert.AreEqual(ColumnType.Real, table1.Columns["NotNullColumn"].Type);
            Assert.AreEqual(14.2, (double)table1.Columns["NotNullColumn"].DefaultValue);
        }
Beispiel #15
0
        public void CreateForeignKey()
        {
            TestDatabase.CreateNew();
            var database = new Database(TestDatabase.Path);

            var table1 = database.Tables["Table1"];
            var table5 = new Table("Table5");

            table5.Columns.AddForeignKey("Table1Id", table1.Columns["Id"]);
            database.Tables.Add(table5);

            database = new Database(TestDatabase.Path);
            table5   = database.Tables["Table5"];

            var table1Fk = table5.Columns["Table1Id"].ForeignKeys.FirstOrDefault();

            Assert.IsNotNull(table1Fk);
            Assert.AreSame(table1Fk.Table, database.Tables["Table1"]);
            Assert.AreSame(table1Fk.Column, database.Tables["Table1"].Columns["Id"]);
        }
Beispiel #16
0
        public void AddRowWithForeignKey()
        {
            TestDatabase.CreateNew();
            var database = new Database(TestDatabase.Path);

            var primaryRow =
                database.Tables["Table1"].Rows.First(row => (string)row.Cells["Value1"].Value == "record 2");
            var table4 = database.Tables["Table4"];
            var newRow = new Row();

            newRow.Cells.AddForeignKey(table4.Columns["Table1Id"], primaryRow);
            newRow.Cells.Add("Value", "foreignTestRow");
            table4.Rows.Add(newRow);

            database = new Database(TestDatabase.Path);
            table4   = database.Tables["Table4"];
            var foreignRow = table4.Rows.First(row => (string)row.Cells["Value"].Value == "foreignTestRow");

            Assert.AreEqual(primaryRow.Cells["Id"].Value, foreignRow.Cells["Table1Id"].Value);
        }
Beispiel #17
0
        public void Load()
        {
            TestDatabase.CreateNew();
            var database = new Database(TestDatabase.Path);

            var table1 = database.Tables["Table1"];

            Assert.AreEqual(3, table1.Rows.Count);
            Assert.IsTrue(table1.Rows.Count(x =>
                                            (string)x.Cells["Value1"].Value == "Test" &&
                                            (double)x.Cells["Value2"].Value == 15.5) == 1);
            Assert.IsTrue(table1.Rows.Count(x =>
                                            (string)x.Cells["Value1"].Value == "record 2" &&
                                            (double)x.Cells["Value2"].Value == 8) == 1);
            Assert.IsTrue(table1.Rows.Count(x =>
                                            (string)x.Cells["Value1"].Value == "  " &&
                                            x.Cells["Value2"].Value == null) == 1);
            Assert.IsTrue(table1.Rows.All(x => x.RowId != null));

            var table2 = database.Tables["Table2"];

            Assert.AreEqual(2, table2.Rows.Count);
            Assert.IsTrue(table2.Rows.Count(x =>
                                            (string)x.Cells["Value3"].Value == "key" &&
                                            x.Cells["Value4"].Value == null) == 1);
            Assert.IsTrue(table2.Rows.Count(x =>
                                            (string)x.Cells["Value3"].Value == "key2" &&
                                            (string)x.Cells["Value4"].Value == "value") == 1);
            Assert.IsTrue(table2.Rows.All(x => x.RowId != null));

            var table3 = database.Tables["Table3"];

            Assert.AreEqual(1, table3.Rows.Count);
            Assert.IsTrue(table3.Rows.Count(x =>
                                            (long)x.Cells["Value5"].Value == 15 &&
                                            (string)x.Cells["Value6"].Value == "test" &&
                                            ((byte[])x.Cells["Value7"].Value)[0] == 0xFD &&
                                            x.Cells["Value8"].Value == null &&
                                            (decimal)x.Cells["Value9"].Value == 10.5M) == 1);
            Assert.IsTrue(table3.Rows.All(x => x.RowId != null));
        }
Beispiel #18
0
        public void Add()
        {
            TestDatabase.Delete();
            var database = new Database(TestDatabase.Path);

            var column1 = new Column("column1", ColumnType.Text);
            var table1  = database.Tables.Add("table1", column1);

            Assert.AreEqual("table1", table1.Name);

            var table2 = new Table {
                Name = "table2"
            };

            table2.Columns.Add("column2", ColumnType.Numeric);
            database.Tables.Add(table2);

            database = new Database(TestDatabase.Path);
            Assert.AreEqual(2, database.Tables.Count);
            Assert.IsNotNull(database.Tables["table1"]);
            Assert.IsNotNull(database.Tables["table2"]);
        }
Beispiel #19
0
        public void Create()
        {
            TestDatabase.Delete();
            var database = new Database(TestDatabase.Path);

            var table1 = new Table {
                Name = "table1"
            };

            table1.Columns.Add("value1", ColumnType.Numeric);
            var column2 = new Column("value2", ColumnType.Real);

            table1.Columns.Add(column2);
            database.Tables.Add(table1);

            database = new Database(TestDatabase.Path);
            var column1 = database.Tables["table1"].Columns["value1"];

            Assert.IsNotNull(column1);
            Assert.AreEqual(ColumnType.Numeric, column1.Type);
            column2 = database.Tables["table1"].Columns["value2"];
            Assert.IsNotNull(column2);
            Assert.AreEqual(ColumnType.Real, column2.Type);
        }
Beispiel #20
0
 public void Open()
 {
     TestDatabase.CreateNew();
     var database = new Database(TestDatabase.Path);
 }