Exemplo n.º 1
0
        public void TestColumnValues()
        {
            using (TestDb db = new TestDb())
            {
                db.CreateTable <WithDefaultValue>();


                string failed = string.Empty;
                foreach (var col in db.GetMapping <WithDefaultValue>().Columns)
                {
                    if (col.PropertyName == "TestInt" && !col.DefaultValue.Equals(WithDefaultValue.IntVal))
                    {
                        failed += " , TestInt does not equal " + WithDefaultValue.IntVal;
                    }


                    if (col.PropertyName == "TestDecimal" && !col.DefaultValue.Equals(WithDefaultValue.DecimalVal))
                    {
                        failed += "TestDecimal does not equal " + WithDefaultValue.DecimalVal;
                    }

                    if (col.PropertyName == "TestDateTime" && !col.DefaultValue.Equals(WithDefaultValue.DateTimegVal))
                    {
                        failed += "TestDateTime does not equal " + WithDefaultValue.DateTimegVal;
                    }

                    if (col.PropertyName == "TestString" && !col.DefaultValue.Equals(WithDefaultValue.StringVal))
                    {
                        failed += "TestString does not equal " + WithDefaultValue.StringVal;
                    }

                    if (col.PropertyName == "DefaultValueInAttributeTestInt" && !col.DefaultValue.Equals(WithDefaultValue.IntVal))
                    {
                        failed += " , DefaultValueInAttributeTestInt does not equal " + WithDefaultValue.IntVal;
                    }

                    if (col.PropertyName == "TestIntWithSubtypeOfDefault" && !col.DefaultValue.Equals(WithDefaultValue.IntVal))
                    {
                        failed += " , TestIntWithSubtypeOfDefault does not equal " + WithDefaultValue.IntVal;
                    }
                }

                Assert.True(string.IsNullOrWhiteSpace(failed), failed);
            }
        }
Exemplo n.º 2
0
        public void Query()
        {
            var db = new TestDb();

            db.CreateTable <UnicodeProduct>();

            string testString = "\u2329\u221E\u232A";

            db.Insert(new UnicodeProduct
            {
                Name = testString,
            });

            var ps = (from p in db.Table <UnicodeProduct>() where p.Name == testString select p).ToList();

            Assert.AreEqual(1, ps.Count);
            Assert.AreEqual(testString, ps[0].Name);
        }
Exemplo n.º 3
0
        public void CreateInsertDrop()
        {
            var db = new TestDb();

            db.CreateTable <Product>();

            db.Insert(new Product
            {
                Name  = "Hello",
                Price = 16,
            });

            int n = db.Table <Product>().Count();

            Assert.AreEqual(1, n);

            db.DropTable <Product>();

            Assert.Throws <SQLiteException>(() => db.Table <Product>().Count());
        }
Exemplo n.º 4
0
        public void Issue115_MissingPrimaryKey()
        {
            using (var conn = new TestDb())
            {
                conn.CreateTable <Issue115_MyObject>();
                conn.InsertAll(from i in Enumerable.Range(0, 10)
                               select new Issue115_MyObject
                {
                    UniqueId   = i.ToString(),
                    OtherValue = (byte)(i * 10),
                });

                TableQuery <Issue115_MyObject> query = conn.Table <Issue115_MyObject>();
                foreach (Issue115_MyObject itm in query)
                {
                    itm.OtherValue++;
                    Assert.AreEqual(1, conn.Update(itm, typeof(Issue115_MyObject)));
                }
            }
        }
Exemplo n.º 5
0
        private void TestDateTime(TestDb db)
        {
            db.CreateTable <TestObj>();

            //
            // Ticks
            //
            var org = new TestObj
            {
                Time1 = DateTime.UtcNow,
                Time2 = DateTime.Now,
            };

            db.Insert(org);
            var fromDb = db.Get <TestObj>(org.Id);

            Assert.AreEqual(fromDb.Time1.ToUniversalTime(), org.Time1.ToUniversalTime());
            Assert.AreEqual(fromDb.Time2.ToUniversalTime(), org.Time2.ToUniversalTime());

            Assert.AreEqual(fromDb.Time1.ToLocalTime(), org.Time1.ToLocalTime());
            Assert.AreEqual(fromDb.Time2.ToLocalTime(), org.Time2.ToLocalTime());
        }
Exemplo n.º 6
0
        public void SetUp()
        {
            db = new TestDb();
            db.CreateTable <Product>();

            var prods = new[]
            {
                new Product
                {
                    Name = "Foo"
                },
                new Product
                {
                    Name = "Bar"
                },
                new Product
                {
                    Name = "Foobar"
                }
            };

            db.InsertAll(prods);
        }
Exemplo n.º 7
0
        public void Issue303_WhereNot_B()
        {
            using (var db = new TestDb())
            {
                db.CreateTable <Issue303_B>();
                db.Insert(new Issue303_B {
                    Id = 1, Flag = true
                });
                db.Insert(new Issue303_B {
                    Id = 2, Flag = false
                });
                db.Insert(new Issue303_B {
                    Id = 3, Flag = true
                });
                db.Insert(new Issue303_B {
                    Id = 4, Flag = false
                });

                var r = (from p in db.Table <Issue303_B>() where !p.Flag select p).ToList();
                Assert.AreEqual(2, r.Count);
                Assert.AreEqual(2, r[0].Id);
                Assert.AreEqual(4, r[1].Id);
            }
        }
Exemplo n.º 8
0
        public void Issue303_WhereNot_A()
        {
            using (var db = new TestDb())
            {
                db.CreateTable <Issue303_A>();
                db.Insert(new Issue303_A {
                    Id = 1, Name = "aa"
                });
                db.Insert(new Issue303_A {
                    Id = 2, Name = null
                });
                db.Insert(new Issue303_A {
                    Id = 3, Name = "test"
                });
                db.Insert(new Issue303_A {
                    Id = 4, Name = null
                });

                var r = (from p in db.Table <Issue303_A>() where !(p.Name == null) select p).ToList();
                Assert.AreEqual(2, r.Count);
                Assert.AreEqual(1, r[0].Id);
                Assert.AreEqual(3, r[1].Id);
            }
        }
Exemplo n.º 9
0
 public void SetUp()
 {
     _db = new TestDb();
     _db.CreateTable <ComplexType>();
 }