diff UnitTests/CS/Mapping/XmlMap.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/Mapping/XmlMap.cs	Thu Mar 27 21:46:09 2014 +0400
@@ -0,0 +1,43 @@
+using System;
+using System.Data;
+
+using NUnit.Framework;
+
+using BLToolkit.DataAccess;
+using BLToolkit.Mapping;
+using BLToolkit.Reflection.Extension;
+
+namespace Mapping
+{
+	[TestFixture]
+	public class XmlMap
+	{
+		public class Person
+		{
+			[PrimaryKey]
+			[MapField("PersonID")]  public int    ID;
+			[MapField("FirstName")] public string FName;
+			[MapField("LastName")]  public string LName;
+		}
+
+		[Test]
+		public void Test()
+		{
+			Person p = (Person)new SqlQuery().SelectByKey(typeof(Person), 1);
+
+			Assert.AreEqual(1,        p.ID);
+			Assert.AreEqual("John",   p.FName);
+			Assert.AreEqual("Pupkin", p.LName);
+
+			MappingSchema map = new MappingSchema();
+
+			map.Extensions = TypeExtension.GetExtensions("XmlMap.xml");
+
+			DataRow dr = map.MapObjectToDataRow(p, new DataTable());
+
+			Assert.AreEqual(1,        dr["PERSON_ID"]);
+			Assert.AreEqual("John",   dr["FIRST_NAME"]);
+			Assert.AreEqual("Pupkin", dr["LAST_NAME"]);
+		}
+	}
+}