-
Notifications
You must be signed in to change notification settings - Fork 59
Open
Description
what is the proper way of injecting this within a test case? ASP Core 7.0
public class IndexModel : PageModel
{
private readonly DbContext _context;
private readonly IConfiguration _configuration;
private readonly IToastNotification _toastNotification;
public IndexModel(DbContext context, IConfiguration configuration, IToastNotification toastNotification)
{
_context = context;
_configuration = configuration;
_toastNotification = toastNotification;
}
...
...
...
}
public class Tests
{
private readonly HttpClient _httpClient;
private readonly DbContext _context;
private readonly IConfiguration _configuration;
private readonly IToastNotification _toastNotification; ??
public Tests()
{
var webAppFactory = new WebApplicationFactory<Program>();
var scope = webAppFactory.Services.CreateScope();
var scopedServices = scope.ServiceProvider;
_httpClient = webAppFactory.CreateDefaultClient();
_context = scopedServices.GetRequiredService<DbContext>();
_configuration = scopedServices.GetRequiredService(typeof(IConfiguration)) as IConfiguration;
}
[Fact, Priority(1)]
public async Task OnPostAddSectionAsyncTest()
{
var indexModel= new IndexModel(_context, _configuration, ???);
}
...
...
...
}
Metadata
Metadata
Assignees
Labels
No labels