I made a repo for the issue I have with Integration testing upgrading to .net core 3.0 : https://github.com/ranouf/TestingWithDotNetCore3_0
When I launch the test, I have this issue: Message:
System.AggregateException : One or more errors occurred. (Class fixture type 'MyIntegrationTests.TestServerFixture' had one or more unresolved constructor arguments: ITestOutputHelper output) (The following constructor parameters did not have matching fixture data: TestServerFixture testServerFixture) ---- Class fixture type 'MyIntegrationTests.TestServerFixture' had one or more unresolved constructor arguments: ITestOutputHelper output ---- The following constructor parameters did not have matching fixture data: TestServerFixture testServerFixture Stack Trace: ----- Inner Stack Trace #1 (Xunit.Sdk.TestClassException) ----- ----- Inner Stack Trace #2 (Xunit.Sdk.TestClassException) -----
Here is the constructor:
public class WeatherForecastController_Tests : IClassFixture<TestServerFixture>
{
public WeatherForecastController_Tests(TestServerFixture testServerFixture, ITestOutputHelper output)
{
Client = testServerFixture.Client;
Output = output;
}
TestStartup:
public class TestStartup : Startup
{
public TestStartup(IConfiguration configuration)
: base(configuration)
{
}
public override void SetUpDataBase(IServiceCollection services)
{
// here is where I use the InMemoryDatabase
}
}
TestServerFixture:
public class TestServerFixture : WebApplicationFactory<TestStartup>
{
private IHost _host;
public HttpClient Client { get; }
public ITestOutputHelper Output { get; }
public TestServerFixture(ITestOutputHelper output)
{
Output = output;
Client = Server.CreateClient();
}
// never called but this is where i was previously building up the server
//
protected override TestServer CreateServer(IWebHostBuilder builder)
{
return base.CreateServer(builder);
}
protected override IHost CreateHost(IHostBuilder builder)
{
_host = builder.Build();
using (var scope = _host.Services.CreateScope())
{
var services = scope.ServiceProvider;
InitializeDataBase(services, Output);
}
_host.Start();
return _host;
}
protected override IHostBuilder CreateHostBuilder() =>
Host.CreateDefaultBuilder()
.ConfigureLogging((hostingContext, builder) =>
{
builder.Services.AddSingleton<ILoggerProvider>(new XunitLoggerProvider(Output));
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseTestServer();
});
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
builder.UseStartup<TestStartup>();
}
private void InitializeDataBase(IServiceProvider services, ITestOutputHelper output)
{
try
{
output.WriteLine("Starting the database initialization.");
//here is where is feed the Test DB
output.WriteLine("The database initialization has been done.");
}
catch (Exception ex)
{
output.WriteLine("An error occurred while initialization the database.");
Console.WriteLine(ex.Message);
}
}
}
So clearly, the Iod for TestServerFixture testServerFixture and ITestOutputHelper output doesnt work. How to make it work?