Replies: 3 comments 2 replies
-
I was able to successfully run my app service tests by modifying [DependsOn(
typeof(SampleTestBaseModule),
typeof(SampleEntityFrameworkCoreModule),
typeof(AbpEntityFrameworkCorePostgreSqlModule)
)]
public class SampleEntityFrameworkCoreTestModule : AbpModule
{
private readonly PostgreSqlContainer _postgreSqlContainer = new PostgreSqlBuilder().Build();
public override void PreConfigureServices(ServiceConfigurationContext context)
{
_postgreSqlContainer.StartAsync().GetAwaiter().GetResult();
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
var connectionString = _postgreSqlContainer.GetConnectionString();
new SampleDbContext(
new DbContextOptionsBuilder<SampleDbContext>().UseNpgsql(connectionString).Options
).GetService<IRelationalDatabaseCreator>().CreateTables();
Configure<AbpDbContextOptions>(options =>
{
options.Configure(abpDbContextConfigurationContext =>
{
abpDbContextConfigurationContext.DbContextOptions.UseNpgsql(connectionString);
});
});
}
public override void OnApplicationShutdown(ApplicationShutdownContext context)
{
_postgreSqlContainer.StopAsync().GetAwaiter().GetResult();
} (side note: I tried to use the async versions of the overridden methods, If you think I'm doing something wrong please say so in the comments. Thanks. |
Beta Was this translation helpful? Give feedback.
-
I know it's old but it might be helpful to anyone else private readonly PostgreSqlContainer _postgreSqlContainer = new PostgreSqlBuilder()
.WithImage("postgres:15.2")
.Build(); |
Beta Was this translation helpful? Give feedback.
-
The best method I found is to follow the same architecture used in MongoDB tests, which is using xunit's for example: (make sure you replace in
|
Beta Was this translation helpful? Give feedback.
-
Please help me setup ABP's
ApplicationTestModule
so that I can use Test Containers and PostgresHere is an article which has samples for "ASP.NET Core Integration Tests with Test Containers & Postgres". Can anyone point out how to modify
ApplicationTestModule
orEntityFrameworkCoreTestModule
(orApplicationTestBase
orEntityFrameworkCoreTestBase
) so it uses Test Containers instead of in memory Sqlite?Beta Was this translation helpful? Give feedback.
All reactions