comparison UnitTests/CS/Mapping/ObjectMapperTest.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.Data;
3 using BLToolkit.EditableObjects;
4 using NUnit.Framework;
5
6 using BLToolkit.Mapping;
7
8 namespace Mapping
9 {
10 [TestFixture]
11 public class ObjectMapperTest
12 {
13 public class Object1
14 {
15 [MapField("col2")]
16 public int Col1 { get; set; }
17 }
18
19
20 [Test]
21 public void NameTest1()
22 {
23 var dt = new DataTable();
24
25 dt.Columns.Add("col1", typeof(int));
26 dt.Columns.Add("col2", typeof(int));
27 dt.Rows.Add(1, 2);
28
29 var o = Map.DataRowToObject<Object1>(dt.Rows[0]);
30
31 Assert.AreEqual(2, o.Col1);
32 }
33
34 [Test]
35 public void NameTest2()
36 {
37 var dt = new DataTable();
38
39 dt.Columns.Add("col2", typeof(int));
40 dt.Columns.Add("col1", typeof(int));
41 dt.Rows.Add(2, 1);
42
43 var o = Map.DataRowToObject<Object1>(dt.Rows[0]);
44
45 Assert.AreEqual(2, o.Col1);
46 }
47
48 [Test]
49 public void GetMemberMapperByNameAliasTest()
50 {
51 var om = Map.GetObjectMapper(typeof(Object1));
52
53 Assert.IsNotNull(om["col2"]);
54 Assert.IsNull (om["Col1"]);
55 Assert.IsNotNull(om["Col1", true]);
56 Assert.IsNull (om["col1", true]);
57 }
58
59 public interface ICheckOut
60 {
61 DateTime DateCheckOut { get; }
62 }
63
64 public class Test : ICheckOut
65 {
66 public int ID { get; set; }
67 public string Value { get; set; }
68
69 DateTime ICheckOut.DateCheckOut
70 {
71 get { return DateTime.Now; }
72 }
73 }
74
75 [Test]
76 public void MapObjectToObject()
77 {
78 var s1 = new Test { ID = 1, Value = "123" };
79 var s2 = new Test();
80
81 Map.ObjectToObject(s1, s2, null);
82 }
83
84 public abstract class BizEntityTest : EditableObject<BizEntityTest>
85 {
86 public abstract int ID { get; set; }
87 public abstract string Name { get; set; }
88 public abstract BizEntityTestInner BizEntityTestInner { get; set; }
89 }
90
91 public abstract class BizEntityTestInner : EditableObject<BizEntityTestInner>
92 {
93 public abstract int ID { get; set; }
94 public abstract string Name { get; set; }
95 }
96
97 [Test]
98 public void DestabilizeTest()
99 {
100 var bet = BizEntityTest.CreateInstance();
101
102 bet.ID = 1;
103 bet.Name = "BizEntityTest";
104 bet.BizEntityTestInner = BizEntityTestInner.CreateInstance();
105 bet.BizEntityTestInner.ID = 111;
106 bet.BizEntityTestInner.Name = "BizEntityTestInner";
107
108 var mapper = Map.GetObjectMapper<BizEntityTest, BizEntityTest>(true);
109
110 var bet2 = mapper(bet);
111 }
112 }
113 }