Example #1
0
		public void TestTableAutoIncrement()
		{
			// Prepare and Cleanup
			Database.RegisterDataObject(typeof(TestTableAutoInc));
			
			var all = Database.SelectAllObjects<TestTableAutoInc>();
			
			foreach(var obj in all)
				Database.DeleteObject(obj);
			
			var none = Database.SelectAllObjects<TestTableAutoInc>();
			
			Assert.IsEmpty(none, "Database shouldn't have any record For TestTableAutoInc.");
			
			var addObj = new TestTableAutoInc() { TestField = "Test AutoInc" };
			
			// Insert a Test Object for guessing last auto increment
			var inserted = Database.AddObject(addObj);
			
			Assert.IsTrue(inserted, "Test Table Auto Inc could not insert a new Entry.");
			
			var autoInc = addObj.PrimaryKey;
			
			Assert.AreNotEqual(autoInc, default(int), "Test Table Auto Inc Primary should not be Default value after insertion.");
			
			// Add Another Object to Check Primary Key Increment
			var otherObj = new TestTableAutoInc() { TestField = "Test AutoInc Other" };
			
			var otherInsert = Database.AddObject(otherObj);
			
			Assert.IsTrue(otherInsert, "Test Table Auto Inc could not insert an other Entry.");
			
			var otherAutoInc = otherObj.PrimaryKey;
			Assert.Greater(otherAutoInc, autoInc, "Newly Inserted Test Table Auto Inc Other Entry should have a Greater Primary Key Increment.");
			
			// Try Deleting and Re-inserting
			var reDeleted = Database.DeleteObject(otherObj);
			Assert.IsTrue(reDeleted, "Test Table Auto Inc could not delete other Entry from Table.");
			Assert.IsTrue(otherObj.IsDeleted, "Test Table Auto Inc other Entry deleted Flag should be true.");
			Assert.IsFalse(otherObj.IsPersisted, "Test Table Auto Inc other Entry Persisted Flag should be false.");
			
			otherObj.PrimaryKey = default(int);
			var reInserted = Database.AddObject(otherObj);
			Assert.IsTrue(reInserted, "Test Table Auto Inc could not insert other Entry in Table again.");
			
			Assert.Greater(otherObj.PrimaryKey, otherAutoInc, "Re-Added Test Table Auto Inc Entry should have a Greater Primary Key Increment.");
			
			// Try modifying to check that Primary Key is Used for Update Where Clause
			otherObj.TestField = "Test AutoInc Other Modified !";
			Assert.IsTrue(otherObj.Dirty, "Test Table Auto Inc Other Object should be Dirty after Modifications.");
			var modified = Database.SaveObject(otherObj);
			Assert.IsTrue(modified, "Test Table Auto Inc Other Object could not be Modified.");
			Assert.IsFalse(otherObj.Dirty, "Test Table Auto Inc Other Object should not be Dirty after save.");
			
			var retrieve = Database.FindObjectByKey<TestTableAutoInc>(otherObj.PrimaryKey);
			Assert.IsNotNull(retrieve, "Test Table Auto Inc Other Object could not be Retrieved through Primary Key.");
			Assert.AreEqual(otherObj.TestField, retrieve.TestField, "Test Table Auto Inc Retrieved Object is different from Other Object.");
		}
Example #2
0
		public void TestSingleFindObjectByKeyPrimaryKeyAutoInc()
		{
			Database.RegisterDataObject(typeof(TestTableAutoInc));
			
			var obj = new TestTableAutoInc { TestField = "Test For Single Find Object By Primary Key Auto Inc" };
			
			var inserted = Database.AddObject(obj);
			
			Assert.IsTrue(inserted, "Find Object By Key Test Could not add object in database...");
			
			var retrieve = Database.FindObjectByKey<TestTableAutoInc>(obj.PrimaryKey);
			
			Assert.IsNotNull(retrieve, "Find Object By Key Could not retrieve previously added Object...");
			Assert.AreEqual(obj.PrimaryKey, retrieve.PrimaryKey, "Find Object By Key Should return similar Object to created one...");
			Assert.AreEqual(obj.TestField, retrieve.TestField, "Find Object By Key Should return similar Object to created one...");
			
			var retrieveCast = Database.FindObjectByKey<TestTableAutoInc>((long)obj.PrimaryKey);
			
			Assert.IsNotNull(retrieveCast, "Find Object By Key Could not retrieve previously added Object using Numeric Cast...");
			Assert.AreEqual(obj.PrimaryKey, retrieveCast.PrimaryKey, "Find Object By Key Should return similar Object to created one...");
			Assert.AreEqual(obj.TestField, retrieveCast.TestField, "Find Object By Key Should return similar Object to created one...");
			
			var retrieveString = Database.FindObjectByKey<TestTableAutoInc>(obj.PrimaryKey.ToString());
			
			Assert.IsNotNull(retrieveString, "Find Object By Key Could not retrieve previously added Object using String Cast...");
			Assert.AreEqual(obj.PrimaryKey, retrieveString.PrimaryKey, "Find Object By Key Should return similar Object to created one...");
			Assert.AreEqual(obj.TestField, retrieveString.TestField, "Find Object By Key Should return similar Object to created one...");
		}