我有UnitTesting
一个项目,TestMethod
它调用存储库和存储库创建新记录PostgreSQL
当我运行此测试时,它会抛出异常:
信息:The type initializer for 'NHibernate.Cfg.Configuration' threw an exception.
内部异常:{"The type initializer for 'NHibernate.LoggerProvider' threw an exception."}
堆栈跟踪:
at NHibernate.Cfg.Configuration..ctor()
at FluentNHibernate.Cfg.FluentConfiguration..ctor()
at FluentNHibernate.Cfg.Fluently.Configure()
at Woo.Test.UnitTest.FillCompany()
当我调用它时,我的存储库运行良好ASP.NET MVC Applictaion
这是我的Fluent NHibernate
配置:
_configuration = Fluently.Configure().Database(PostgreSQLConfiguration.Standard.ConnectionString(c => c
.FromConnectionStringWithKey("DefaultConnection"))).Mappings(m => m.FluentMappings.AddFromAssemblyOf<Company>())
.ExposeConfiguration(cfg => new SchemaUpdate(cfg).Execute(false, true)).BuildConfiguration();
_sessionFactory = _configuration.BuildSessionFactory();
所以问题只出在单元测试项目上。
应用程序配置:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configurations>
<connectionStrings>
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Server=localhost;Port=5432;Database=Test;User=postgres;Password=Test;" />
</connectionStrings>
</configurations>
</configuration>