comparison HowTo/Mapping/MapFieldAttribute.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f990fcb411a9
1 using System;
2
3 using NUnit.Framework;
4
5 using BLToolkit.Mapping;
6
7 namespace HowTo.Mapping
8 {
9 [TestFixture]
10 public class MapField
11 {
12 public class SourceObject1
13 {
14 public string Street = "1 Main";
15 public string City = "Bigtown";
16 public string State = "XX";
17 public string Zip = "00000";
18 }
19
20 public class Address
21 {
22 public string Street;
23 public string City;
24 public string State;
25 public string Zip;
26 }
27
28 /*[a]*/[MapField("Street", "Address.Street")]/*[/a]*/
29 /*[a]*/[MapField("City", "Address.City")]/*[/a]*/
30 /*[a]*/[MapField("State", "Address.State")]/*[/a]*/
31 /*[a]*/[MapField("Zip", "Address.Zip")]/*[/a]*/
32 public class Order1
33 {
34 public Address Address = new Address();
35 }
36
37 [Test]
38 public void MapFieldTest1()
39 {
40 SourceObject1 source = new SourceObject1();
41 Order1 order = Map.ObjectToObject<Order1>(source);
42
43 Assert.AreEqual("1 Main", order.Address.Street);
44 Assert.AreEqual("Bigtown", order.Address.City);
45 Assert.AreEqual("XX", order.Address.State);
46 Assert.AreEqual("00000", order.Address.Zip);
47 }
48
49 public class SourceObject2
50 {
51 public string BillingStreet = "1 Main";
52 public string BillingCity = "Bigtown";
53 public string BillingState = "XX";
54 public string BillingZip = "00000";
55
56 public string ShippingStreet = "2 Main";
57 public string ShippingCity = "Bigtown";
58 public string ShippingState = "XX";
59 public string ShippingZip = "00000";
60 }
61
62 public class Order2
63 {
64 /*[a]*/[MapField(Format="Billing{0}")]/*[/a]*/
65 public Address BillingAddress = new Address();
66
67 /*[a]*/[MapField(Format="Shipping{0}")]/*[/a]*/
68 public Address ShippingAddress = new Address();
69 }
70
71 [Test]
72 public void MapFieldTest2()
73 {
74 SourceObject2 source = new SourceObject2();
75 Order2 order = Map.ObjectToObject<Order2>(source);
76
77 Assert.AreEqual("1 Main", order.BillingAddress.Street);
78 Assert.AreEqual("Bigtown", order.BillingAddress.City);
79 Assert.AreEqual("XX", order.BillingAddress.State);
80 Assert.AreEqual("00000", order.BillingAddress.Zip);
81
82 Assert.AreEqual("2 Main", order.ShippingAddress.Street);
83 Assert.AreEqual("Bigtown", order.ShippingAddress.City);
84 Assert.AreEqual("XX", order.ShippingAddress.State);
85 Assert.AreEqual("00000", order.ShippingAddress.Zip);
86 }
87 }
88 }