| 
0
 | 
     1 using System;
 | 
| 
 | 
     2 
 | 
| 
 | 
     3 using NUnit.Framework;
 | 
| 
 | 
     4 
 | 
| 
 | 
     5 using BLToolkit.Mapping;
 | 
| 
 | 
     6 
 | 
| 
 | 
     7 namespace Mapping
 | 
| 
 | 
     8 {
 | 
| 
 | 
     9 	[TestFixture]
 | 
| 
 | 
    10 	public class DefaultValueAttributeTest
 | 
| 
 | 
    11 	{
 | 
| 
 | 
    12 		[MapValue(Enum1.Value1, "1")]
 | 
| 
 | 
    13 		[MapValue(Enum1.Value3, "3")]
 | 
| 
 | 
    14 		[DefaultValue(Enum1.Value3)]
 | 
| 
 | 
    15 		public enum Enum1
 | 
| 
 | 
    16 		{
 | 
| 
 | 
    17 			Value1,
 | 
| 
 | 
    18 			[MapValue("2")] Value2,
 | 
| 
 | 
    19 			Value3
 | 
| 
 | 
    20 		}
 | 
| 
 | 
    21 
 | 
| 
 | 
    22 		public class Object1
 | 
| 
 | 
    23 		{
 | 
| 
 | 
    24 			public Enum1 Enum1;
 | 
| 
 | 
    25 			[DefaultValue(Enum1.Value1)]
 | 
| 
 | 
    26 			public Enum1 Enum2;
 | 
| 
 | 
    27 		}
 | 
| 
 | 
    28 
 | 
| 
 | 
    29 		[Test]
 | 
| 
 | 
    30 		public void TestEnum1()
 | 
| 
 | 
    31 		{
 | 
| 
 | 
    32 			ObjectMapper om = Map.GetObjectMapper(typeof(Object1));
 | 
| 
 | 
    33 
 | 
| 
 | 
    34 			Object1 o = (Object1)om.CreateInstance();
 | 
| 
 | 
    35 
 | 
| 
 | 
    36 			om.SetValue(o, "Enum1", "55");
 | 
| 
 | 
    37 			om.SetValue(o, "Enum2", "66");
 | 
| 
 | 
    38 
 | 
| 
 | 
    39 			Assert.AreEqual(Enum1.Value3, o.Enum1);
 | 
| 
 | 
    40 			Assert.AreEqual(Enum1.Value1, o.Enum2);
 | 
| 
 | 
    41 
 | 
| 
 | 
    42 			Assert.AreEqual("3",  om.GetValue(o, "Enum1"));
 | 
| 
 | 
    43 			Assert.AreEqual("1",  om.GetValue(o, "Enum2"));
 | 
| 
 | 
    44 		}
 | 
| 
 | 
    45 
 | 
| 
 | 
    46 		[MapValue(Enum2.Value1, "1")]
 | 
| 
 | 
    47 		[MapValue(Enum2.Value3, "3")]
 | 
| 
 | 
    48 		public enum Enum2
 | 
| 
 | 
    49 		{
 | 
| 
 | 
    50 			Value1,
 | 
| 
 | 
    51 			[MapValue("2")] Value2,
 | 
| 
 | 
    52 			[DefaultValue]  Value3
 | 
| 
 | 
    53 		}
 | 
| 
 | 
    54 
 | 
| 
 | 
    55 		public class Object2
 | 
| 
 | 
    56 		{
 | 
| 
 | 
    57 			public Enum2 Enum1;
 | 
| 
 | 
    58 		}
 | 
| 
 | 
    59 
 | 
| 
 | 
    60 		[Test]
 | 
| 
 | 
    61 		public void TestEnum2()
 | 
| 
 | 
    62 		{
 | 
| 
 | 
    63 			ObjectMapper om = Map.GetObjectMapper(typeof(Object2));
 | 
| 
 | 
    64 
 | 
| 
 | 
    65 			Object2 o = (Object2)om.CreateInstance();
 | 
| 
 | 
    66 
 | 
| 
 | 
    67 			om.SetValue(o, "Enum1", "55");
 | 
| 
 | 
    68 
 | 
| 
 | 
    69 			Assert.AreEqual(Enum2.Value3, o.Enum1);
 | 
| 
 | 
    70 
 | 
| 
 | 
    71 			Assert.AreEqual("3",  om.GetValue(o, "Enum1"));
 | 
| 
 | 
    72 		}
 | 
| 
 | 
    73 
 | 
| 
 | 
    74 		[DefaultValue(typeof(Enum2), Enum2.Value2)]
 | 
| 
 | 
    75 		public class Object3
 | 
| 
 | 
    76 		{
 | 
| 
 | 
    77 			public Enum2 Enum1;
 | 
| 
 | 
    78 		}
 | 
| 
 | 
    79 
 | 
| 
 | 
    80 		[Test]
 | 
| 
 | 
    81 		public void TestEnum3()
 | 
| 
 | 
    82 		{
 | 
| 
 | 
    83 			ObjectMapper om = Map.GetObjectMapper(typeof(Object3));
 | 
| 
 | 
    84 
 | 
| 
 | 
    85 			Object3 o = (Object3)om.CreateInstance();
 | 
| 
 | 
    86 
 | 
| 
 | 
    87 			om.SetValue(o, "Enum1", "55");
 | 
| 
 | 
    88 
 | 
| 
 | 
    89 			Assert.AreEqual(Enum2.Value2, o.Enum1);
 | 
| 
 | 
    90 
 | 
| 
 | 
    91 			Assert.AreEqual("2",  om.GetValue(o, "Enum1"));
 | 
| 
 | 
    92 		}
 | 
| 
 | 
    93 
 | 
| 
 | 
    94 		[DefaultValue(Enum2.Value2)]
 | 
| 
 | 
    95 		public class Object4
 | 
| 
 | 
    96 		{
 | 
| 
 | 
    97 			public Enum2 Enum1;
 | 
| 
 | 
    98 		}
 | 
| 
 | 
    99 
 | 
| 
 | 
   100 		[Test]
 | 
| 
 | 
   101 		public void TestEnum4()
 | 
| 
 | 
   102 		{
 | 
| 
 | 
   103 			ObjectMapper om = Map.GetObjectMapper(typeof(Object4));
 | 
| 
 | 
   104 
 | 
| 
 | 
   105 			Object4 o = (Object4)om.CreateInstance();
 | 
| 
 | 
   106 
 | 
| 
 | 
   107 			om.SetValue(o, "Enum1", "55");
 | 
| 
 | 
   108 
 | 
| 
 | 
   109 			Assert.AreEqual(Enum2.Value2, o.Enum1);
 | 
| 
 | 
   110 
 | 
| 
 | 
   111 			Assert.AreEqual("2",  om.GetValue(o, "Enum1"));
 | 
| 
 | 
   112 		}
 | 
| 
 | 
   113 	}
 | 
| 
 | 
   114 }
 |