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
|
||||
|
|
|
|||
|
|
@ -11,6 +11,10 @@ namespace Yavsc.Migrations
|
|||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
var declarationDateDefaultSql = ActiveProvider == "Microsoft.EntityFrameworkCore.Sqlite"
|
||||
? "CURRENT_TIMESTAMP"
|
||||
: "LOCALTIMESTAMP";
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Activities",
|
||||
columns: table => new
|
||||
|
|
@ -1484,7 +1488,7 @@ namespace Yavsc.Migrations
|
|||
Platform = table.Column<string>(type: "text", nullable: true),
|
||||
Version = table.Column<string>(type: "text", nullable: true),
|
||||
DeviceOwnerId = table.Column<string>(type: "text", nullable: true),
|
||||
DeclarationDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, defaultValueSql: "LOCALTIMESTAMP"),
|
||||
DeclarationDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, defaultValueSql: declarationDateDefaultSql),
|
||||
LatestActivityUpdate = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue