2013-06-20 29 views
0

UnitTesting項目,一個TestMethod這就要求存儲庫和信息庫中PostgreSQL「NHibernate.Cfg.Configuration」的類型初始值設定項引發異常。單元測試

當我運行這個測試其拋出異常創造了新的紀錄:

消息:The type initializer for 'NHibernate.Cfg.Configuration' threw an exception.

內部異常:{"The type initializer for 'NHibernate.LoggerProvider' threw an exception."}

StackTrace:

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(); 

那麼問題只與單元測試項目。

的App.config:

<?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> 

回答

1

單元測試部署的工作方式不同。您應該從* .testsettings文件中將所有必需的文件/程序集標記在bin目錄中。看到下面的屏幕:

enter image description here

所有你現在要做的是找到丟失的文件/裝配,並通過testsettings文件進行部署。

1

您的app.config必須在單元測試中的bin目錄。檢查app.config的屬性並查看它是否已部署。

+0

請回復。我總是複製:始終在app.config上覆制。這不是連接字符串問題。我試過PostgreSQLConfiguration.Standard.ConnectionString(「Server = localhost; Port = 5432; Database = Test; User = postgres; Password = Test;」),但它也可以。 –

相關問題