public void AddColumns() { // // Init the DB // var path = ""; using (var db = new TestDb(true) { Trace = true }) { path = db.DatabasePath; db.CreateTable <TestAddBefore> (); var cols = db.GetTableInfo("TestAdd"); Assert.AreEqual(2, cols.Count); var o = new TestAddBefore { Name = "Foo", }; db.Insert(o); var oo = db.Table <TestAddBefore> ().First(); Assert.AreEqual("Foo", oo.Name); } // // Migrate and use it // using (var db = new SQLiteConnection(path, true) { Trace = true }) { db.CreateTable <TestAddAfter> (); var cols = db.GetTableInfo("TestAdd"); Assert.AreEqual(4, cols.Count); var oo = db.Table <TestAddAfter> ().First(); Assert.AreEqual("Foo", oo.Name); Assert.AreEqual(0, oo.IntValue); Assert.AreEqual(null, oo.StringValue); var o = new TestAddAfter { Name = "Bar", IntValue = 42, StringValue = "Hello", }; db.Insert(o); var ooo = db.Get <TestAddAfter> (o.Id); Assert.AreEqual("Bar", ooo.Name); Assert.AreEqual(42, ooo.IntValue); Assert.AreEqual("Hello", ooo.StringValue); } }
public void UpperAndLowerColumnNames() { using (var db = new TestDb(true) { Trace = true }) { db.CreateTable <LowerId> (); db.CreateTable <UpperId> (); var cols = db.GetTableInfo("Test").ToList(); Assert.AreEqual(1, cols.Count); Assert.AreEqual("Id", cols[0].Name); } }
public void CreateTableWithNotNullConstraints() { using (var db = new TestDb()) { db.CreateTable <NotNullNoPK> (); var cols = db.GetTableInfo("NotNullNoPK"); var joined = from expected in GetExpectedColumnInfos(typeof(NotNullNoPK)) join actual in cols on expected.Name equals actual.Name where actual.notnull != expected.notnull select actual.Name; Assert.AreNotEqual(0, cols.Count(), "Failed to get table info"); Assert.IsTrue(joined.Count() == 0, string.Format("not null constraint was not created for the following properties: {0}" , string.Join(", ", joined.ToArray()))); } }
public void OverrideNames() { var db = new TestDb(); db.CreateTable <OverrideNamesClass> (); var cols = db.GetTableInfo("OverrideNamesClass"); Assert.AreEqual(3, cols.Count); Assert.IsTrue(cols.Exists(x => x.Name == "n")); Assert.IsTrue(cols.Exists(x => x.Name == "v")); var o = new OverrideNamesClass { Name = "Foo", Value = "Bar", }; db.Insert(o); var oo = db.Table <OverrideNamesClass> ().First(); Assert.AreEqual("Foo", oo.Name); Assert.AreEqual("Bar", oo.Value); }