feat/files-control #52
3 changed files with 38 additions and 10 deletions
db testing
commit
b75d0add7d
|
|
@ -1,20 +1,22 @@
|
||||||
|
|
||||||
|
using Microsoft.Data.Sqlite;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||||
|
using Yavsc.Models;
|
||||||
|
|
||||||
namespace Yavsc.Org.Tests.Mandatory
|
namespace Yavsc.Org.Tests.Mandatory
|
||||||
{
|
{[Collection("Database")]
|
||||||
|
|
||||||
[Collection("Database")]
|
|
||||||
[Trait("regression", "II")]
|
[Trait("regression", "II")]
|
||||||
[Trait("dev", "wip")]
|
[Trait("dev", "wip")]
|
||||||
public class Database: IClassFixture<WebServerFixture>, IDisposable
|
public class Database: IClassFixture<WebServerFixture>, IDisposable
|
||||||
{
|
{
|
||||||
readonly WebServerFixture _serverFixture;
|
|
||||||
readonly ITestOutputHelper output;
|
readonly ITestOutputHelper output;
|
||||||
public Database(WebServerFixture serverFixture, ITestOutputHelper output)
|
readonly WebServerFixture _serverFixture;
|
||||||
|
|
||||||
|
public Database(ITestOutputHelper output, WebServerFixture _serverFixture)
|
||||||
{
|
{
|
||||||
this.output = output;
|
this.output = output;
|
||||||
_serverFixture = serverFixture;
|
this._serverFixture = _serverFixture;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -30,5 +32,13 @@ namespace Yavsc.Org.Tests.Mandatory
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TestDatabaseMigration()
|
||||||
|
{
|
||||||
|
// Test logic goes here
|
||||||
|
_serverFixture.ResetAndMigrateDatabase();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -189,6 +189,20 @@ public sealed class WebServerFixture : WebHostFixture
|
||||||
return app;
|
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)
|
protected override async Task<WebApplication> ConfigurePipelineAsync(WebApplication app)
|
||||||
{
|
{
|
||||||
// The MSBuild target CopyYavscOrgStaticAssets in
|
// The MSBuild target CopyYavscOrgStaticAssets in
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,10 @@ namespace Yavsc.Migrations
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
{
|
{
|
||||||
|
var declarationDateDefaultSql = ActiveProvider == "Microsoft.EntityFrameworkCore.Sqlite"
|
||||||
|
? "CURRENT_TIMESTAMP"
|
||||||
|
: "LOCALTIMESTAMP";
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
name: "Activities",
|
name: "Activities",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
|
|
@ -1484,7 +1488,7 @@ namespace Yavsc.Migrations
|
||||||
Platform = table.Column<string>(type: "text", nullable: true),
|
Platform = table.Column<string>(type: "text", nullable: true),
|
||||||
Version = table.Column<string>(type: "text", nullable: true),
|
Version = table.Column<string>(type: "text", nullable: true),
|
||||||
DeviceOwnerId = 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)
|
LatestActivityUpdate = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue