I'm trying to create integration tests for my ASP5 MVC6
application.
In my integration tests I registered all my classes, and added some MVC specific stuff form Startup
class:
_services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApplicationDbContext>(
options =>
options.UseSqlServer(_configuration[ServerModulesLoader.DataDefaultConnectionConnectionstringConfigurationKey]));
_services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
_services.AddCors();
_services.AddMvc();
Everything works fine until either IUrlHelper
or IHttpContextAccessor
appears somewhere in the dependencies tree.
This is how I create my controllers for tests:
// register all my classes
// run the code from above
_provider = _services.BuildServiceProvider();
ActivatorUtilities.GetServiceOrCreateInstance<T>(_provider);
Right now I registered mocks for these interfaces, but I'd rather use original implementations.
What am I missing?
Aucun commentaire:
Enregistrer un commentaire