forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFieldGetterFixture.cs
133 lines (115 loc) · 5.05 KB
/
FieldGetterFixture.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using System;
using NHibernate.Properties;
using NHibernate.Util;
using NUnit.Framework;
namespace NHibernate.Test.PropertyTest
{
/// <summary>
/// This is more of a test of ReflectHelper.GetGetter() to make sure that
/// it will find the correct IGetter when a Property does not exist.
/// </summary>
[TestFixture]
public class FieldGetterFixture
{
private FieldGetterClass obj = new FieldGetterClass();
[Test]
public void NoNamingStrategy()
{
IGetter fieldGetter = ReflectHelper.GetGetter(typeof(FieldGetterClass), "Id", "field");
Assert.IsNotNull(fieldGetter, "should have found getter");
Assert.AreEqual(typeof(FieldAccessor.FieldGetter), fieldGetter.GetType(), "IGetter should be for a field.");
Assert.AreEqual(typeof(Int32), fieldGetter.ReturnType, "returns Int32.");
Assert.IsNull(fieldGetter.Method, "no MethodInfo for fields.");
Assert.IsNull(fieldGetter.PropertyName, "no Property Names for fields.");
Assert.AreEqual(7, fieldGetter.Get(obj), "Get() for Int32");
}
[Test]
public void CamelCaseNamingStrategy()
{
IGetter fieldGetter = ReflectHelper.GetGetter(typeof(FieldGetterClass), "PropertyOne", "field.camelcase");
Assert.IsNotNull(fieldGetter, "should have found getter");
Assert.AreEqual(typeof(FieldAccessor.FieldGetter), fieldGetter.GetType(), "IGetter should be for a field.");
Assert.AreEqual(typeof(DateTime), fieldGetter.ReturnType, "returns DateTime.");
Assert.IsNull(fieldGetter.Method, "no MethodInfo for fields.");
Assert.IsNull(fieldGetter.PropertyName, "no Property Names for fields.");
Assert.AreEqual(DateTime.Parse("2000-01-01"), fieldGetter.Get(obj), "Get() for DateTime");
}
[Test]
public void CamelCaseUnderscoreNamingStrategy()
{
IGetter fieldGetter = ReflectHelper.GetGetter(typeof(FieldGetterClass), "PropertyTwo", "field.camelcase-underscore");
Assert.IsNotNull(fieldGetter, "should have found getter");
Assert.AreEqual(typeof(FieldAccessor.FieldGetter), fieldGetter.GetType(), "IGetter should be for a field.");
Assert.AreEqual(typeof(Boolean), fieldGetter.ReturnType, "returns Boolean.");
Assert.IsNull(fieldGetter.Method, "no MethodInfo for fields.");
Assert.IsNull(fieldGetter.PropertyName, "no Property Names for fields.");
Assert.AreEqual(true, fieldGetter.Get(obj), "Get() for Boolean");
}
[Test]
public void LowerCaseUnderscoreNamingStrategy()
{
IGetter fieldGetter = ReflectHelper.GetGetter(typeof(FieldGetterClass), "PropertyFour", "field.lowercase-underscore");
Assert.IsNotNull(fieldGetter, "should have found getter");
Assert.AreEqual(typeof(FieldAccessor.FieldGetter), fieldGetter.GetType(), "IGetter should be for a field.");
Assert.AreEqual(typeof(Int64), fieldGetter.ReturnType, "returns Int64.");
Assert.IsNull(fieldGetter.Method, "no MethodInfo for fields.");
Assert.IsNull(fieldGetter.PropertyName, "no Property Names for fields.");
Assert.AreEqual(Int64.MaxValue, fieldGetter.Get(obj), "Get() for Int64");
}
[Test]
public void PascalCaseMUnderscoreNamingStrategy()
{
IGetter fieldGetter =
ReflectHelper.GetGetter(typeof(FieldGetterClass), "PropertyThree", "field.pascalcase-m-underscore");
Assert.IsNotNull(fieldGetter, "should have found getter");
Assert.AreEqual(typeof(FieldAccessor.FieldGetter), fieldGetter.GetType(), "IGetter should be for a field.");
Assert.AreEqual(typeof(TimeSpan), fieldGetter.ReturnType, "returns DateTime.");
Assert.IsNull(fieldGetter.Method, "no MethodInfo for fields.");
Assert.IsNull(fieldGetter.PropertyName, "no Property Names for fields.");
Assert.AreEqual(new TimeSpan(DateTime.Parse("2001-01-01").Ticks), fieldGetter.Get(obj), "Get() for TimeSpan");
}
[Test]
public void CamelCaseMUnderscoreNamingStrategy()
{
IGetter fieldGetter =
ReflectHelper.GetGetter(typeof(FieldGetterClass), "PropertyFive", "field.camelcase-m-underscore");
Assert.IsNotNull(fieldGetter, "should have found getter");
Assert.AreEqual(typeof(FieldAccessor.FieldGetter), fieldGetter.GetType(), "IGetter should be for a field.");
Assert.AreEqual(typeof(decimal), fieldGetter.ReturnType, "returns Decimal.");
Assert.IsNull(fieldGetter.Method, "no MethodInfo for fields.");
Assert.IsNull(fieldGetter.PropertyName, "no Property Names for fields.");
Assert.AreEqual(2.5m, fieldGetter.Get(obj), "Get() for Decimal");
}
public class FieldGetterClass
{
#pragma warning disable 414
private int Id = 7;
private DateTime propertyOne = DateTime.Parse("2000-01-01");
private bool _propertyTwo = true;
private TimeSpan m_PropertyThree = new TimeSpan(DateTime.Parse("2001-01-01").Ticks);
private long _propertyfour = Int64.MaxValue;
private decimal m_propertyFive = 2.5m;
#pragma warning restore 414
public DateTime PropertyOne
{
get { return propertyOne; }
}
public bool PropertyTwo
{
get { return _propertyTwo; }
}
public TimeSpan PropertyThree
{
get { return m_PropertyThree; }
}
public long PropertyFour
{
get { return _propertyfour; }
}
public decimal PropertyFive
{
get { return m_propertyFive; }
}
}
}
}