diff UnitTests/CS/DataAccess/PrimaryKeyAttributeTest.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/UnitTests/CS/DataAccess/PrimaryKeyAttributeTest.cs	Thu Mar 27 21:46:09 2014 +0400
@@ -0,0 +1,110 @@
+using System;
+
+using NUnit.Framework;
+
+using BLToolkit.Data;
+using BLToolkit.DataAccess;
+using BLToolkit.Mapping;
+
+namespace DataAccess
+{
+	[TestFixture]
+	public class PrimaryKeyAttributeTest : SqlQuery
+	{
+		public class Base
+		{
+			[PrimaryKey]
+			public int ID;
+		}
+
+		public class Derived : Base
+		{
+			public new int ID
+			{
+				get { return base.ID;  }
+				set { base.ID = value; }
+			}
+		}
+
+
+		[Test]
+		public void PrimaryKeyOverrideTest()
+		{
+			using (DbManager db = new DbManager())
+			{
+				MemberMapper[] personPrimaryKeys = GetKeyFieldList(db, typeof (Base));
+				Assert.IsNotNull(personPrimaryKeys);
+				Assert.AreEqual(1, personPrimaryKeys.Length);
+				Assert.AreEqual("ID", personPrimaryKeys[0].MemberName);
+
+				MemberMapper[] derivedPrimaryKeys = GetKeyFieldList(db, typeof (Derived));
+				Assert.IsNotNull(derivedPrimaryKeys);
+				Assert.AreEqual(0, derivedPrimaryKeys.Length);
+			}
+		}
+
+		public class Base2
+		{
+			protected      int _ID;
+
+			[PrimaryKey]
+			public virtual int  ID
+			{
+				get { return _ID;  }
+				set { _ID = value; }
+			}
+		}
+
+		public class Derived2 : Base2
+		{
+			public override int ID
+			{
+				get { return _ID;  }
+				set { _ID = value; }
+			}
+		}
+
+		[Test]
+		public void PrimaryKeyOverrideTest2()
+		{
+			using (DbManager db = new DbManager())
+			{
+				MemberMapper[] personPrimaryKeys = GetKeyFieldList(db, typeof (Base2));
+				Assert.IsNotNull(personPrimaryKeys);
+				Assert.AreEqual(1, personPrimaryKeys.Length);
+				Assert.AreEqual("ID", personPrimaryKeys[0].MemberName);
+
+				MemberMapper[] derivedPrimaryKeys = GetKeyFieldList(db, typeof (Derived2));
+				Assert.IsNotNull(derivedPrimaryKeys);
+				Assert.AreEqual(0, derivedPrimaryKeys.Length);
+			}
+		}
+
+		public class Base3
+		{
+			[PrimaryKey]
+			public int ID;
+		}
+
+		public class Derived3 : Base3
+		{
+			public new int ID;
+		}
+
+		[Test]
+		public void PrimaryKeyOverrideTest3()
+		{
+			using (DbManager db = new DbManager())
+			{
+				MemberMapper[] personPrimaryKeys = GetKeyFieldList(db, typeof (Base3));
+				Assert.IsNotNull(personPrimaryKeys);
+				Assert.AreEqual(1, personPrimaryKeys.Length);
+				Assert.AreEqual("ID", personPrimaryKeys[0].MemberName);
+
+				MemberMapper[] derivedPrimaryKeys = GetKeyFieldList(db, typeof (Derived3));
+				Assert.IsNotNull(derivedPrimaryKeys);
+				Assert.AreEqual(0, derivedPrimaryKeys.Length);
+			}
+		}
+	}
+}