2012-01-06 27 views
7

Tôi muốn viết kiểm tra để xác minh ánh xạ trong windsor lâu đài. Tôi đang sử dụng ASP MVC2 nơi tôi đang sử dụng windsor lâu đài để ánh xạ kho của tôi.Thử nghiệm ánh xạ chibernate Castle Windsor trong httpModules không được đăng ký

Tôi đã đọc bài viết này:

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

và dựa trên này tôi đã tạo ra MS thử nghiệm

[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); 
      } 
     } 

tôi Các dữ liệu cho target.getcontainer() thực hiện

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

Tôi nhận được tin nhắn là fol mức thấp:

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> 

Trả lời

2

Tôi đã có cùng một vấn đề và tôi đã tìm thấy một giải pháp: Bạn có thể xác định một sự kiện trong contructor của unit test để ghi đè 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

Cảm ơn! Chính xác những gì tôi cần. –

+0

Haha, một vài tháng sau, tôi đến cùng một vấn đề trong một dự án khác và nó giải quyết nó cho tôi một lần nữa. Cảm ơn! PS Chỉ cần nhớ để thực hiện đăng ký sự kiện ComponentModelCreated này trước bất kỳ trình cài đặt hoặc Đăng ký cuộc gọi nào! –

Các vấn đề liên quan