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 NullableEnum
|
|
12 {
|
|
13 public class Source
|
|
14 {
|
|
15 public Source(string value)
|
|
16 {
|
|
17 Field = value;
|
|
18 }
|
|
19
|
|
20 public string Field;
|
|
21 }
|
|
22
|
|
23 public enum StrEnum
|
|
24 {
|
|
25 [MapValue("str")] Str,
|
|
26 [MapValue("str1")] Str1
|
|
27 }
|
|
28
|
|
29 public class StrDest1
|
|
30 {
|
|
31 public StrEnum? Field;
|
|
32 }
|
|
33
|
|
34 [Test]
|
|
35 public void Test1()
|
|
36 {
|
|
37 StrDest1 sd = Map.ObjectToObject<StrDest1>(new Source("str"));
|
|
38
|
|
39 Assert.AreEqual(StrEnum.Str, sd.Field);
|
|
40 }
|
|
41
|
|
42 [Test]
|
|
43 public void Test2()
|
|
44 {
|
|
45 StrDest1 sd = Map.ObjectToObject<StrDest1>(new Source(null));
|
|
46
|
|
47 Assert.IsNull(sd.Field);
|
|
48 }
|
|
49
|
|
50 public class StrDest2
|
|
51 {
|
|
52 public Mapping.EnumExtension.CountryCodeEnum? Field;
|
|
53 }
|
|
54
|
|
55 [Test]
|
|
56 public void Test3()
|
|
57 {
|
|
58 Map.Extensions = TypeExtension.GetExtensions("Map.xml");
|
|
59
|
|
60 StrDest2 sd = Map.ObjectToObject<StrDest2>(new Source("AL"));
|
|
61
|
|
62 Assert.AreEqual(Mapping.EnumExtension.CountryCodeEnum.AL, sd.Field);
|
|
63 }
|
|
64
|
|
65 [Test]
|
|
66 public void Test4()
|
|
67 {
|
|
68 Map.Extensions = TypeExtension.GetExtensions("Map.xml");
|
|
69
|
|
70 StrDest2 sd = Map.ObjectToObject<StrDest2>(new Source(null));
|
|
71
|
|
72 Assert.IsNull(sd.Field);
|
|
73 }
|
|
74
|
|
75 public enum IntEnum
|
|
76 {
|
|
77 Str = 1,
|
|
78 Str1 = 2
|
|
79 }
|
|
80
|
|
81 public class StrDest3
|
|
82 {
|
|
83 public IntEnum? Field;
|
|
84 }
|
|
85
|
|
86 [Test]
|
|
87 public void Test5()
|
|
88 {
|
|
89 StrDest3 sd = Map.ObjectToObject<StrDest3>(new Source("1"));
|
|
90
|
|
91 Assert.AreEqual(IntEnum.Str, sd.Field);
|
|
92 }
|
|
93
|
|
94 [Test]
|
|
95 public void Test6()
|
|
96 {
|
|
97 StrDest3 sd = Map.ObjectToObject<StrDest3>(new Source(null));
|
|
98
|
|
99 Assert.IsNull(sd.Field);
|
|
100 }
|
|
101 }
|
|
102 }
|