diff options
Diffstat (limited to 'Timeline.Tests/Helpers/TestApplication.cs')
-rw-r--r-- | Timeline.Tests/Helpers/TestApplication.cs | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/Timeline.Tests/Helpers/TestApplication.cs b/Timeline.Tests/Helpers/TestApplication.cs index abdb0a60..45807516 100644 --- a/Timeline.Tests/Helpers/TestApplication.cs +++ b/Timeline.Tests/Helpers/TestApplication.cs @@ -1,8 +1,10 @@ -using Microsoft.AspNetCore.Mvc.Testing;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.AspNetCore.TestHost;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
@@ -17,13 +19,13 @@ namespace Timeline.Tests.Helpers {
public SqliteConnection DatabaseConnection { get; private set; }
- public WebApplicationFactory<Startup> Factory { get; private set; }
+ public IHost Host { get; private set; }
public string WorkDir { get; private set; }
- public TestApplication(WebApplicationFactory<Startup> factory)
+ public TestApplication()
{
- Factory = factory;
+
}
public async Task InitializeAsync()
@@ -35,8 +37,7 @@ namespace Timeline.Tests.Helpers await DatabaseConnection.OpenAsync();
var options = new DbContextOptionsBuilder<DatabaseContext>()
- .UseSqlite(DatabaseConnection)
- .Options;
+ .UseSqlite(DatabaseConnection).Options;
using (var context = new DatabaseContext(options))
{
@@ -48,28 +49,36 @@ namespace Timeline.Tests.Helpers await context.SaveChangesAsync();
}
- Factory = Factory.WithWebHostBuilder(builder =>
- {
- builder.ConfigureAppConfiguration((context, config) =>
+ Host = await Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder()
+ .ConfigureAppConfiguration((context, config) =>
{
config.AddInMemoryCollection(new Dictionary<string, string>
{
[ApplicationConfiguration.UseMockFrontEndKey] = "true",
["WorkDir"] = WorkDir
});
- });
- builder.ConfigureServices(services =>
+ })
+ .ConfigureServices(services =>
{
services.AddDbContext<DatabaseContext>(options =>
{
options.UseSqlite(DatabaseConnection);
});
- });
- });
+ })
+ .ConfigureWebHost(webBuilder =>
+ {
+ webBuilder
+ .UseTestServer()
+ .UseStartup<Startup>();
+ })
+ .StartAsync();
}
public async Task DisposeAsync()
{
+ await Host.StopAsync();
+ Host.Dispose();
+
await DatabaseConnection.CloseAsync();
await DatabaseConnection.DisposeAsync();
Directory.Delete(WorkDir, true);
|