rehansaeed.github.io
rehansaeed.github.io copied to clipboard
[Comment] ASP.NET Core Integration Testing & Mocking using Moq
https://rehansaeed.com/asp-net-core-integration-testing-mocking-using-moq/
Leszek commented on 2020-01-03 13:48:39
Thank you very much, sir.
Another good article is on https://automationrhapsody.com/net-core-integration-testing-mock-dependencies/
Rutxifer commented on 2020-01-03 18:04:48
Great article! Could be improved using HttpClient rather than HttpClientFactory?
How it works if web application have a lot of dependencies? All of them are stored in properties when tests starts.
Muhammad Rehan Saeed commented on 2020-01-04 09:54:37
Great article! Could be improved using
HttpClientrather thanHttpClientFactory? How it works if web application have a lot of dependencies? All of them are stored in properties when tests starts.
Not sure what you mean. We're not using HttpClientFactory.
The only mocks you should have is for external systems like DB's.
Nicole commented on 2020-03-30 03:48:37
Hi,
Thank you for the article.
However, I came across an issue when i tried this method.
this.ApplicationOptions = serviceProvider.GetRequiredService<IOptions>().Value;
The thing inside IOptions should be non-abstract, but ApplicationOptions is an abstract class.
Is there any possible way to fix that?
Cheers, Nicole
Milind commented on 2020-04-07 07:05:32
Getting error in CustomWebApplicationFactory.cs for this.Services.CreateScope() in ConfigureClient method. It does not recognize it. What is this.Services?
Muhammad Rehan Saeed commented on 2020-04-08 14:31:55
Hi,
Thank you for the article.
However, I came across an issue when i tried this method.
this.ApplicationOptions = serviceProvider.GetRequiredService<IOptions>().Value;The thing inside
IOptionsshould be non-abstract, butApplicationOptionsis an abstract class.Is there any possible way to fix that?
Cheers, Nicole
ApplicationOptions is just a class that I myself wrote to contain some custom configuration options. It doesn't have to be abstract.
Muhammad Rehan Saeed commented on 2020-04-08 14:37:03
Getting error in
CustomWebApplicationFactory.csforthis.Services.CreateScope()inConfigureClientmethod. It does not recognize it. What isthis.Services?
The class inherits from WebApplicationFactory and that is where the Services property comes from.
Neal commented on 2020-04-20 20:28:28
You don' t need to extend startup to configure your test services for dotnet core 3+. IWebHostBuilder has a ConfigureTestServices extension method that will allow you to update the service registrations. In your custom web application factory override ConfigureWebHost and call the ConfigureTestServices method from there. This is documented here.
Muhammad Rehan Saeed commented on 2020-04-21 09:33:56
You don' t need to extend startup to configure your test services for dotnet core 3+.
IWebHostBuilderhas aConfigureTestServicesextension method that will allow you to update the service registrations. In your custom web application factory overrideConfigureWebHostand call theConfigureTestServicesmethod from there. This is documented here.
This is true. However, there was/is a known bug that stops this working at the time of writing. Also, I find that splitting it out into a separate class is helpful.
Jonathan commented on 2020-04-21 16:47:30
Nice article.