.nettfsdependency-injectioncastle-windsorautomated-tests

How do I do Dependency Injection in a test project (TFS 2008) using Castle


I'm using Castle Windsor for dependency injection in my test project. I'm trying to create an instance one of my 'Repository' classes. "It works fine on my machine", but when I run a nightly build in TFS, my tests are not able to load said classes.

private static readonly WindsorContainer _container = new WindsorContainer(new XmlInterpreter());


    public void MyTestInitialize()
    {
        var testRepository = (IBogusRepository)_container[typeof(IBogusRepository)];

    }

xml configuration:

<castle>
    <components>
      <component id="primaryBogusRepository" type="Example2008.Repository.LALALALALA, Example2008.Repository" service="Example2008.Domain.Repository.IBogusRepository, Example2008.Domain" />
      <component id="primaryProductRepository" type="Example2008.Repository.ProductRepository, Example2008.Repository" service="Example2008.Domain.Repository.IProductRepository, Example2008.Domain" />
    </components>
  </castle>

When I queue a new build it produces the following message:

Unable to create instance of class Example2008.Test.ActiveProductRepositoryTest. Error: System.Configuration.ConfigurationException: The type name Example2008.Repository.LALALALALA, Example2008.Repository could not be located.

Castle.Windsor.Installer.DefaultComponentInstaller.ObtainType(String typeName) Castle.Windsor.Installer.DefaultComponentInstaller.SetUpComponents(IConfiguration[] configurations, IWindsorContainer container) Castle.Windsor.Installer.DefaultComponentInstaller.SetUp(IWindsorContainer container, IConfigurationStore store) Castle.Windsor.WindsorContainer.RunInstaller() Castle.Windsor.WindsorContainer..ctor(IConfigurationInterpreter interpreter) Example2008.Test.ActiveProductRepositoryTest..cctor() in d:\Code_Temp\Example Project Nightly\Sources\Example2008.Test\ProductRepositoryTest.cs: line 19

From this message, it seems that my configuration is correct (it can see that I want to instantiate the concrete class 'LALALALALA', so the xml configuration has obviously been red correctly)

I think I have my dependencies set up correctly as well (because it works locally, even if I clean the solution and rebuild).

Any thoughts?

(using VS2008, TFS 2008.Net 3.5, Castle 1.03, by the way)


Solution

  • That is...interesting. I found this blog post that may help your issue. It looks like MSTest is using that as its working directory, which is annoying to say the least. The blog post shows how to change the directory, so that you can have consistent results. I would also do some Googling to find out if a more elegant solution exists.