コード例 #1
0
        public void InsertIntoTwoTables()
        {
            var obj1 = new TestObj
            {
                Text = "GLaDOS loves testing!"
            };
            var obj2 = new TestObj2
            {
                Text = "Keep testing, just keep testing"
            };

            int numIn1 = _db.Insert(obj1);

            Assert.AreEqual(1, numIn1);
            int numIn2 = _db.Insert(obj2);

            Assert.AreEqual(1, numIn2);

            List <TestObj> result1 = _db.Query <TestObj>("select * from TestObj").ToList();

            Assert.AreEqual(numIn1, result1.Count);
            Assert.AreEqual(obj1.Text, result1.First().Text);

            List <TestObj> result2 = _db.Query <TestObj>("select * from TestObj2").ToList();

            Assert.AreEqual(numIn2, result2.Count);
        }
コード例 #2
0
        public void ShouldPersistAndReadGuid()
        {
            var db = new TestDb(TestPath.CreateTemporaryDatabase());

            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"
            };

            int numIn1 = db.Insert(obj1);
            int numIn2 = db.Insert(obj2);

            Assert.AreEqual(1, numIn1);
            Assert.AreEqual(1, numIn2);

            List <TestObj> 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();
        }
コード例 #3
0
 public void CreateUniqueIndexes()
 {
     using (var db = new TestDb())
     {
         db.CreateTable <TheOne>();
         List <IndexInfo> 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");
     }
 }
コード例 #4
0
        private static void CheckIndex(TestDb db, List <IndexInfo> indexes, string iname, bool unique,
                                       params string[] columns)
        {
            if (columns == null)
            {
                throw new Exception("Don't!");
            }
            IndexInfo 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));
            List <IndexColumns> 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 (string col in columns)
            {
                Assert.IsNotNull(idx_columns.SingleOrDefault(c => c.name == col),
                                 String.Format("Column {0} not in index {1}", col, idx.name));
            }
        }