从命令行运行 MSTest 时出现 Fluent NNhibernate 异常
我正在为 Fluent NHibernate 映射编写一些单元测试(第一次)。当在 Visual Studio 中运行时,它们运行得很好。
这是使用 Resharpers 单元测试窗口或内置的 Visual Studio 窗口。
问题是当从 MSTest 运行单元测试时:
mstest /testcontainer:Tests.MyProject.dll
单元测试失败...
我从生成的 trx 文件中得到的唯一错误是:
BlockquoteUnit 测试适配器抛出异常:未解析成员“FluentNHibernate.Cfg.FluentConfigurationException,FluentNHibernate,Version=1.2.0.694,Culture=neutral,PublicKeyToken=8aa435e3cb308880”的类型..
这没有帮助...我无法调试代码,因为它在 Visual Studio 中工作得很好,并且测试文件中的错误消息没有给我任何信息...
创建会话的代码是:
public class InMemoryDatabaseTest : IDisposable
{
private Configuration _configuration;
private ISessionFactory _sessionFactory;
protected ISession _session;
public InMemoryDatabaseTest(Assembly assemblyContainingMappedType)
{
if (_configuration == null)
_sessionFactory = CreateSessionFactory(assemblyContainingMappedType);
_session = _sessionFactory.OpenSession();
new SchemaExport(_configuration).Execute(false, true, false, _session.Connection, Console.Out);
}
private ISessionFactory CreateSessionFactory(Assembly assemblyContainingMappedType)
{
return Fluently.Configure()
.Database(SQLiteConfiguration.Standard.InMemory)
.Mappings(m => m.FluentMappings.AddFromAssembly(assemblyContainingMappedType))
.ExposeConfiguration(cfg => _configuration = cfg)
.BuildSessionFactory();
}
public void Dispose()
{
_session.Dispose();
}
}
我不确定这是否是正确的创建方法单元测试会话。
任何人都知道出了什么问题:(
I'm writing some unit tests for Fluent NHibernate mappings (for the first time). When run in visual studio they run perfectly fine.
This is using Resharpers Unit Test window or the built in Visual Studio one.
The problem is when the unit tests are run from MSTest:
mstest /testcontainer:Tests.MyProject.dll
The unit tests fail...
The only error I get from the trx file thats generated is:
BlockquoteUnit Test Adapter threw exception: Type is not resolved for member 'FluentNHibernate.Cfg.FluentConfigurationException,FluentNHibernate, Version=1.2.0.694, Culture=neutral, PublicKeyToken=8aa435e3cb308880'..
Which doesn't help... I can't debug the code because it works perfectly fine in visual studio, and the error message in the test file doesn't give me any information...
The code around creating the session is:
public class InMemoryDatabaseTest : IDisposable
{
private Configuration _configuration;
private ISessionFactory _sessionFactory;
protected ISession _session;
public InMemoryDatabaseTest(Assembly assemblyContainingMappedType)
{
if (_configuration == null)
_sessionFactory = CreateSessionFactory(assemblyContainingMappedType);
_session = _sessionFactory.OpenSession();
new SchemaExport(_configuration).Execute(false, true, false, _session.Connection, Console.Out);
}
private ISessionFactory CreateSessionFactory(Assembly assemblyContainingMappedType)
{
return Fluently.Configure()
.Database(SQLiteConfiguration.Standard.InMemory)
.Mappings(m => m.FluentMappings.AddFromAssembly(assemblyContainingMappedType))
.ExposeConfiguration(cfg => _configuration = cfg)
.BuildSessionFactory();
}
public void Dispose()
{
_session.Dispose();
}
}
I'm not sure if this is the correct way of creating the session for unit testing tho.
Anyone got any idea what's wrong :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我解决了这个问题。原来是 PEBKAC 问题。
对于测试配置,我需要将 System.Data.Sqlite 程序集添加到配置中,以便在运行测试之前将其复制到 TestResult 文件夹。
所以 FluentNHibernate 配置异常是 Sqlite 程序集不存在。
添加程序集后,测试在控制台中运行,现在在集成构建上运行。耶。
I solved this problem. Turns out it was a PEBKAC problem.
For the test configuration I needed to add the System.Data.Sqlite assembly to the configuration so that it got copied to the TestResult folder prior to the test being run.
So the FluentNHibernate Configuration exception was that the Sqlite assembly didn't exist.
Adding the assembly, the test ran in the console and now runs on the integration builds. YAY.