forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFieldAccessorFixture.cs
57 lines (52 loc) · 1.5 KB
/
FieldAccessorFixture.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
using System;
using NHibernate.Properties;
using NUnit.Framework;
namespace NHibernate.Test.PropertyTest
{
/// <summary>
/// Base test fixture for the Field Accessors.
/// </summary>
[TestFixture]
public class FieldAccessorFixture
{
protected IPropertyAccessor _accessor;
protected IGetter _getter;
protected ISetter _setter;
protected FieldClass _instance;
/// <summary>
/// SetUp the local fields for the test cases.
/// </summary>
/// <remarks>
/// Any classes testing out their field access should override this
/// and setup their FieldClass instance so that whichever field is
/// going to be reflected upon is initialized to 0.
/// </remarks>
[SetUp]
public virtual void SetUp()
{
_accessor = PropertyAccessorFactory.GetPropertyAccessor("field");
_getter = _accessor.GetGetter(typeof(FieldClass), "Id");
_setter = _accessor.GetSetter(typeof(FieldClass), "Id");
_instance = new FieldClass();
_instance.InitId(0);
}
[Test]
public void GetValue()
{
Assert.AreEqual(0, _getter.Get(_instance));
_instance.Increment();
Assert.AreEqual(1, _getter.Get(_instance));
Assert.IsFalse(_instance.BlahGetterCalled);
Assert.IsFalse(_instance.CamelBazGetterCalled);
Assert.IsFalse(_instance.CamelUnderscoreFooGetterCalled);
Assert.IsFalse(_instance.LowerUnderscoreFooGetterCalled);
}
[Test]
public void SetValue()
{
Assert.AreEqual(0, _getter.Get(_instance));
_setter.Set(_instance, 5);
Assert.AreEqual(5, _getter.Get(_instance));
}
}
}