Search code examples
c#aspnetboilerplate

IHostingEnvironment for testing


I'm trying to use the unit test project in ABP 2.0.2 and I get the following error when I run the selected test GetUsers_Test().

Message: Castle.MicroKernel.Handlers.HandlerException : Can't create component 'imfundoplatform.imfundoplatformCoreModule' as it has dependencies to be satisfied.

'imfundoplatform.imfundoplatformCoreModule' is waiting for the following dependencies:
- Service 'Microsoft.AspNetCore.Hosting.IHostingEnvironment' which was not registered.

The constructor for my Core module:

public imfundoplatformCoreModule(IHostingEnvironment env)
{
    _appConfiguration = AppConfigurations.Get(env.ContentRootPath, env.EnvironmentName, env.IsDevelopment());
}

I cannot figure out how to pass this to the module or get unit tests working. Please help!


Solution

  • you cannot inject IHostingEnvironment ... To get the content root path use;

    Directory.GetCurrentDirectory