db testing
This commit is contained in:
parent
555087232c
commit
b75d0add7d
3 changed files with 38 additions and 10 deletions
|
|
@ -1,34 +1,44 @@
|
|||
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||
using Yavsc.Models;
|
||||
|
||||
namespace Yavsc.Org.Tests.Mandatory
|
||||
{
|
||||
|
||||
[Collection("Database")]
|
||||
{[Collection("Database")]
|
||||
[Trait("regression", "II")]
|
||||
[Trait("dev", "wip")]
|
||||
public class Database: IClassFixture<WebServerFixture>, IDisposable
|
||||
{
|
||||
readonly WebServerFixture _serverFixture;
|
||||
readonly ITestOutputHelper output;
|
||||
public Database(WebServerFixture serverFixture, ITestOutputHelper output)
|
||||
readonly WebServerFixture _serverFixture;
|
||||
|
||||
public Database(ITestOutputHelper output, WebServerFixture _serverFixture)
|
||||
{
|
||||
this.output = output;
|
||||
_serverFixture = serverFixture;
|
||||
|
||||
this._serverFixture = _serverFixture;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Assuming we're using an account that may create databases,
|
||||
/// Assuming we're using an account that may create databases,
|
||||
/// Install all our migrations in a fresh new database.
|
||||
/// </summary>
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_serverFixture!=null)
|
||||
if (_serverFixture!=null)
|
||||
{
|
||||
_serverFixture.Dispose();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestDatabaseMigration()
|
||||
{
|
||||
// Test logic goes here
|
||||
_serverFixture.ResetAndMigrateDatabase();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -189,6 +189,20 @@ public sealed class WebServerFixture : WebHostFixture
|
|||
return app;
|
||||
}
|
||||
|
||||
public void ResetAndMigrateDatabase()
|
||||
{
|
||||
using var scope = Services.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
|
||||
db.Database.EnsureDeleted();
|
||||
if (db.Database.IsRelational())
|
||||
{
|
||||
db.Database.Migrate();
|
||||
return;
|
||||
}
|
||||
|
||||
db.Database.EnsureCreated();
|
||||
}
|
||||
|
||||
protected override async Task<WebApplication> ConfigurePipelineAsync(WebApplication app)
|
||||
{
|
||||
// The MSBuild target CopyYavscOrgStaticAssets in
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue