I am currently upgrading a project from .NET Core RC1 to the new RTM 1.0 version. In RC1, there was a IApplicationEnvironment which was replaced with IHostingEnvironment in version 1.0
In RC1 I could do this
public class MyClass
{
protected static IApplicationEnvironment ApplicationEnvironment { get;private set; }
public MyClass()
{
ApplicationEnvironment = PlatformServices.Default.Application;
}
}
Does anyone know how to achieve this in v1.0?
public class MyClass
{
protected static IHostingEnvironment HostingEnvironment { get;private set; }
public MyClass()
{
HostingEnvironment = ???????????;
}
}
In general, as IHostingEnvironment is just an interface, you can simply mock it to return whatever you want.
If you are using TestServer in your tests, the best way to mock is to use WebHostBuilder.Configure method. Something like this: