diff options
author | crupest <crupest@outlook.com> | 2020-02-21 20:19:10 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-21 20:19:10 +0800 |
commit | 15371296c7b4b6a3a9a75b844ade5ccf00ec53bb (patch) | |
tree | bc3da9df67e73dff6578da9a0f4cd3982f4cd5f2 /Timeline.Tests | |
parent | 32765bc2009d36cd3bc124e2a9bb769fc3ec9b4b (diff) | |
parent | 90e5eb7672e58745d1c41c28051375582d22e6ec (diff) | |
download | timeline-15371296c7b4b6a3a9a75b844ade5ccf00ec53bb.tar.gz timeline-15371296c7b4b6a3a9a75b844ade5ccf00ec53bb.tar.bz2 timeline-15371296c7b4b6a3a9a75b844ade5ccf00ec53bb.zip |
Merge pull request #59 from crupest/dev
Migrate to sqlite.
Diffstat (limited to 'Timeline.Tests')
-rw-r--r-- | Timeline.Tests/Helpers/TestApplication.cs | 30 | ||||
-rw-r--r-- | Timeline.Tests/Timeline.Tests.csproj | 6 |
2 files changed, 29 insertions, 7 deletions
diff --git a/Timeline.Tests/Helpers/TestApplication.cs b/Timeline.Tests/Helpers/TestApplication.cs index bc5deeec..52c2f2e2 100644 --- a/Timeline.Tests/Helpers/TestApplication.cs +++ b/Timeline.Tests/Helpers/TestApplication.cs @@ -1,10 +1,13 @@ using Microsoft.AspNetCore.Mvc.Testing;
-using Microsoft.AspNetCore.TestHost;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
+using System.Collections.Generic;
+using System.IO;
using Timeline.Entities;
+using Timeline.Migrations;
namespace Timeline.Tests.Helpers
{
@@ -14,25 +17,42 @@ namespace Timeline.Tests.Helpers public WebApplicationFactory<Startup> Factory { get; }
+ public string WorkDir { get; }
+
public TestApplication(WebApplicationFactory<Startup> factory)
{
+ WorkDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
+ Directory.CreateDirectory(WorkDir);
+
DatabaseConnection = new SqliteConnection("Data Source=:memory:;");
DatabaseConnection.Open();
- var options = new DbContextOptionsBuilder<DevelopmentDatabaseContext>()
+ var options = new DbContextOptionsBuilder<DatabaseContext>()
.UseSqlite(DatabaseConnection)
.Options;
- using (var context = new DevelopmentDatabaseContext(options))
+ using (var context = new DatabaseContext(options))
{
context.Database.EnsureCreated();
+ context.JwtToken.Add(new JwtTokenEntity
+ {
+ Key = JwtTokenGenerateHelper.GenerateKey()
+ });
+ context.SaveChanges();
}
Factory = factory.WithWebHostBuilder(builder =>
{
+ builder.ConfigureAppConfiguration((context, config) =>
+ {
+ config.AddInMemoryCollection(new Dictionary<string, string>
+ {
+ ["WorkDir"] = WorkDir
+ });
+ });
builder.ConfigureServices(services =>
{
- services.AddDbContext<DatabaseContext, DevelopmentDatabaseContext>(options =>
+ services.AddDbContext<DatabaseContext>(options =>
{
options.UseSqlite(DatabaseConnection);
});
@@ -44,6 +64,8 @@ namespace Timeline.Tests.Helpers {
DatabaseConnection.Close();
DatabaseConnection.Dispose();
+
+ Directory.Delete(WorkDir, true);
}
}
}
diff --git a/Timeline.Tests/Timeline.Tests.csproj b/Timeline.Tests/Timeline.Tests.csproj index 40e8cda2..00c1e103 100644 --- a/Timeline.Tests/Timeline.Tests.csproj +++ b/Timeline.Tests/Timeline.Tests.csproj @@ -11,14 +11,14 @@ <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
- <PackageReference Include="FluentAssertions" Version="5.10.0" />
+ <PackageReference Include="FluentAssertions" Version="5.10.2" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
- <PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.1.1" />
+ <PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.1.2" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
- <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
|