How do I pass dependency to object with Castle Windsor and MS Test?

Posted by Nick on Stack Overflow See other posts from Stack Overflow or by Nick
Published on 2010-06-10T03:27:39Z Indexed on 2010/06/10 3:32 UTC
Read the original article Hit count: 200

I am trying to use Castle Windsor with MS Test. The test class only seems to use the default constructor. How do I configure Castle to resolve the service in the constructor?

Here is the Test Class' constructors:

private readonly IWebBrowser _browser;

        public DepressionSummaryTests()
        {

        }

        public DepressionSummaryTests(IWebBrowser browser)
        {
            _browser = browser;
        }

My component in the app config looks like so:

 <castle>
    <components>
      <component id="browser"
                 service="ConversationSummary.IWebBrowser, ConversationSummary"
                 type="ConversationSummary.Browser" />       

    </components>
  </castle>

Here is my application container:

public class ApplicationContainer : WindsorContainer
    {
        private static IWindsorContainer container;

        static ApplicationContainer()
        {
            container = new WindsorContainer(new XmlInterpreter(new ConfigResource("castle")));
        }
        private static IWindsorContainer Container
        {
            get { return container; }
        }

        public static IWebBrowser Browser
        {
            get { return (IWebBrowser) Container.Resolve("browser"); }
        }
    }

MS test requires the default constructor. What am I missing?

Thanks!

© Stack Overflow or respective owner

Related posts about c#

Related posts about dependency-injection