0

I have a XUnit project for End2End test for my Api Project.

Inside the Unit project: MyApi.E2E.Test

under its root folder, I have a setting file:

e2e-local-settings.json

Now I have a File called: MyWebApplicationFactory

public class MyWebApplicationFactory<TStartUp>: WebApplicationFactory<Startup>
{
    protected override void ConfigureWebHost(IWebHostBuilder builder)
    {
       ........code here.......
    }
}

exception How can I load the setting json file under the TEST project.

I have read this one: https://stackoverflow.com/a/47591692/601862 But it does not load from the Test Project, instead it loads from the Api project.

Franva
  • 6,565
  • 23
  • 79
  • 144

1 Answers1

0

The reason for it not finding it is because configuration files are expected to be in the application running directory. In your .csproj file, you would need to add a <Content> tag so that it is copied to the output directory.

<ItemGroup>
  <Content Include="e2e-local-settings.json" CopyToOutputDirectory="PreserveNewest" Link="e2e-local-settings.json" />
</ItemGroup>

Make sure after you add this, to look at the loaded modules window in the debugger, and look at the path where your test .dll is loaded from. Look at that directory, and make sure the file exists there, if the file doesn't exist, it will fail in the way you're seeing it.