我最近开始学习Fluent NH,并且在测试方法上遇到了一些麻烦。它需要永远运行(现在已经运行了十多分钟,并没有进展的迹象......)。流利的NHibernate映射测试需要永久
[TestMethod]
public void Entry_IsCorrectlyMapped()
{
Action<PersistenceSpecification<Entry>> testAction = pspec => pspec
.CheckProperty(e => e.Id, "1")
.VerifyTheMappings();
TestMapping<Entry>(testAction);
}
与这个辅助方法(稍作简化 - 我有一对夫妇try/catch块太大,以提供更好的错误消息):
public void TestMapping<T>(Action<PersistenceSpecification<T>> testAction) where T : IEntity
{
using (var session = DependencyFactory.CreateSessionFactory(true).OpenSession())
{
testAction(new PersistenceSpecification<T>(session));
}
}
的DependencyFactory.CreateSessionFactory()
方法是这样的:
public static ISessionFactory CreateSessionFactory(bool buildSchema)
{
var cfg = Fluently.Configure()
.Database(SQLiteConfiguration.Standard.InMemory())
.Mappings(m => m.FluentMappings.AddFromAssembly(typeof(Entry).Assembly));
if (buildSchema)
{
cfg = cfg.ExposeConfiguration(config => new SchemaExport(config).Create(false, true));
}
return cfg.BuildSessionFactory();
}
我试过调试过,但是我找不出瓶颈在哪里。为什么这需要这么长时间?
有多长 '长'?范围内有多少映射? – 2010-01-09 01:56:47
我说了十分钟,但现在已经过了半个多小时 - 测试跑步者仍然说“正在进行......”。到目前为止,只有两种映射 - 两者都非常简单。 – 2010-01-09 02:13:44