Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with inject of NToastNotify within Unit Test #164

Open
Scnck opened this issue Jan 26, 2023 · 0 comments
Open

Issue with inject of NToastNotify within Unit Test #164

Scnck opened this issue Jan 26, 2023 · 0 comments

Comments

@Scnck
Copy link

Scnck commented Jan 26, 2023

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, ???);
        }
	
	...
	...
	...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant