mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.5 KiB
74 lines
2.5 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Squidex.Domain.Apps.Core.TestHelpers;
|
|
using Squidex.Hosting;
|
|
using Squidex.Infrastructure.Migrations;
|
|
using Squidex.Infrastructure.Queries;
|
|
using Squidex.Providers.Postgres;
|
|
using Testcontainers.PostgreSql;
|
|
|
|
#pragma warning disable CA1822 // Mark members as static
|
|
#pragma warning disable MA0048 // File name must match type name
|
|
|
|
namespace Squidex.EntityFramework.TestHelpers;
|
|
|
|
[CollectionDefinition("Postgres")]
|
|
public sealed class PostgresFixtureCollection : ICollectionFixture<PostgresFixture>
|
|
{
|
|
}
|
|
|
|
public sealed class PostgresFixture : IAsyncLifetime, ISqlFixture<TestDbContextPostgres>
|
|
{
|
|
private readonly PostgreSqlContainer postgreSql =
|
|
new PostgreSqlBuilder()
|
|
.WithImage("postgis/postgis")
|
|
.WithReuse(true)
|
|
.WithLabel("reuse-id", "squidex-postgres")
|
|
.Build();
|
|
|
|
private IServiceProvider services;
|
|
|
|
public IDbContextFactory<TestDbContextPostgres> DbContextFactory => services.GetRequiredService<IDbContextFactory<TestDbContextPostgres>>();
|
|
|
|
public SqlDialect Dialect => PostgresDialect.Instance;
|
|
|
|
public async Task InitializeAsync()
|
|
{
|
|
await postgreSql.StartAsync();
|
|
|
|
services =
|
|
new ServiceCollection()
|
|
.AddDbContextFactory<TestDbContextPostgres>(b =>
|
|
{
|
|
b.UseNpgsql(postgreSql.GetConnectionString(), options =>
|
|
{
|
|
options.UseNetTopologySuite();
|
|
});
|
|
})
|
|
.AddSingletonAs<DatabaseCreator<TestDbContextPostgres>>().Done()
|
|
.AddSingleton(TestUtils.DefaultSerializer)
|
|
.BuildServiceProvider();
|
|
|
|
foreach (var service in services.GetRequiredService<IEnumerable<IInitializable>>())
|
|
{
|
|
await service.InitializeAsync(default);
|
|
}
|
|
}
|
|
|
|
public async Task DisposeAsync()
|
|
{
|
|
foreach (var service in services.GetRequiredService<IEnumerable<IInitializable>>())
|
|
{
|
|
await service.ReleaseAsync(default);
|
|
}
|
|
|
|
await postgreSql.StopAsync();
|
|
}
|
|
}
|
|
|