diff HowTo/Mapping/MapValueAttribute1.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/HowTo/Mapping/MapValueAttribute1.cs	Thu Mar 27 21:46:09 2014 +0400
@@ -0,0 +1,75 @@
+using System;
+
+using NUnit.Framework;
+
+using BLToolkit.Mapping;
+
+namespace HowTo.Mapping
+{
+	[TestFixture]
+	public class MapValue1
+	{
+		public class SourceObject
+		{
+			public string Value = "Y";
+		}
+
+		public class TestObject1
+		{
+			// The attribute is applied to a field/property.
+			//
+			[/*[a]*/MapValue(true,  "Y")/*[/a]*/]
+			[/*[a]*/MapValue(false, "N")/*[/a]*/]
+			public bool Value;
+		}
+
+		[Test]
+		public void Test1()
+		{
+			SourceObject so = new SourceObject();
+			TestObject1  to = Map.ObjectToObject<TestObject1>(so);
+
+			Assert.AreEqual(true, to.Value);
+		}
+
+		// The attribute is applied to a class.
+		//
+		[/*[a]*/MapValue(true,  "Y")/*[/a]*/]
+		[/*[a]*/MapValue(false, "N")/*[/a]*/]
+		public class TestObject2
+		{
+			public bool Value;
+		}
+
+		[Test]
+		public void Test2()
+		{
+			SourceObject so = new SourceObject();
+			TestObject2  to = Map.ObjectToObject<TestObject2>(so);
+
+			Assert.AreEqual(true, to.Value);
+		}
+
+		// The attribute is applied to a base class and affects all child classes.
+		//
+		[/*[a]*/MapValue(typeof(bool), true,  "Y")/*[/a]*/]
+		[/*[a]*/MapValue(typeof(bool), false, "N")/*[/a]*/]
+		public class ObjectBase
+		{
+		}
+
+		public class TestObject3 : /*[a]*/ObjectBase/*[/a]*/
+		{
+			public bool Value;
+		}
+
+		[Test]
+		public void Test3()
+		{
+			SourceObject so = new SourceObject();
+			TestObject3  to = Map.ObjectToObject<TestObject3>(so);
+
+			Assert.AreEqual(true, to.Value);
+		}
+	}
+}