Skip to content

Issue with inject of NToastNotify within Unit Test #164

@Scnck

Description

@Scnck

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions