0
|
1 using System;
|
|
2
|
|
3 using NUnit.Framework;
|
|
4
|
|
5 using BLToolkit.Mapping;
|
|
6
|
|
7 namespace HowTo.Mapping
|
|
8 {
|
|
9 [TestFixture]
|
|
10 public class ObjectToObject
|
|
11 {
|
|
12 public class SourceObject
|
|
13 {
|
|
14 public bool Value1 = true;
|
|
15 public string Value2 = "10";
|
|
16 public string StrValue = "test";
|
|
17 }
|
|
18
|
|
19 public class DestObject
|
|
20 {
|
|
21 [MapField("Value1")] public bool BoolValue;
|
|
22 [MapField("Value2")] public int IntValue;
|
|
23
|
|
24 // If the source and destination field/property names are equal,
|
|
25 // there is no need for using the MapField attribute.
|
|
26 //
|
|
27 public string StrValue;
|
|
28 }
|
|
29
|
|
30 [Test]
|
|
31 public void Test1()
|
|
32 {
|
|
33 SourceObject source = new SourceObject();
|
|
34 DestObject dest = Map./*[a]*/ObjectToObject/*[/a]*/<DestObject>(source);
|
|
35
|
|
36 Assert.AreEqual(true, dest.BoolValue);
|
|
37 Assert.AreEqual(10, dest.IntValue);
|
|
38 Assert.AreEqual("test", dest.StrValue);
|
|
39 }
|
|
40 }
|
|
41 }
|