2012-01-06 4 views
7

城ウィンザーのマッピングを検証するテストを書いてみたいと思います。 私は城ウィンザーを使用して私のリポジトリをマップしているASP MVC2を使用しています。http.modulesのnhibernate城ウィンザーマッピングのテストが登録されていません

私はこの記事を読んだことがある:私はtarget.getcontainerため

[TestMethod()] 
     public void GetContainerTest() 
     { 
      MooseMvc.Infrastructure.DependencyInjectionInitialiser target = new MooseMvc.Infrastructure.DependencyInjectionInitialiser(); // TODO: Initialize to an appropriate value 
      IWindsorContainer container = target.GetContainer(); 
      foreach (IHandler assignableHandler in container.Kernel.GetAssignableHandlers(typeof(object))) 
      {    
       container.Resolve(assignableHandler.ComponentModel.Service); 
      } 
     } 

データ私のMSのテストを作成している

http://weblogs.asp.net/bsimser/archive/2008/06/04/the-first-spec-you-should-write-when-using-castle.aspx

をし、これに基づいて()

this._windsorContainer.Register(Component.For<TInterfaceType>() 
       .ImplementedBy(typeof(TConcreteType)).LifeStyle.PerWebRequest); 
を実装

私はフォローとしてメッセージを受け取ります安値:

Looks like you forgot to register the http module 
Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule Add '<add 
name="PerRequestLifestyle" 
type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, 
Castle.Windsor" />' to the <httpModules> section on your web.config. 
If you're running IIS7 in Integrated Mode you will need to add it to 
<modules> section under <system.webServer> 

答えて

1

私が発見した美しいガイド私は同じ問題があったと私は解決策を見つけた

2

追加する他の多くはありません

http://docs.castleproject.org/Windsor.Windsor-tutorial-part-three-a-testing-your-first-installer.ashx

..:ユニットテストのコンストラクタでイベントを定義して、LifestyleTypeをオーバーライドすることができます。

void Kernel_ComponentModelCreated(Castle.Core.ComponentModel model) 
{ 
    if (model.LifestyleType == LifestyleType.Undefined) 
     model.LifestyleType = LifestyleType.Transient; 

    if (model.LifestyleType == LifestyleType.PerWebRequest) 
     model.LifestyleType = LifestyleType.Transient; 
} 

public UnitTest1() 
{ 
    containerWithControllers = new WindsorContainer(); 

    containerWithControllers.Kernel.ComponentModelCreated += new ComponentModelDelegate(Kernel_ComponentModelCreated); 
} 
+0

ありがとうございます!正確に私が必要としたもの。 –

+0

母、数ヶ月後、別のプロジェクトでこの同じ問題に遭遇し、再び私のために解決します。ありがとう! PS InstallerやRegisterの呼び出しの前に、このComponentModelCreatedイベント登録を行うことを忘れないでください! –

関連する問題