forked from ThatRendle/Simple.Data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConcreteTypeCreatorTest.cs
104 lines (93 loc) · 3.59 KB
/
ConcreteTypeCreatorTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Simple.Data.UnitTest
{
using NUnit.Framework;
[TestFixture]
public class ConcreteTypeCreatorTest
{
[Test]
public void CanConvertDecimalToDouble()
{
var source = new Dictionary<string, object> { { "Value", 1.0m } };
var target = ConcreteTypeCreator.Get(typeof (DecimalToDouble));
object actual;
Assert.IsTrue(target.TryCreate(source, out actual));
Assert.IsInstanceOf<DecimalToDouble>(actual);
Assert.AreEqual(1.0d, ((DecimalToDouble)actual).Value);
}
[Test]
public void CanConvertDateTimeToNullableDateTime()
{
var expected = new DateTime(2011,9,8);
var source = new Dictionary<string, object> { { "Value", expected } };
var target = ConcreteTypeCreator.Get(typeof(DateTimeToNullableDateTime));
object actual;
Assert.IsTrue(target.TryCreate(source, out actual));
Assert.IsInstanceOf<DateTimeToNullableDateTime>(actual);
Assert.IsTrue(((DateTimeToNullableDateTime)actual).Value.HasValue);
Assert.AreEqual(expected, ((DateTimeToNullableDateTime)actual).Value.Value);
}
[Test]
public void CanConvertInt32ToEnum()
{
var expected = Int32ToEnum.Numbers.One;
var source = new Dictionary<string, object> { { "Value", (int)expected } };
var target = ConcreteTypeCreator.Get(typeof(Int32ToEnum));
object actual;
Assert.IsTrue(target.TryCreate(source, out actual));
Assert.IsInstanceOf<Int32ToEnum>(actual);
Assert.AreEqual(expected, ((Int32ToEnum)actual).Value);
}
[Test]
public void CanConvertInt32ToNullableEnum()
{
Int32ToNullableEnum.Numbers? expected = Int32ToNullableEnum.Numbers.One;
var source = new Dictionary<string, object> { { "Value", (int)expected } };
var target = ConcreteTypeCreator.Get(typeof(Int32ToNullableEnum));
object actual;
Assert.IsTrue(target.TryCreate(source, out actual));
Assert.IsInstanceOf<Int32ToNullableEnum>(actual);
Assert.AreEqual(expected, ((Int32ToNullableEnum)actual).Value);
}
[Test]
public void CanConvertStringToEnum()
{
var expected = Int32ToEnum.Numbers.One;
var source = new Dictionary<string, object> { { "Value", expected.ToString() } };
var target = ConcreteTypeCreator.Get(typeof(Int32ToEnum));
object actual;
Assert.IsTrue(target.TryCreate(source, out actual));
Assert.IsInstanceOf<Int32ToEnum>(actual);
Assert.AreEqual(expected, ((Int32ToEnum)actual).Value);
}
public class DecimalToDouble
{
public double Value { get; set; }
}
public class Int32ToNullableEnum
{
public Numbers? Value { get; set; }
public enum Numbers
{
One = 1,
Two = 2
}
}
public class DateTimeToNullableDateTime
{
public DateTime? Value { get; set; }
}
public class Int32ToEnum
{
public enum Numbers
{
One = 1,
Two = 2
}
public Numbers Value { get; set; }
}
}
}