I have written one GET API which loads the json data from wwwroot/data/data.json. It works fine when I do testing through browser. I am getting the data and it displays
in the browser.
However when I run the same through integration testing, it does not load data from the same folder(wwwroot/data/data.json).
I created the same structure folder structure under Integration Test project as well.
Technology: .NET Core 3.1
[HttpGet]
public async Task<Response> FetchData()
{
var response = await new HttpClient().GetAsync("https://localhost:44311/data/data.json");
return somedata;
}
Please find the project struecture
WebAPI
- wwwroot
- Controller
- contains the actual code
WebAPI-IntegrationTest
I referred many of the sites and did not get enough information on my specific scenario. I tried the below article as well which uses
builder.UseContentRoot(".");
but no luck.
https://dasith.me/2018/12/30/integration-testing-aspnet-core-webapi/
If I want to write the integration test for the above , what are the steps I need to be followed?
What is the best practice for testing this kind of scenario? what are all the configuration needed for the same? It would be great if someone could proivde a simple example on this.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…