Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.4k views
in Technique[技术] by (71.8m points)

asp.net core - Integration testing loading mock data from root folder

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
    • data -data.json
  • Controller
  • contains the actual code

WebAPI-IntegrationTest

  • wwwroot

    • data -data.json
  • Tests

  • contains Integration test

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...