29 lines
812 B
C#
29 lines
812 B
C#
namespace Blog.Tests.EndToEnd;
|
|
|
|
public class BlogHostFactory<TProgram> : WebApplicationFactory<TProgram> where TProgram : class
|
|
{
|
|
public BlogHostFactory()
|
|
{
|
|
UseKestrel(server => server.Listen(IPAddress.Loopback, 0));
|
|
}
|
|
|
|
public string ServerAddress
|
|
{
|
|
get
|
|
{
|
|
StartServer();
|
|
return ClientOptions.BaseAddress.ToString();
|
|
}
|
|
}
|
|
|
|
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
|
{
|
|
builder.ConfigureLogging(config => config.ClearProviders());
|
|
builder.ConfigureTestServices(services =>
|
|
{
|
|
var postsDirectory = Path.Combine(Directory.GetCurrentDirectory(), "TestPosts");
|
|
var postServiceOptions = new FilePostServiceOptions() { PostsDirectory = postsDirectory };
|
|
services.AddSingleton(Options.Create(postServiceOptions));
|
|
});
|
|
}
|
|
} |