diff options
author | 杨宇千 <crupest@outlook.com> | 2019-11-20 18:21:17 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-20 18:21:17 +0800 |
commit | 751467deb8ae18909ebd2b241bbb64f1f9da8295 (patch) | |
tree | 788b8acdf1141c757cb3226d3cd5f64594386b8f /Timeline.Tests/Helpers/TestApplication.cs | |
parent | 2de7fa95bb5ad0a10f74fb390bac464a250dee42 (diff) | |
parent | 33318b9244a82fee6d711aa15f853e1590ff13f7 (diff) | |
download | timeline-751467deb8ae18909ebd2b241bbb64f1f9da8295.tar.gz timeline-751467deb8ae18909ebd2b241bbb64f1f9da8295.tar.bz2 timeline-751467deb8ae18909ebd2b241bbb64f1f9da8295.zip |
Merge pull request #54 from crupest/timeline
Add core feature Timeline (currently only personal timeline)
Diffstat (limited to 'Timeline.Tests/Helpers/TestApplication.cs')
-rw-r--r-- | Timeline.Tests/Helpers/TestApplication.cs | 24 |
1 files changed, 3 insertions, 21 deletions
diff --git a/Timeline.Tests/Helpers/TestApplication.cs b/Timeline.Tests/Helpers/TestApplication.cs index b0187a30..a624da6b 100644 --- a/Timeline.Tests/Helpers/TestApplication.cs +++ b/Timeline.Tests/Helpers/TestApplication.cs @@ -1,35 +1,18 @@ using Microsoft.AspNetCore.Mvc.Testing;
-using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System;
using Timeline.Entities;
-using Timeline.Tests.Mock.Data;
namespace Timeline.Tests.Helpers
{
public class TestApplication : IDisposable
{
- public SqliteConnection DatabaseConnection { get; } = new SqliteConnection("Data Source=:memory:;");
+ public TestDatabase Database { get; } = new TestDatabase();
public WebApplicationFactory<Startup> Factory { get; }
public TestApplication(WebApplicationFactory<Startup> factory)
{
- // We should keep the connection, so the database is persisted but not recreate every time.
- // See https://docs.microsoft.com/en-us/ef/core/miscellaneous/testing/sqlite#writing-tests .
- DatabaseConnection.Open();
-
- {
- var options = new DbContextOptionsBuilder<DatabaseContext>()
- .UseSqlite(DatabaseConnection)
- .Options;
-
- using (var context = new DatabaseContext(options))
- {
- TestDatabase.InitDatabase(context);
- };
- }
-
Factory = factory.WithWebHostBuilder(builder =>
{
builder.ConfigureServices(services =>
@@ -37,7 +20,7 @@ namespace Timeline.Tests.Helpers services.AddEntityFrameworkSqlite();
services.AddDbContext<DatabaseContext>(options =>
{
- options.UseSqlite(DatabaseConnection);
+ options.UseSqlite(Database.Connection);
});
});
});
@@ -45,8 +28,7 @@ namespace Timeline.Tests.Helpers public void Dispose()
{
- DatabaseConnection.Close();
- DatabaseConnection.Dispose();
+ Database.Dispose();
}
}
}
|