aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline.Tests/Services/DatabaseBasedTest.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-11-13 16:20:45 +0800
committerGitHub <noreply@github.com>2020-11-13 16:20:45 +0800
commit381cb7c64123c71899f549baa16bb610cc8b037f (patch)
treedfb4dd690704e887e3609265e6a652fe7ccea218 /BackEnd/Timeline.Tests/Services/DatabaseBasedTest.cs
parent5b78017e93450342c85a0e7f5ed16bbb6ae8422e (diff)
parentb635b4453756d9a33c173c9b9f2ae0ab7c830d3b (diff)
downloadtimeline-381cb7c64123c71899f549baa16bb610cc8b037f.tar.gz
timeline-381cb7c64123c71899f549baa16bb610cc8b037f.tar.bz2
timeline-381cb7c64123c71899f549baa16bb610cc8b037f.zip
Merge pull request #183 from crupest/auth
Refactor auth module to enable more flexiable permission control.
Diffstat (limited to 'BackEnd/Timeline.Tests/Services/DatabaseBasedTest.cs')
-rw-r--r--BackEnd/Timeline.Tests/Services/DatabaseBasedTest.cs49
1 files changed, 49 insertions, 0 deletions
diff --git a/BackEnd/Timeline.Tests/Services/DatabaseBasedTest.cs b/BackEnd/Timeline.Tests/Services/DatabaseBasedTest.cs
new file mode 100644
index 00000000..7c97158c
--- /dev/null
+++ b/BackEnd/Timeline.Tests/Services/DatabaseBasedTest.cs
@@ -0,0 +1,49 @@
+using System.Threading.Tasks;
+using Timeline.Entities;
+using Timeline.Tests.Helpers;
+using Xunit;
+
+namespace Timeline.Tests.Services
+{
+ public abstract class DatabaseBasedTest : IAsyncLifetime
+ {
+ protected TestDatabase TestDatabase { get; }
+ protected DatabaseContext Database { get; private set; }
+
+ protected DatabaseBasedTest(bool databaseCreateUsers = true)
+ {
+ TestDatabase = new TestDatabase(databaseCreateUsers);
+ }
+
+ public async Task InitializeAsync()
+ {
+ await TestDatabase.InitializeAsync();
+ Database = TestDatabase.CreateContext();
+ await OnDatabaseCreatedAsync();
+ OnDatabaseCreated();
+ }
+
+ public async Task DisposeAsync()
+ {
+ BeforeDatabaseDestroy();
+ await BeforeDatabaseDestroyAsync();
+ await Database.DisposeAsync();
+ await TestDatabase.DisposeAsync();
+ }
+
+
+ protected virtual void OnDatabaseCreated() { }
+ protected virtual void BeforeDatabaseDestroy() { }
+
+
+ protected virtual Task OnDatabaseCreatedAsync()
+ {
+ return Task.CompletedTask;
+ }
+
+ protected virtual Task BeforeDatabaseDestroyAsync()
+ {
+ return Task.CompletedTask;
+ }
+ }
+}