public void ShouldPersistAndReadGuid() { var db = new TestDb(TestPath.GetTempFileName()); var obj1 = new TestObj() { Id = new Guid("36473164-C9E4-4CDF-B266-A0B287C85623"), Text = "First Guid Object" }; var obj2 = new TestObj() { Id = new Guid("BC5C4C4A-CA57-4B61-8B53-9FD4673528B6"), Text = "Second Guid Object" }; var numIn1 = db.Insert(obj1); var numIn2 = db.Insert(obj2); Assert.AreEqual(1, numIn1); Assert.AreEqual(1, numIn2); var result = db.Query <TestObj>("select * from TestObj").ToList(); Assert.AreEqual(2, result.Count); Assert.AreEqual(obj1.Text, result[0].Text); Assert.AreEqual(obj2.Text, result[1].Text); Assert.AreEqual(obj1.Id, result[0].Id); Assert.AreEqual(obj2.Id, result[1].Id); db.Close(); }
public void ShouldPersistAndReadEnum() { var db = new TestDb(TestPath.GetTempFileName()); var obj1 = new TestObj() { Id = 1, Value = TestEnum.Value2 }; var obj2 = new TestObj() { Id = 2, Value = TestEnum.Value3 }; var numIn1 = db.Insert(obj1); var numIn2 = db.Insert(obj2); Assert.AreEqual(1, numIn1); Assert.AreEqual(1, numIn2); var result = db.Query <TestObj>("select * from TestObj").ToList(); Assert.AreEqual(2, result.Count); Assert.AreEqual(obj1.Value, result[0].Value); Assert.AreEqual(obj2.Value, result[1].Value); Assert.AreEqual(obj1.Id, result[0].Id); Assert.AreEqual(obj2.Id, result[1].Id); db.Close(); }
public void CreateUniqueIndexes() { using (var db = new TestDb()) { db.CreateTable <TheOne> (); var indexes = db.Query <IndexInfo> ("PRAGMA INDEX_LIST (\"TheOne\")"); Assert.AreEqual(4, indexes.Count, "# of indexes"); CheckIndex(db, indexes, "UX_Uno", true, "Uno"); CheckIndex(db, indexes, "UX_Dos", true, "Dos", "Tres"); CheckIndex(db, indexes, "UX_Uno_bool", true, "Cuatro"); CheckIndex(db, indexes, "UX_Dos_bool", true, "Cinco", "Seis"); } }
public void InsertTwoTimes() { var obj1 = new TestObj() { Text = "GLaDOS loves testing!" }; var obj2 = new TestObj() { Text = "Keep testing, just keep testing" }; var numIn1 = _db.Insert(obj1); var numIn2 = _db.Insert(obj2); Assert.AreEqual(1, numIn1); Assert.AreEqual(1, numIn2); var result = _db.Query <TestObj>("select * from TestObj").ToList(); Assert.AreEqual(2, result.Count); Assert.AreEqual(obj1.Text, result[0].Text); Assert.AreEqual(obj2.Text, result[1].Text); }
static void CheckIndex(TestDb db, List <IndexInfo> indexes, string iname, bool unique, params string [] columns) { if (columns == null) { throw new Exception("Don't!"); } var idx = indexes.SingleOrDefault(i => i.name == iname); Assert.IsNotNull(idx, String.Format("Index {0} not found", iname)); Assert.AreEqual(idx.unique, unique, String.Format("Index {0} unique expected {1} but got {2}", iname, unique, idx.unique)); var idx_columns = db.Query <IndexColumns> (String.Format("PRAGMA INDEX_INFO (\"{0}\")", iname)); Assert.AreEqual(columns.Length, idx_columns.Count, String.Format("# of columns: expected {0}, got {1}", columns.Length, idx_columns.Count)); foreach (var col in columns) { Assert.IsNotNull(idx_columns.SingleOrDefault(c => c.name == col), String.Format("Column {0} not in index {1}", col, idx.name)); } }