Mercurial > pub > bltoolkit
comparison UnitTests/CS/Mapping/BltMapTests.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 using System.Collections.Generic; | |
3 using System.ComponentModel; | |
4 | |
5 using BLToolkit.Mapping; | |
6 using BLToolkit.Reflection; | |
7 | |
8 using NUnit.Framework; | |
9 | |
10 namespace Mapping | |
11 { | |
12 [TestFixture] | |
13 public class BltMapTests | |
14 { | |
15 #region Types | |
16 | |
17 public class TestStep | |
18 { | |
19 public string Step { get; set; } | |
20 } | |
21 | |
22 internal class Test_Int | |
23 { | |
24 private BindingList<TestStep> _steps; | |
25 | |
26 public Test_Int() | |
27 { | |
28 InitializeStepsList(); | |
29 } | |
30 | |
31 public bool NotNullSetterCalled = false; | |
32 | |
33 private void InitializeStepsList(IList<TestStep> init = null) | |
34 { | |
35 _steps = new BindingList<TestStep>(init ?? new List<TestStep>()); | |
36 if (init != null) NotNullSetterCalled = true; | |
37 } | |
38 | |
39 [MapField(Storage = "Steps")] | |
40 public IList<TestStep> Steps | |
41 { | |
42 get { return _steps; } | |
43 private set { InitializeStepsList(value); } | |
44 } | |
45 } | |
46 | |
47 public class Test_Pub | |
48 { | |
49 private BindingList<TestStep> _steps; | |
50 | |
51 public Test_Pub() | |
52 { | |
53 InitializeStepsList(); | |
54 } | |
55 | |
56 public bool NotNullSetterCalled = false; | |
57 | |
58 private void InitializeStepsList(IList<TestStep> init = null) | |
59 { | |
60 _steps = new BindingList<TestStep>(init ?? new List<TestStep>()); | |
61 if (init != null) NotNullSetterCalled = true; | |
62 } | |
63 | |
64 [MapField(Storage = "Steps")] | |
65 public IList<TestStep> Steps | |
66 { | |
67 get { return _steps; } | |
68 private set { InitializeStepsList(value); } | |
69 } | |
70 } | |
71 | |
72 public class TestStepRecord | |
73 { | |
74 public string Step { get; set; } | |
75 } | |
76 | |
77 public class TestRecord | |
78 { | |
79 //[MapField] | |
80 public List<TestStepRecord> Steps; | |
81 } | |
82 | |
83 #endregion | |
84 | |
85 [Test] | |
86 public void TestExpressionMapper_Int() | |
87 { | |
88 //Arrange | |
89 var em = new ExpressionMapper<TestRecord, Test_Int>(); | |
90 var tr = new TestRecord { Steps = new List<TestStepRecord> { new TestStepRecord {Step = "Test" } } }; | |
91 | |
92 //Act | |
93 var t = em.GetMapper()(tr); | |
94 | |
95 //Assert | |
96 Assert.IsTrue(t.Steps.Count == 1); | |
97 Assert.IsTrue(t.NotNullSetterCalled); | |
98 } | |
99 | |
100 [Test] | |
101 public void TestExpressionMapper_Pub() | |
102 { | |
103 //Arrange | |
104 var em = new ExpressionMapper<TestRecord, Test_Pub>(); | |
105 var tr = new TestRecord { Steps = new List<TestStepRecord> { new TestStepRecord { Step = "Test" } } }; | |
106 | |
107 //Act | |
108 var t = em.GetMapper()(tr); | |
109 | |
110 //Assert | |
111 Assert.IsTrue(t.Steps.Count == 1); | |
112 Assert.IsTrue(t.NotNullSetterCalled); | |
113 } | |
114 } | |
115 } |