Beispiel #1
0
        public void ClearTableTest()
        {
            // setup
            var db = new OrmTestSession();

            db.CreateTable <Product>();

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

            // confirm
            Assert.AreEqual(2, db.Table <Product>().Count());
            db.Get <Product>(1);

            // clear
            Assert.AreEqual(2, db.ClearTable <Product>());

            // confirm
            Assert.AreEqual(0, db.Table <Product>().Count());

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

            // confirm that the Ids have not reset
            Assert.AreEqual(1, db.Table <Product>().Count());
            db.Get <Product>(3);
        }
        public void ClearTableTest()
        {
            // setup
            var db = new OrmTestSession();
            db.CreateTable<Product>();

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

            // confirm
            Assert.AreEqual(2, db.Table<Product>().Count());
            db.Get<Product>(1);

            // clear
            Assert.AreEqual(2, db.ClearTable<Product>());

            // confirm
            Assert.AreEqual(0, db.Table<Product>().Count());

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

            // confirm that the Ids have not reset
            Assert.AreEqual(1, db.Table<Product>().Count());
            db.Get<Product>(3);
        }
 public void CreateInstanceHookTestNonGeneric()
 {
     var db = new OrmTestSession();
     db.InstanceCreated += InstanceCreated;
     db.CreateTable<HookTestTable>();
     db.Insert(new HookTestTable { Text = InsertedTest });
     var got = db.Get(typeof(HookTestTable), 1);
     Assert.AreEqual(ReplacedText, ((HookTestTable)got).Text);
 }
 public void CreateInstanceHookTest()
 {
     var db = new OrmTestSession();
     db.InstanceCreated += InstanceCreated;
     db.CreateTable<HookTestTable>();
     db.Insert(new HookTestTable { Text = InsertedTest });
     var got = db.Get<HookTestTable>(1);
     Assert.AreEqual(ReplacedText, got.Text);
 }
        public void Insert()
        {
            var db = new OrmTestSession();
            db.CreateTable<Product>();

            db.Insert(new Product { Name = TestString, });

            var p = db.Get<Product>(1);

            Assert.AreEqual(TestString, p.Name);
        }
Beispiel #6
0
        public void GetWithExpressionFailsTest()
        {
            var db = new OrmTestSession();

            db.CreateTable <Product>();

            db.Insert(new Product {
                Name = "A", Price = 20
            });

            ExceptionAssert.Throws <InvalidOperationException>(() => db.Get <Product>(x => x.Name == "B"));
        }
        public void GetWithExpressionTest()
        {
            OrmTestSession db = CreateDb();

            db.Insert(new Product {
                Name = "A", Price = 20
            });

            var product = db.Get <Product>(x => x.Name == "A");

            Assert.AreEqual(20, product.Price);
        }
        public void ColumnsSaveLoadMinCorrectly()
        {
            var db = new OrmTestSession();

            db.CreateTable <Test>();

            var test = new Test
            {
                Id        = 0,
                Int32     = Int32.MinValue,
                String    = "A unicode string \u2022 <- bullet point",
                Byte      = Byte.MinValue,
                UInt16    = UInt16.MinValue,
                SByte     = SByte.MinValue,
                Int16     = Int16.MinValue,
                Boolean   = false,
                UInt32    = UInt32.MinValue,
                Int64     = Int64.MinValue,
                Single    = Single.MinValue,
                Double    = Double.MinValue,
                Decimal   = -79228162514264300000000000000M,
                Enum1     = EEnum.EnumVal1,
                Enum2     = EEnum.EnumVal2,
                Timestamp = DateTime.Parse("2012-04-05 15:08:24.723"),
                Blob      = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
                Guid      = Guid.NewGuid(),
                TimeSpan  = TimeSpan.MinValue
            };

            db.Insert(test);
            var res = db.Get <Test>(test.Id);

            Assert.AreEqual(test.Id, res.Id);
            Assert.AreEqual(test.Int32, res.Int32);
            Assert.AreEqual(test.String, res.String);
            Assert.AreEqual(test.Byte, res.Byte);
            Assert.AreEqual(test.UInt16, res.UInt16);
            Assert.AreEqual(test.SByte, res.SByte);
            Assert.AreEqual(test.Int16, res.Int16);
            Assert.AreEqual(test.Boolean, res.Boolean);
            Assert.AreEqual(test.UInt32, res.UInt32);
            Assert.AreEqual(test.Int64, res.Int64);
            Assert.AreEqual(test.Single, res.Single);
            Assert.AreEqual(test.Double, res.Double);
            Assert.AreEqual(test.Decimal, res.Decimal);
            Assert.AreEqual(test.Enum1, res.Enum1);
            Assert.AreEqual(test.Enum2, res.Enum2);
            Assert.AreEqual(test.Timestamp, res.Timestamp);
            ArrayAssert.AreEqual(test.Blob, res.Blob);
            Assert.AreEqual(test.Guid, res.Guid);
            Assert.AreEqual(test.TimeSpan, res.TimeSpan);
        }
        public void ColumnsSaveLoadRandomValuesCorrectly()
        {
            var db = new OrmTestSession();

            db.CreateTable <Test>();

            var test = new Test
            {
                Id        = 0,
                Int32     = 0x1337beef,
                String    = "A unicode string \u2022 <- bullet point",
                Byte      = 0xEA,
                UInt16    = 65535,
                SByte     = -128,
                Int16     = -32768,
                Boolean   = false,
                UInt32    = 0xdead,
                Int64     = 0x123456789abcdef,
                Single    = 6.283185f,
                Double    = 6.283185307179586476925286766559,
                Decimal   = (decimal)6.283185307179586476925286766559,
                Enum1     = EEnum.EnumVal1,
                Enum2     = EEnum.EnumVal2,
                Timestamp = DateTime.Parse("2012-04-05 15:08:24.723"),
                Blob      = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
                Guid      = Guid.NewGuid(),
                TimeSpan  = TimeSpan.FromMinutes(7)
            };

            db.Insert(test);
            var res = db.Get <Test>(test.Id);

            Assert.AreEqual(test.Id, res.Id);
            Assert.AreEqual(test.Int32, res.Int32);
            Assert.AreEqual(test.String, res.String);
            Assert.AreEqual(test.Byte, res.Byte);
            Assert.AreEqual(test.UInt16, res.UInt16);
            Assert.AreEqual(test.SByte, res.SByte);
            Assert.AreEqual(test.Int16, res.Int16);
            Assert.AreEqual(test.Boolean, res.Boolean);
            Assert.AreEqual(test.UInt32, res.UInt32);
            Assert.AreEqual(test.Int64, res.Int64);
            Assert.AreEqual(test.Single, res.Single);
            Assert.AreEqual(test.Double, res.Double);
            Assert.AreEqual(test.Decimal, res.Decimal);
            Assert.AreEqual(test.Enum1, res.Enum1);
            Assert.AreEqual(test.Enum2, res.Enum2);
            Assert.AreEqual(test.Timestamp, res.Timestamp);
            ArrayAssert.AreEqual(test.Blob, res.Blob);
            Assert.AreEqual(test.Guid, res.Guid);
            Assert.AreEqual(test.TimeSpan, res.TimeSpan);
        }
        public void ColumnsSaveLoadZerosCorrectly()
        {
            var db = new OrmTestSession();

            db.CreateTable <Test>();

            var test = new Test
            {
                Id        = 0,
                Int32     = 0,
                String    = "A unicode string \u2022 <- bullet point",
                Byte      = 0,
                UInt16    = 0,
                SByte     = 0,
                Int16     = 0,
                Boolean   = false,
                UInt32    = 0,
                Int64     = 0,
                Single    = Single.Epsilon,
                Double    = Double.Epsilon,
                Decimal   = Decimal.Zero,
                Enum1     = EEnum.EnumVal1,
                Enum2     = EEnum.EnumVal2,
                Timestamp = DateTime.Parse("0001-01-01 00:00:00.000"),
                Blob      = new byte[] { 0 },
                Guid      = Guid.NewGuid(),
                TimeSpan  = TimeSpan.Zero
            };

            db.Insert(test);
            var res = db.Get <Test>(test.Id);

            Assert.AreEqual(test.Id, res.Id);
            Assert.AreEqual(test.Int32, res.Int32);
            Assert.AreEqual(test.String, res.String);
            Assert.AreEqual(test.Byte, res.Byte);
            Assert.AreEqual(test.UInt16, res.UInt16);
            Assert.AreEqual(test.SByte, res.SByte);
            Assert.AreEqual(test.Int16, res.Int16);
            Assert.AreEqual(test.Boolean, res.Boolean);
            Assert.AreEqual(test.UInt32, res.UInt32);
            Assert.AreEqual(test.Int64, res.Int64);
            Assert.AreEqual(test.Single, res.Single);
            Assert.AreEqual(test.Double, res.Double);
            Assert.AreEqual(test.Decimal, res.Decimal);
            Assert.AreEqual(test.Enum1, res.Enum1);
            Assert.AreEqual(test.Enum2, res.Enum2);
            Assert.AreEqual(test.Timestamp, res.Timestamp);
            ArrayAssert.AreEqual(test.Blob, res.Blob);
            Assert.AreEqual(test.Guid, res.Guid);
            Assert.AreEqual(test.TimeSpan, res.TimeSpan);
        }
        public void CreateInstanceHookTestNonGeneric()
        {
            var db = new OrmTestSession();

            db.InstanceCreated += InstanceCreated;
            db.CreateTable <HookTestTable>();
            db.Insert(new HookTestTable {
                Text = InsertedTest
            });
            var got = db.Get(typeof(HookTestTable), 1);

            Assert.AreEqual(ReplacedText, ((HookTestTable)got).Text);
        }
        public void CreateInstanceHookTest()
        {
            var db = new OrmTestSession();

            db.InstanceCreated += InstanceCreated;
            db.CreateTable <HookTestTable>();
            db.Insert(new HookTestTable {
                Text = InsertedTest
            });
            var got = db.Get <HookTestTable>(1);

            Assert.AreEqual(ReplacedText, got.Text);
        }
Beispiel #13
0
        public void DataConverterInsertTest()
        {
            var db = new OrmTestSession();

            db.CreateTable <TestConverter>();

            db.Insert(new TestConverter {
                Color = Color.FromArgb(255, 255, 0, 0)
            });

            var plain = db.Get <TestPlain>(1);

            Assert.AreEqual("255/255/0/0", plain.Color);
        }
Beispiel #14
0
        public void DataConverterSelectTest()
        {
            var db = new OrmTestSession();

            db.CreateTable <TestConverter>();

            db.Insert(new TestPlain {
                Color = "255/0/255/0"
            });

            var withC = db.Get <TestConverter>(1);

            Assert.AreEqual(Color.FromArgb(255, 0, 255, 0), withC.Color);
        }
Beispiel #15
0
        public void Insert()
        {
            var db = new OrmTestSession();

            db.CreateTable <Product>();

            db.Insert(new Product {
                Name = TestString,
            });

            var p = db.Get <Product>(1);

            Assert.AreEqual(TestString, p.Name);
        }
        public void ColumnsSaveLoadMaxCorrectly()
        {
            var db = new OrmTestSession();
            db.CreateTable<Test>();

            var test = new Test
                           {
                               Id = 0,
                               Int32 = Int32.MaxValue,
                               String = "A unicode string \u2022 <- bullet point",
                               Byte = Byte.MaxValue,
                               UInt16 = UInt16.MaxValue,
                               SByte = SByte.MaxValue,
                               Int16 = Int16.MaxValue,
                               Boolean = true,
                               UInt32 = UInt32.MaxValue,
                               Int64 = Int64.MaxValue,
                               Single = Single.MaxValue,
                               Double = Double.MaxValue,
                               Decimal = 79228162514264300000000000000M,
                               Enum1 = EEnum.EnumVal1,
                               Enum2 = EEnum.EnumVal2,
                               Timestamp = DateTime.Parse("2012-04-05 15:08:24.723"),
                               Blob = new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
                               Guid = Guid.NewGuid()
                           };

            db.Insert(test);
            var res = db.Get<Test>(test.Id);

            Assert.AreEqual(test.Id, res.Id);
            Assert.AreEqual(test.Int32, res.Int32);
            Assert.AreEqual(test.String, res.String);
            Assert.AreEqual(test.Byte, res.Byte);
            Assert.AreEqual(test.UInt16, res.UInt16);
            Assert.AreEqual(test.SByte, res.SByte);
            Assert.AreEqual(test.Int16, res.Int16);
            Assert.AreEqual(test.Boolean, res.Boolean);
            Assert.AreEqual(test.UInt32, res.UInt32);
            Assert.AreEqual(test.Int64, res.Int64);
            Assert.AreEqual(test.Single, res.Single);
            Assert.AreEqual(test.Double, res.Double);
            Assert.AreEqual(test.Decimal, res.Decimal);
            Assert.AreEqual(test.Enum1, res.Enum1);
            Assert.AreEqual(test.Enum2, res.Enum2);
            Assert.AreEqual(test.Timestamp, res.Timestamp);
            ArrayAssert.AreEqual(test.Blob, res.Blob);
            Assert.AreEqual(test.Guid, res.Guid);
        }
Beispiel #17
0
        public void EnumDataConverterTest()
        {
            var db = new OrmTestSession();

            db.CreateTable <EnumTestTable>();

            db.Insert(new EnumTestTable {
                EnumColumn = MyEnum.Second
            });
            db.Insert(new EnumTestTable {
                EnumColumn = null
            });

            var plain = db.Get <EnumTestTablePlain>(1);

            Assert.AreEqual("2", plain.EnumColumn);

            plain = db.Get <EnumTestTablePlain>(2);
            Assert.IsNull(plain.EnumColumn);

            var rich = db.Get <EnumTestTable>(1);

            Assert.AreEqual(MyEnum.Second, rich.EnumColumn);

            rich = db.Get <EnumTestTable>(2);
            Assert.IsNull(rich.EnumColumn);

            db.Insert(new EnumTestTablePlain {
                EnumColumn = "2"
            });
            db.Insert(new EnumTestTablePlain {
                EnumColumn = null
            });

            plain = db.Get <EnumTestTablePlain>(3);
            Assert.AreEqual("2", plain.EnumColumn);

            plain = db.Get <EnumTestTablePlain>(4);
            Assert.IsNull(plain.EnumColumn);

            rich = db.Get <EnumTestTable>(3);
            Assert.AreEqual(MyEnum.Second, rich.EnumColumn);

            rich = db.Get <EnumTestTable>(4);
            Assert.IsNull(rich.EnumColumn);
        }
Beispiel #18
0
        public void DefaultsTest()
        {
            var db = new OrmTestSession();

            db.CreateTable <DefaultsObject>();

            int numIn = db.InsertDefaults <DefaultsObject>();

            Assert.AreEqual(numIn, 1, "Num inserted must = 1");

            var inObjs = db.Get <DefaultsObject>(1);

            Assert.AreEqual("Default Text", inObjs.Text);
            Assert.AreEqual(33, inObjs.Number);
        }
        public void GetWithExpressionFailsTest()
        {
            OrmTestSession db = CreateDb();

            db.Insert(new Product {
                Name = "A", Price = 20
            });
            try
            {
                var product = db.Get <Product>(x => x.Name == "B");

                Assert.Fail();
            }
            catch (InvalidOperationException)
            {
            }
        }
        public void DataConverterSelectTest()
        {
            var db = new OrmTestSession();
            db.CreateTable<TestConverter>();

            db.Insert(new TestPlain { Color = "255/0/255/0" });

            var withC = db.Get<TestConverter>(1);

            Assert.AreEqual(Color.FromArgb(255, 0, 255, 0), withC.Color);
        }
        public void ColumnsSaveLoadRandomValuesCorrectly()
        {
            var db = new OrmTestSession();
            db.CreateTable<Test>();

            var test = new Test
            {
                Id = 0,
                Int32 = 0x1337beef,
                String = "A unicode string \u2022 <- bullet point",
                Byte = 0xEA,
                UInt16 = 65535,
                SByte = -128,
                Int16 = -32768,
                Boolean = false,
                UInt32 = 0xdeadbeef,
                Int64 = 0x123456789abcdef,
                Single = 6.283185f,
                Double = 6.283185307179586476925286766559,
                Decimal = (decimal)6.283185307179586476925286766559,
                Enum1 = EEnum.EnumVal1,
                Enum2 = EEnum.EnumVal2,
                Timestamp = DateTime.Parse("2012-04-05 15:08:24.723"),
                Blob = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
                Guid = Guid.NewGuid()
            };

            db.Insert(test);
            var res = db.Get<Test>(test.Id);

            Assert.AreEqual(test.Id, res.Id);
            Assert.AreEqual(test.Int32, res.Int32);
            Assert.AreEqual(test.String, res.String);
            Assert.AreEqual(test.Byte, res.Byte);
            Assert.AreEqual(test.UInt16, res.UInt16);
            Assert.AreEqual(test.SByte, res.SByte);
            Assert.AreEqual(test.Int16, res.Int16);
            Assert.AreEqual(test.Boolean, res.Boolean);
            Assert.AreEqual(test.UInt32, res.UInt32);
            Assert.AreEqual(test.Int64, res.Int64);
            Assert.AreEqual(test.Single, res.Single);
            Assert.AreEqual(test.Double, res.Double);
            Assert.AreEqual(test.Decimal, res.Decimal);
            Assert.AreEqual(test.Enum1, res.Enum1);
            Assert.AreEqual(test.Enum2, res.Enum2);
            Assert.AreEqual(test.Timestamp, res.Timestamp);
            ArrayAssert.AreEqual(test.Blob, res.Blob);
            Assert.AreEqual(test.Guid, res.Guid);
        }
        public void ColumnsSaveLoadZerosCorrectly()
        {
            var db = new OrmTestSession();
            db.CreateTable<Test>();

            var test = new Test
            {
                Id = 0,
                Int32 = 0,
                String = "A unicode string \u2022 <- bullet point",
                Byte = 0,
                UInt16 = 0,
                SByte = 0,
                Int16 = 0,
                Boolean = false,
                UInt32 = 0,
                Int64 = 0,
                Single = Single.Epsilon,
                Double = Double.Epsilon,
                Decimal = Decimal.Zero,
                Enum1 = EEnum.EnumVal1,
                Enum2 = EEnum.EnumVal2,
                Timestamp = DateTime.Parse("0001-01-01 00:00:00.000"),
                Blob = new byte[] { 0 },
                Guid = Guid.NewGuid()
            };

            db.Insert(test);
            var res = db.Get<Test>(test.Id);

            Assert.AreEqual(test.Id, res.Id);
            Assert.AreEqual(test.Int32, res.Int32);
            Assert.AreEqual(test.String, res.String);
            Assert.AreEqual(test.Byte, res.Byte);
            Assert.AreEqual(test.UInt16, res.UInt16);
            Assert.AreEqual(test.SByte, res.SByte);
            Assert.AreEqual(test.Int16, res.Int16);
            Assert.AreEqual(test.Boolean, res.Boolean);
            Assert.AreEqual(test.UInt32, res.UInt32);
            Assert.AreEqual(test.Int64, res.Int64);
            Assert.AreEqual(test.Single, res.Single);
            Assert.AreEqual(test.Double, res.Double);
            Assert.AreEqual(test.Decimal, res.Decimal);
            Assert.AreEqual(test.Enum1, res.Enum1);
            Assert.AreEqual(test.Enum2, res.Enum2);
            Assert.AreEqual(test.Timestamp, res.Timestamp);
            ArrayAssert.AreEqual(test.Blob, res.Blob);
            Assert.AreEqual(test.Guid, res.Guid);
        }
        public void MultiplePkOperations()
		{
			var db = new OrmTestSession();
			db.CreateTable<TestObj>();
			
			// insert
			const int n = 10 , m= 5;
			var objs = new TestObj[n * m];
			for (int j = 0; j != n; ++j)
			{
				for (int i = 0; i != m; ++i)
				{
					objs[j * m + i] = new TestObj {Id = j, SubId = i, Text = "I am (" + j + "," + i + ")"};
				}
			}

			int numIn = db.InsertAll(objs);

			Assert.AreEqual(numIn, n * m, "Num inserted must = num objects");

			var obj = db.Get<TestObj>(5, 3);
			Assert.AreEqual(5, obj.Id);
			Assert.AreEqual(3, obj.SubId);
			Assert.AreEqual("I am (5,3)", obj.Text);
			
			try
			{
				db.Insert(obj);
			}
			catch (SqliteException ex)
			{
                Assert.AreEqual(SQLiteErrorCode.Constraint, ex.ErrorCode);
			}

			// update
			obj.Text = "I've been changed";
			db.Update(obj);
			db.Update<TestObj>("Text", "I've been changed also", 8, 2);

			obj = db.Get<TestObj>(5, 3);
			Assert.AreEqual("I've been changed", obj.Text);

			obj = db.Get<TestObj>(8, 2);
			Assert.AreEqual("I've been changed also", obj.Text);

			db.UpdateAll<TestObj>("Text", "All changed");
			IEnumerable<TestObj> q1 = from o in db.Table<TestObj>() select o;
			foreach (TestObj o in q1)
				Assert.AreEqual("All changed", o.Text);

			TestObj[] q2 = (from o in db.Table<TestObj>() where o.SubId == 3 select o).ToArray();
			Assert.AreEqual(10, q2.Length);
			for (int i = 0; i != 10; ++i)
			{
				Assert.AreEqual(i, q2[i].Id);
			}

            object numCount = db.Table<TestObj>().Count();
			Assert.AreEqual(numCount, objs.Length, "Num counted must = num objects");

			// delete
			obj = db.Get<TestObj>(8, 2);
			db.Delete(obj);
			
			try
			{
				var item = db.Get<TestObj>(8, 2);

				Assert.Fail();
			}
			catch (InvalidOperationException)
			{
			}
			catch (Exception ex)
			{
				Assert.Fail(ex.Message);
			}

            db.Execute("delete from TestObj where SubId=2");
            numCount = db.ExecuteScalar<int>("select count(*) from TestObj");
			Assert.AreEqual(numCount, objs.Length - 10);
			foreach (TestObj o in (from o in db.Table<TestObj>() select o))
				Assert.AreNotEqual(2, o.SubId);
		}
Beispiel #24
0
        public void MultiplePkOperations()
        {
            var db = new OrmTestSession();

            db.CreateTable <TestObj>();

            // insert
            const int n = 10, m = 5;
            var       objs = new TestObj[n * m];

            for (int j = 0; j != n; ++j)
            {
                for (int i = 0; i != m; ++i)
                {
                    objs[j * m + i] = new TestObj {
                        Id = j, SubId = i, Text = "I am (" + j + "," + i + ")"
                    };
                }
            }

            int numIn = db.InsertAll(objs);

            Assert.AreEqual(numIn, n * m, "Num inserted must = num objects");

            var obj = db.Get <TestObj>(5, 3);

            Assert.AreEqual(5, obj.Id);
            Assert.AreEqual(3, obj.SubId);
            Assert.AreEqual("I am (5,3)", obj.Text);

            try
            {
                db.Insert(obj);
            }
            catch (SqliteException ex)
            {
                Assert.AreEqual(SQLiteErrorCode.Constraint, ex.ErrorCode);
            }

            // update
            obj.Text = "I've been changed";
            db.Update(obj);
            db.Update <TestObj>("Text", "I've been changed also", 8, 2);

            obj = db.Get <TestObj>(5, 3);
            Assert.AreEqual("I've been changed", obj.Text);

            obj = db.Get <TestObj>(8, 2);
            Assert.AreEqual("I've been changed also", obj.Text);

            db.UpdateAll <TestObj>("Text", "All changed");
            IEnumerable <TestObj> q1 = from o in db.Table <TestObj>() select o;

            foreach (TestObj o in q1)
            {
                Assert.AreEqual("All changed", o.Text);
            }

            TestObj[] q2 = (from o in db.Table <TestObj>() where o.SubId == 3 select o).ToArray();
            Assert.AreEqual(10, q2.Length);
            for (int i = 0; i != 10; ++i)
            {
                Assert.AreEqual(i, q2[i].Id);
            }

            object numCount = db.Table <TestObj>().Count();

            Assert.AreEqual(numCount, objs.Length, "Num counted must = num objects");

            // delete
            obj = db.Get <TestObj>(8, 2);
            db.Delete(obj);

            ExceptionAssert.Throws <InvalidOperationException>(() => db.Get <TestObj>(8, 2));

            db.Execute("delete from TestObj where SubId=2");
            numCount = db.ExecuteScalar <int>("select count(*) from TestObj");
            Assert.AreEqual(numCount, objs.Length - 10);
            foreach (TestObj o in (from o in db.Table <TestObj>() select o))
            {
                Assert.AreNotEqual(2, o.SubId);
            }
        }
        public void DefaultsTest()
        {
            var db = new OrmTestSession();
            db.CreateTable<DefaultsObject>();

            int numIn = db.InsertDefaults<DefaultsObject>();

            Assert.AreEqual(numIn, 1, "Num inserted must = 1");

            var inObjs = db.Get<DefaultsObject>(1);

            Assert.AreEqual("Default Text", inObjs.Text);
            Assert.AreEqual(33, inObjs.Number);
        }
        public void EnumDataConverterTest()
        {
            var db = new OrmTestSession();
            db.CreateTable<EnumTestTable>();

            db.Insert(new EnumTestTable { EnumColumn = MyEnum.Second });
            db.Insert(new EnumTestTable { EnumColumn = null });

            var plain = db.Get<EnumTestTablePlain>(1);
            Assert.AreEqual("2", plain.EnumColumn);

            plain = db.Get<EnumTestTablePlain>(2);
            Assert.IsNull(plain.EnumColumn);

            var rich = db.Get<EnumTestTable>(1);
            Assert.AreEqual(MyEnum.Second, rich.EnumColumn);

            rich = db.Get<EnumTestTable>(2);
            Assert.IsNull(rich.EnumColumn);

            db.Insert(new EnumTestTablePlain { EnumColumn = "2" });
            db.Insert(new EnumTestTablePlain { EnumColumn = null });

            plain = db.Get<EnumTestTablePlain>(3);
            Assert.AreEqual("2", plain.EnumColumn);

            plain = db.Get<EnumTestTablePlain>(4);
            Assert.IsNull(plain.EnumColumn);

            rich = db.Get<EnumTestTable>(3);
            Assert.AreEqual(MyEnum.Second, rich.EnumColumn);

            rich = db.Get<EnumTestTable>(4);
            Assert.IsNull(rich.EnumColumn);
        }
        public void DataConverterInsertTest()
        {
            var db = new OrmTestSession();
            db.CreateTable<TestConverter>();

            db.Insert(new TestConverter { Color = Color.FromArgb(255, 255, 0, 0) });

            var plain = db.Get<TestPlain>(1);

            Assert.AreEqual("255/255/0/0", plain.Color);
        }