0
|
1 using System;
|
|
2
|
|
3 using NUnit.Framework;
|
|
4
|
|
5 using BLToolkit.Mapping;
|
|
6 using BLToolkit.Reflection.Extension;
|
|
7
|
|
8 namespace Mapping
|
|
9 {
|
|
10 [TestFixture]
|
|
11 public class EnumExtension
|
|
12 {
|
|
13 public enum CountryCodeEnum
|
|
14 {
|
|
15 AF,
|
|
16 AL,
|
|
17 DZ,
|
|
18 AS,
|
|
19 AD
|
|
20 }
|
|
21
|
|
22 public enum OtherEnum
|
|
23 {
|
|
24 EnumValue1,
|
|
25 EnumValue2
|
|
26 }
|
|
27
|
|
28 [Test]
|
|
29 public void Test1()
|
|
30 {
|
|
31 Map.Extensions = TypeExtension.GetExtensions("Map.xml");
|
|
32
|
|
33 Assert.AreEqual("AL", Map.EnumToValue(CountryCodeEnum.AL));
|
|
34 Assert.AreEqual(101, Map.EnumToValue(OtherEnum.EnumValue2));
|
|
35 }
|
|
36
|
|
37 public class TestObj
|
|
38 {
|
|
39 [MapField("country_code")] public CountryCodeEnum1 Country { get; set; }
|
|
40 [MapField("other")] public OtherEnum1 Other { get; set; }
|
|
41 }
|
|
42
|
|
43 public enum CountryCodeEnum1
|
|
44 {
|
|
45 [MapValue("AFA")] AF,
|
|
46 [MapValue("ALA")] AL,
|
|
47 [MapValue("DZA")] DZ,
|
|
48 [MapValue("ASA")] AS,
|
|
49 [MapValue("ADA")] AD
|
|
50 }
|
|
51
|
|
52 public enum OtherEnum1
|
|
53 {
|
|
54 [MapValue("v1")] EnumValue1,
|
|
55 [MapValue("v2")] EnumValue2
|
|
56 }
|
|
57
|
|
58 [Test]
|
|
59 public void EnumToValueTest()
|
|
60 {
|
|
61 Map.Extensions = TypeExtension.GetExtensions("Map.xml");
|
|
62
|
|
63 Assert.AreEqual("AL", Map.EnumToValue(CountryCodeEnum1.AL));
|
|
64 Assert.AreEqual(101, Map.EnumToValue(OtherEnum1.EnumValue2));
|
|
65 }
|
|
66
|
|
67 //[Test]
|
|
68 public void ObjToDicTest()
|
|
69 {
|
|
70 var obj = new TestObj { Country = CountryCodeEnum1.DZ, Other = OtherEnum1.EnumValue2 };
|
|
71 var sh = new MappingSchema { Extensions = TypeExtension.GetExtensions("Map.xml") };
|
|
72 var pars = sh.MapObjectToDictionary(obj);
|
|
73
|
|
74 Assert.AreEqual("DZ", pars["country_code"]);
|
|
75 Assert.AreEqual(101, pars["other"]);
|
|
76 }
|
|
77 }
|
|
78 }
|