📄 enumgenericfixture.cs
字号:
using System;
using System.Collections;
using NHibernate.Impl;
using NHibernate.Persister.Entity;
using NHibernate.Type;
using NUnit.Framework;
namespace NHibernate.Test.GenericTest.EnumGeneric
{
/// <summary>
/// http://jira.nhibernate.org/browse/NH-1236
/// </summary>
[TestFixture]
public class EnumGenericFixture : TestCase
{
protected override IList Mappings
{
get { return new String[] {"GenericTest.EnumGeneric.EnumGenericFixture.hbm.xml"}; }
}
protected override string MappingsAssembly
{
get { return "NHibernate.Test"; }
}
[Test]
public void MapsToEnum()
{
using (ISession s = OpenSession())
{
A a = new A();
SessionImpl impl = (SessionImpl) s;
IEntityPersister persister = impl.GetEntityPersister(a);
int index = -1;
for (int i = 0; i < persister.PropertyNames.Length; i++)
{
if (persister.PropertyNames[i].Equals("NullableValue"))
{
index = i;
break;
}
}
if (index == -1) Assert.Fail("Property NullableValue not found.");
Assert.AreEqual(typeof (PersistentEnumType), persister.PropertyTypes[index].GetType());
}
}
[Test]
public void Persists()
{
A a1 = new A();
using (ISession s = OpenSession())
{
s.Save(a1);
s.Flush();
}
//Verify initial null
using (ISession s = OpenSession())
{
A a2 = s.Load<A>(a1.Id);
Assert.IsNull(a2.NullableValue);
a2.NullableValue = B.Value3;
s.Save(a2);
s.Flush();
}
//Verify set to non-null
using (ISession s = OpenSession())
{
A a3 = s.Load<A>(a1.Id);
Assert.AreEqual(B.Value3, a3.NullableValue);
a3.NullableValue = null;
s.Save(a3);
s.Flush();
}
//Verify set to null
using (ISession s = OpenSession())
{
A a4 = s.Load<A>(a1.Id);
Assert.IsNull(a4.NullableValue);
s.Delete(a4);
s.Flush();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -