I have a console app constructed using the following code:
public partial class Program
{
private static async Task<int> Main(string[] args)
{
Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration(cfg =>
{
cfg.SetBasePath(contentRootFull);
cfg.AddJsonFile($"appsettings.{environment}.json", false, true);
cfg.AddEnvironmentVariables().Build();
})
.ConfigureServices((hostContext, services) =>
{
services.AddTransient<IMyService, MyService>();
services.AddSingleton<MyConsoleApp>(); // Register your main application class
})
.Build()
.Services.GetRequiredService<MyConsoleApp>() // Resolve your main application class
.Run(args); // Execute your application logic
}
public partial class Program { } // so you can reference it from tests
ASP.Net Core uses WebApplicationFactory<TStartup>. Is there any similar mechanism to do integration tests with a console application which uses dependency injection?
MyConsoleAppdoes, and how much it really knows about the outside world.