2017-09-05 60 views
1

我創建了一個單元測試項目(我正在使用nUnit),並且我想在其中使用OWIN自主主機& Castle Windsor。nUnit + OWIN啓動類 - 無法使用SetUpFixture和OneTimeSetUp屬性

但問題是,在執行任何測試之前,我無法管理以下代碼以進行初始化。

[assembly: OwinStartup(typeof(UnitTests.Startup))] 
namespace UnitTests 
{ 
    [SetUpFixture] 
    public class Startup 
    { 
     public static IWindsorContainer _container; 

     [OneTimeSetUp] 
     public void Configuration(IAppBuilder appBuilder) 
     { 
      var config = new HttpConfiguration(); 

      containerWithControllers = new WindsorContainer(); 

      //.... 
      config.DependencyResolver = new CastleResolver(_container); 

      appBuilder.UseWebApi(config); 
     } 
    } 
} 

回答

0

問題是,SetUpFixture由NUnit的框架和方法標有OneTimeSetUp不能有任何參數創建。所以你的SetUpFixture類應該看起來像這樣:

[SetUpFixture] 
public class SetUpFixture 
{ 
    public static TestServer _server; 

    [OneTimeSetUp] 
    public void SetUp() 
    { 
     _server = TestServer.Create<Startup>(); 
    } 
}