Mercurial > pub > bltoolkit
comparison UnitTests/CS/Mapping/ISupportMappingTest.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 using BLToolkit.Reflection; | |
| 7 using BLToolkit.TypeBuilder; | |
| 8 | |
| 9 namespace Mapping | |
| 10 { | |
| 11 [TestFixture, Category("Mapping")] | |
| 12 public class ISupportMappingTest | |
| 13 { | |
| 14 public class SourceObject | |
| 15 { | |
| 16 public int Int1 = 10; | |
| 17 public int Int2 = 20; | |
| 18 public int Int3 = 30; | |
| 19 } | |
| 20 | |
| 21 public class Object1 : ISupportMapping | |
| 22 { | |
| 23 public Object1(InitContext initContext) | |
| 24 { | |
| 25 if (initContext != null) | |
| 26 Int11 = (int)initContext.Parameters[0]; | |
| 27 | |
| 28 if (Int11 == 77) | |
| 29 initContext.StopMapping = true; | |
| 30 } | |
| 31 | |
| 32 public int Int11; | |
| 33 public int Int22; | |
| 34 public int Int3; | |
| 35 public int Int44; | |
| 36 | |
| 37 public void BeginMapping(InitContext initContext) | |
| 38 { | |
| 39 Int22 = (int)initContext.Parameters[1]; | |
| 40 | |
| 41 if (Int22 == 66) | |
| 42 initContext.StopMapping = true; | |
| 43 } | |
| 44 | |
| 45 public void EndMapping(InitContext initContext) | |
| 46 { | |
| 47 Int44 = (int)initContext.Parameters[2]; | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 [Test] | |
| 52 public void Test1() | |
| 53 { | |
| 54 Object1 o = (Object1)Map.ObjectToObject(new SourceObject(), typeof(Object1), 11, 22, 44); | |
| 55 | |
| 56 Assert.AreEqual(11, o.Int11); | |
| 57 Assert.AreEqual(22, o.Int22); | |
| 58 Assert.AreEqual(30, o.Int3); | |
| 59 Assert.AreEqual(44, o.Int44); | |
| 60 } | |
| 61 | |
| 62 [Test] | |
| 63 public void Test2() | |
| 64 { | |
| 65 Object1 o = new Object1(null); | |
| 66 | |
| 67 Map.ObjectToObject(new SourceObject(), o, 11, 22, 44); | |
| 68 | |
| 69 Assert.AreEqual(0, o.Int11); | |
| 70 Assert.AreEqual(22, o.Int22); | |
| 71 Assert.AreEqual(30, o.Int3); | |
| 72 Assert.AreEqual(44, o.Int44); | |
| 73 } | |
| 74 | |
| 75 [Test] | |
| 76 public void Test3() | |
| 77 { | |
| 78 Object1 o = (Object1)Map.ObjectToObject(new SourceObject(), typeof(Object1), 77, 66, 44); | |
| 79 | |
| 80 Assert.AreEqual(77, o.Int11); | |
| 81 Assert.AreEqual(0, o.Int22); | |
| 82 Assert.AreEqual(0, o.Int3); | |
| 83 Assert.AreEqual(0, o.Int44); | |
| 84 } | |
| 85 | |
| 86 [Test] | |
| 87 public void Test4() | |
| 88 { | |
| 89 Object1 o = (Object1)Map.ObjectToObject(new SourceObject(), typeof(Object1), 11, 66, 44); | |
| 90 | |
| 91 Assert.AreEqual(11, o.Int11); | |
| 92 Assert.AreEqual(66, o.Int22); | |
| 93 Assert.AreEqual(0, o.Int3); | |
| 94 Assert.AreEqual(0, o.Int44); | |
| 95 } | |
| 96 | |
| 97 public abstract class Object5 : ISupportMapping | |
| 98 { | |
| 99 public Object5(InitContext initContext) | |
| 100 { | |
| 101 Int11 = (int)initContext.Parameters[0]; | |
| 102 } | |
| 103 | |
| 104 [Parameter(77)] | |
| 105 public abstract int Int00 { get; set; } | |
| 106 public abstract int Int11 { get; set; } | |
| 107 public abstract int Int22 { get; set; } | |
| 108 public abstract short Int3 { get; set; } | |
| 109 public abstract int Int44 { get; set; } | |
| 110 | |
| 111 public void BeginMapping(InitContext initContext) | |
| 112 { | |
| 113 Int22 = (int)initContext.Parameters[1]; | |
| 114 } | |
| 115 | |
| 116 public void EndMapping(InitContext initContext) | |
| 117 { | |
| 118 Int44 = (int)initContext.Parameters[2]; | |
| 119 } | |
| 120 } | |
| 121 | |
| 122 [Test] | |
| 123 public void Test5() | |
| 124 { | |
| 125 Object5 o = (Object5)Map.ObjectToObject(new SourceObject(), typeof(Object5), 11, 22, 44); | |
| 126 | |
| 127 Assert.AreEqual(77, o.Int00); | |
| 128 Assert.AreEqual(11, o.Int11); | |
| 129 Assert.AreEqual(22, o.Int22); | |
| 130 Assert.AreEqual(30, o.Int3); | |
| 131 Assert.AreEqual(44, o.Int44); | |
| 132 } | |
| 133 } | |
| 134 } |
