Exemplo n.º 1
0
        public void ForeignKeyConstraintWhileInsertTest()
        {
            var ownerObj = new TestObjWithOne2Many {
                Id = 1, Text = "Test1"
            };
            var testObjects = Enumerable.Range(1, 10)
                              .Select(i => new TestDependentObj1 {
                Id = i, OwnerId = ownerObj.Id, Text = "Test" + i
            }).ToList();

            testObjects.Add(new TestDependentObj1 {
                Id = 11, OwnerId = 99
            });
            ownerObj.ObjList = testObjects;

            string exception = string.Empty;

            try{
                _db.Insert(ownerObj);
            }
            catch (SQLiteException ex) {
                exception = ex.Message;
            }

            Assert.AreNotEqual(string.Empty, exception);
            Assert.AreEqual("Constraint", exception);
        }
Exemplo n.º 2
0
        public void InsertOrReplaceWithOwnerIdAutogetting()
        {
            var ownerObj = new TestObjWithOne2Many {
                Text = "Test1"
            };
            var testObjects = Enumerable.Range(1, 10)
                              .Select(i => new TestDependentObj1 {
                Text = "Test" + i
            }).ToList();

            ownerObj.ObjList = testObjects;

            _db.InsertOrReplace(ownerObj);
            var tmpObject = _db.Table <TestObjWithOne2Many>().First();

            foreach (var o in tmpObject.ObjList)
            {
                o.Text += o.Id;
            }
            tmpObject.Text = "Test2";

            _db.InsertOrReplace(tmpObject);
            var resultObjs = _db.Table <TestObjWithOne2Many>().ToList();

            Assert.AreEqual(1, resultObjs.Count);
            Assert.AreEqual(tmpObject.ObjList[0].Text, resultObjs[0].ObjList[0].Text);
            Assert.AreNotEqual(ownerObj.ObjList[0].Text, resultObjs[0].ObjList[0].Text);
        }
Exemplo n.º 3
0
        public void InsertObjWithOwnerIdAutogetting()
        {
            var ownerObj    = new TestObjWithOne2Many();
            var testObjects = Enumerable.Range(1, 10)
                              .Select(i => new TestDependentObj1 {
                Text = "Test" + i
            }).ToList();

            ownerObj.ObjList = testObjects;

            _db.Insert(ownerObj);
            var resultObj = _db.Table <TestObjWithOne2Many>().First();

            Assert.AreNotEqual(null, resultObj);
            Assert.AreEqual(10, resultObj.ObjList.Count);
            Assert.AreEqual("Test1", resultObj.ObjList.First(x => x.Id == 1).Text);
        }
Exemplo n.º 4
0
		public void ForeignKeyConstraintWhileInsertTest()
		{
			var ownerObj = new TestObjWithOne2Many {Id = 1, Text = "Test1"};
			var testObjects = Enumerable.Range(1,10)
				.Select(i => new TestDependentObj1 {Id = i,OwnerId = ownerObj.Id, Text = "Test"+i}).ToList();
			testObjects.Add(new TestDependentObj1{Id = 11,OwnerId = 99});
			ownerObj.ObjList = testObjects;

			string exception = string.Empty;
			try{
				_db.Insert(ownerObj);
			}
			catch(SQLiteException ex){
				exception = ex.Message;
			}

			Assert.AreNotEqual(string.Empty,exception);
			Assert.AreEqual("Constraint", exception);
		}
Exemplo n.º 5
0
		public void InsertOrReplaceWithOwnerIdAutogetting()
		{
			var ownerObj = new TestObjWithOne2Many {Text = "Test1"};
			var testObjects = Enumerable.Range(1,10)
				.Select(i => new TestDependentObj1 {Text = "Test"+i}).ToList();
			ownerObj.ObjList = testObjects;

			_db.InsertOrReplace(ownerObj);
			var tmpObject = _db.Table<TestObjWithOne2Many>().First();
			foreach(var o in tmpObject.ObjList)
			{
				o.Text += o.Id;
			}
			tmpObject.Text = "Test2";

			_db.InsertOrReplace(tmpObject);
			var resultObjs = _db.Table<TestObjWithOne2Many>().ToList();

			Assert.AreEqual(1, resultObjs.Count);
			Assert.AreEqual(tmpObject.ObjList[0].Text, resultObjs[0].ObjList[0].Text);
			Assert.AreNotEqual(ownerObj.ObjList[0].Text, resultObjs[0].ObjList[0].Text);
		}
Exemplo n.º 6
0
		public void InsertObjWithOwnerIdAutogetting()
		{
			var ownerObj = new TestObjWithOne2Many ();
			var testObjects = Enumerable.Range(1,10)
				.Select(i => new TestDependentObj1 {Text = "Test"+i}).ToList();
			ownerObj.ObjList = testObjects;

			_db.Insert(ownerObj);
			var resultObj = _db.Table<TestObjWithOne2Many>().First();

			Assert.AreNotEqual(null,resultObj);
			Assert.AreEqual(10,resultObj.ObjList.Count);
			Assert.AreEqual("Test1",resultObj.ObjList.First(x => x.Id == 1).Text);			
		}