Beispiel #1
0
        public void RemoveAttachedCell()
        {
            TestDatabase.CreateNew();
            var row = new Database(TestDatabase.Path).Tables["Table1"].Rows.First();

            row.Cells.Remove("Value1");
        }
Beispiel #2
0
        public void Load()
        {
            TestDatabase.CreateNew();
            var database = new Database(TestDatabase.Path);

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

            TestColumn(table1, "Id", ColumnType.Integer, true, false);
            TestColumn(table1, "Value1", ColumnType.Text, false, false);
            TestColumn(table1, "Value2", ColumnType.Real, false, true);
            Assert.IsNull(table1.Columns["NonExistingColumn"]);
            Assert.IsNotNull(table1.Columns["value1"]); // casing

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

            Assert.IsNotNull(table2);
            Assert.AreEqual(2, table2.Columns.Count);
            TestColumn(table2, "Value3", ColumnType.Text, true, false);
            TestColumn(table2, "Value4", ColumnType.Text, false, true);

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

            Assert.IsNotNull(table3);
            Assert.AreEqual(5, table3.Columns.Count);
            TestColumn(table3, "Value5", ColumnType.Integer, true, false);
            TestColumn(table3, "Value6", ColumnType.Text, false, true);
            TestColumn(table3, "Value7", ColumnType.BLOB, false, false);
            TestColumn(table3, "Value8", ColumnType.Real, false, true);
            TestColumn(table3, "Value9", ColumnType.Numeric, false, false);
        }
Beispiel #3
0
        public void AddCellToAttachedRow()
        {
            TestDatabase.CreateNew();
            var row = new Database(TestDatabase.Path).Tables["Table1"].Rows.First();

            row.Cells.Add("NewColumn", "test");
        }
Beispiel #4
0
        public void CreatePrimaryKeyInExistingTable()
        {
            TestDatabase.CreateNew();
            var database = new Database(TestDatabase.Path);

            database.Tables["Table1"].Columns.Add("PKColumn", ColumnType.Integer, ColumnQuantity.Single, false, true);
        }
Beispiel #5
0
        public void Create()
        {
            TestDatabase.CreateNew();
            var database = new Database(TestDatabase.Path);

            var table = database.Tables["Table3"];
            var row   = new Row();

            row.Cells.Add("Value5", 20);
            row.Cells.Add("Value6", "example");
            row.Cells.Add("Value7", new Byte[] { 1, 2 });
            row.Cells.Add("Value8", 10.14123156921);
            row.Cells.Add("Value9", 5.6);
            table.Rows.Add(row);

            database = new Database(TestDatabase.Path);
            table    = database.Tables["Table3"];
            Assert.AreEqual(2, table.Rows.Count);
            row = table.Rows.Single(x => (long)x.Cells["Value5"].Value == 20);
            Assert.IsNotNull(row);
            Assert.IsNotNull(row.RowId);
            Assert.IsTrue(row.Cells["Value5"].Type == ColumnType.Integer);
            Assert.AreEqual((long)20, row.Cells["Value5"].Value);
            Assert.IsTrue(row.Cells["Value6"].Type == ColumnType.Text);
            Assert.AreEqual("example", row.Cells["Value6"].Value);
            Assert.IsTrue(row.Cells["Value7"].Type == ColumnType.BLOB);
            Assert.AreEqual(1, ((byte[])row.Cells["Value7"].Value)[0]);
            Assert.AreEqual(2, ((byte[])row.Cells["Value7"].Value)[1]);
            Assert.IsTrue(row.Cells["Value8"].Type == ColumnType.Real);
            Assert.AreEqual(10.14123156921, row.Cells["Value8"].Value);
            Assert.IsTrue(row.Cells["Value9"].Type == ColumnType.Numeric);
            Assert.AreEqual(5.6M, row.Cells["Value9"].Value);
            Assert.IsNull(row.Cells["Value0"]);
        }
Beispiel #6
0
        public void CreateNotNullWithoutDefaultValueInExistingTable()
        {
            TestDatabase.CreateNew();
            var database = new Database(TestDatabase.Path);

            database.Tables["Table1"].Columns.Add("NullColumn", ColumnType.Integer, ColumnQuantity.Single, false);
        }
Beispiel #7
0
        public void AddNullToNotNullColumn()
        {
            TestDatabase.CreateNew();
            var database = new Database(TestDatabase.Path);
            var table    = database.Tables["Table1"];

            table.Rows.Add(new Cell("Value1", null), new Cell("Value2", 29.2));
        }
Beispiel #8
0
        public void CreateForeignKeyToNotPrimaryKey()
        {
            TestDatabase.CreateNew();
            var database = new Database(TestDatabase.Path);

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

            table2.Columns.AddForeignKey("Table1Id", database.Tables["Table1"].Columns["Id"]);
        }
Beispiel #9
0
        public void AddWithOtherColumn()
        {
            TestDatabase.CreateNew();
            var database    = new Database(TestDatabase.Path);
            var otherColumn = database.Tables["Table2"].Columns.First();
            var cell        = new Cell(otherColumn, "test");

            database.Tables["Table1"].Rows.Add(cell);
        }
Beispiel #10
0
        public void AverageWrongType()
        {
            TestDatabase.CreateNew();
            var database = new Database(TestDatabase.Path);

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

            table.Rows.Average("Value1");
        }
Beispiel #11
0
        public void AddToListColumn()
        {
            TestDatabase.CreateNew();
            var database = new Database(TestDatabase.Path);
            var table    = database.Tables["Table1"];

            table.Columns.Add("List", ColumnType.Text, ColumnQuantity.List);
            table.Rows.Add(new Cell("Value1", "test"), new Cell("Value2", 0.2), new Cell("List", "example"));
        }
Beispiel #12
0
        public void SumNull()
        {
            TestDatabase.CreateNew();
            var database = new Database(TestDatabase.Path);

            var table = database.Tables["Table3"];
            var sum   = table.Rows.Sum("Value8");

            Assert.AreEqual(null, sum);
        }
Beispiel #13
0
        public void AddRowWithForeignKeyWrongTable()
        {
            TestDatabase.CreateNew();
            var database = new Database(TestDatabase.Path);

            var primaryRow = database.Tables["Table2"].Rows.First();
            var newRow     = new Row();

            newRow.Cells.AddForeignKey(database.Tables["Table4"].Columns["Table1Id"], primaryRow);
        }
Beispiel #14
0
        public void Sum()
        {
            TestDatabase.CreateNew();
            var database = new Database(TestDatabase.Path);

            var table = database.Tables["Table1"];
            var sum   = table.Rows.Sum("Value2");

            Assert.AreEqual(15.5D + 8D, sum);
        }
Beispiel #15
0
        public void Max()
        {
            TestDatabase.CreateNew();
            var database = new Database(TestDatabase.Path);

            var table1 = database.Tables["Table1"];
            var max    = table1.Rows.Max("Value2");

            Assert.AreEqual(15.5D, max);
        }
Beispiel #16
0
        public void LikeWrongType()
        {
            TestDatabase.CreateNew();
            var database = new Database(TestDatabase.Path);

            var table1   = database.Tables["Table1"];
            var likeRows = table1.Rows.Like("Value2", "%1%");

            Assert.AreEqual(0, likeRows.Count());
        }
Beispiel #17
0
        public void Average()
        {
            TestDatabase.CreateNew();
            var database = new Database(TestDatabase.Path);

            var table = database.Tables["Table1"];
            var avg   = table.Rows.Average("Value2");

            Assert.AreEqual((15.5D + 8D) / 2D, avg);
        }
Beispiel #18
0
        public void AddWithAutoField()
        {
            TestDatabase.CreateNew();

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

            table.Rows.Add(row);
            Assert.IsNotNull(row.Cells["Id"]);
        }
Beispiel #19
0
        public void Load()
        {
            TestDatabase.CreateNew();
            var database = new Database(TestDatabase.Path);

            Assert.AreEqual(4, database.Tables.Count);
            Assert.IsTrue(
                new[] { "Table1", "Table2", "Table3", "Table4" }.All(
                    name => database.Tables.Count(table => table.Name == name) == 1));
        }
Beispiel #20
0
        public void WhereWrongType()
        {
            TestDatabase.CreateNew();
            var database = new Database(TestDatabase.Path);

            var table1    = database.Tables["Table1"];
            var whereRows = table1.Rows.Where("Value1", Comparison.Equal, 20);

            Assert.AreEqual(0, whereRows.Count());
        }
Beispiel #21
0
        public void UpdateAfterAdd()
        {
            TestDatabase.CreateNew();
            var row = new Database(TestDatabase.Path).Tables["Table1"].Rows.Add(new Cell("Value1", "add"));

            Assert.AreEqual("add", (string)row.Cells["Value1"].Value);
            row.Cells["Value1"].Value = "update";

            row = new Database(TestDatabase.Path).Tables["Table1"].Rows.First();
            Assert.IsNotNull(row.Cells.Where(cell => (string)cell.Value == "update"));
        }
Beispiel #22
0
        public void WhereNull()
        {
            TestDatabase.CreateNew();
            var database = new Database(TestDatabase.Path);

            var table2    = database.Tables["Table2"];
            var whereRows = table2.Rows.Where("Value4", Comparison.Equal, null);

            Assert.AreEqual(1, whereRows.Count());
            Assert.AreEqual(null, whereRows.First().Cells["Value4"].Value);
        }
Beispiel #23
0
        public void WhereGreaterThan()
        {
            TestDatabase.CreateNew();
            var database = new Database(TestDatabase.Path);

            var table1    = database.Tables["Table1"];
            var whereRows = table1.Rows.Where("Value2", Comparison.GreaterThan, 10);

            Assert.AreEqual(1, whereRows.Count());
            Assert.AreEqual(15.5, whereRows.First().Cells["Value2"].Value);
        }
Beispiel #24
0
        public void OrderWrongType()
        {
            TestDatabase.CreateNew();
            var database = new Database(TestDatabase.Path);

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

            table3.Rows.Add(new Cell("Value5", 22), new Cell("Value7", new byte[] { 90, 12, 3 }),
                            new Cell("Value9", 12.0));
            table3.Rows.Order("Value7").ToList();
        }
Beispiel #25
0
        public void SumWrongType()
        {
            TestDatabase.CreateNew();
            var database = new Database(TestDatabase.Path);

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

            table.Rows.Add(new Cell("Value7", new byte[] { 5, 2, 4 }), new Cell("Value8", 0D), new Cell("Value9", 0));
            table.Rows.Add(new Cell("Value7", new byte[] { 8, 1 }), new Cell("Value8", 0D), new Cell("Value9", 0));

            table.Rows.Sum("Value7");
        }
Beispiel #26
0
        public void Update()
        {
            TestDatabase.CreateNew();
            var row = new Database(TestDatabase.Path).Tables["Table1"].Rows.First();

            row.Cells["Value1"].Value = "update";
            Assert.AreEqual("update", (string)row.Cells["Value1"].Value);

            var table = new Database(TestDatabase.Path).Tables["Table1"];

            Assert.IsNotNull(table.Rows.SingleOrDefault(r => (string)r.Cells["Value1"].Value == "update"));
        }
Beispiel #27
0
        public void Like()
        {
            TestDatabase.CreateNew();
            var database = new Database(TestDatabase.Path);

            var table1   = database.Tables["Table1"];
            var likeRows = table1.Rows.Like("Value1", "%e[sc]%");

            Assert.AreEqual(2, likeRows.Count());
            Assert.AreEqual("Test", likeRows.First().Cells["Value1"].Value);
            Assert.AreEqual("record 2", likeRows.Last().Cells["Value1"].Value);
        }
Beispiel #28
0
        public void ForeignKeysLoad()
        {
            TestDatabase.CreateNew();
            var database = new Database(TestDatabase.Path);

            var table4 = database.Tables["Table4"];

            Assert.AreEqual(1, table4.Columns["Table1Id"].ForeignKeys.Count);
            var key = table4.Columns["Table1Id"].ForeignKeys.First();

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

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

            table2.Name = "RenamedTable";

            database = new Database(TestDatabase.Path);
            Assert.IsNotNull(database.Tables["RenamedTable"]);
            Assert.IsNull(database.Tables["Table2"]);
        }
Beispiel #30
0
        public void RemoveNonExisting()
        {
            TestDatabase.CreateNew();
            var database = new Database(TestDatabase.Path);

            var tablesCount = database.Tables.Count;
            var result      = database.Tables.Remove("NonExistingTable");

            Assert.IsFalse(result);

            database = new Database(TestDatabase.Path);
            Assert.AreEqual(tablesCount, database.Tables.Count);
        }