C # Injection of dependencies in UnitTestProject

1

Good morning. I am setting up a test project to test a webapi (for now only the controllers). This uses Unity for the dependency injection.

For this, in my test project I have included the Unity 4.0.1 library and I have made the following changes.

In the app.config I have included the following block.

<configSections>
  <section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration, Version=4.0.0.0" />
  <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<unity configSource="Unity.config" />

And I have copied the Unity.config file that I have in the webapi. This file is correct and valid because it is the same one that the webapi uses and works correctly.

In the initialization function of the test I do the following:

UnityContainer container = new UnityContainer();
container.LoadConfiguration();

When I launch the debugging test, the second line throws me the following error.

No se puede abrir el archivo configSource 'Unity.config'.
(C:\Proyecto\UnitTestProject\bin\Debug\UnitTestProject.dll.config line 8)

I've been reviewing documentation and apparently I have everything right. Does anyone know what may be happening?

    
asked by Alejandro 29.08.2017 в 10:00
source

1 answer

0

First you must check if the unity.config file of your project is being copied in the path: C: \ Project \ UnitTestProject \ bin \ Debug \

If not, you should check the properties of the file from visual studio, if the action when compiling is: copy always.

    
answered by 29.08.2017 / 16:16
source