How to register integration tests of IUrlHelper and IHttpContextAccessor i?

I am trying to create integration tests for my ASP5 MVC6 application.

In my integration tests, I registered all my classes and added some special MVC Startup class form:

 _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 IUrlHelper or IHttpContextAccessor appears in the dependency tree.

This is how I create my test controllers:

 // register all my classes // run the code from above _provider = _services.BuildServiceProvider(); ActivatorUtilities.GetServiceOrCreateInstance<T>(_provider); 

Right now I have registered mocks for these interfaces, but I would prefer to use the original implementations.

What am I missing?

+5
source share

Source: https://habr.com/ru/post/1241379/


All Articles