Skip to content

Commit

Permalink
Merge pull request #84 from netcorepal/ci
Browse files Browse the repository at this point in the history
fix ci , UseNpgsql
  • Loading branch information
witskeeper authored Sep 20, 2024
2 parents 4156f4d + becb944 commit dc51c60
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 28 deletions.
18 changes: 9 additions & 9 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<FrameworkVersion>9.0.0-rc.1.24452.1</FrameworkVersion>
<ExtensionsVersion>9.0.0-rc.1.24431.7</ExtensionsVersion>
<EntityFrameworkVersion>9.0.0-rc.1.24451.1</EntityFrameworkVersion>
<NpgsqlEntityFrameworkCorePostgreSQLVersion>9.0.0-preview.1</NpgsqlEntityFrameworkCorePostgreSQLVersion>
<NpgsqlEntityFrameworkCorePostgreSQLVersion>9.0.0-rc.1</NpgsqlEntityFrameworkCorePostgreSQLVersion>
<PomeloVersion>9.0.0-preview.1</PomeloVersion>
</PropertyGroup>
<ItemGroup>
Expand Down Expand Up @@ -97,14 +97,14 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Update="Testcontainers.K3s" Version="3.6.0" />
<PackageReference Update="Testcontainers" Version="3.6.0" />
<PackageReference Update="Testcontainers.PostgreSql" Version="3.6.0" />
<PackageReference Update="Testcontainers.RabbitMq" Version="3.6.0" />
<PackageReference Update="Testcontainers.Redis" Version="3.6.0" />
<PackageReference Update="Testcontainers.Consul" Version="3.6.0" />
<PackageReference Update="Testcontainers.MySql" Version="3.6.0"/>
<PackageReference Update="Testcontainers.MsSql" Version="3.6.0"/>
<PackageReference Update="Testcontainers.K3s" Version="3.10.0" />
<PackageReference Update="Testcontainers" Version="3.10.0" />
<PackageReference Update="Testcontainers.PostgreSql" Version="3.10.0" />
<PackageReference Update="Testcontainers.RabbitMq" Version="3.10.0" />
<PackageReference Update="Testcontainers.Redis" Version="3.10.0" />
<PackageReference Update="Testcontainers.Consul" Version="3.10.0" />
<PackageReference Update="Testcontainers.MySql" Version="3.10.0"/>
<PackageReference Update="Testcontainers.MsSql" Version="3.10.0"/>
<PackageReference Update="Backport.System.Threading.Lock" Version="2.0.0"/>
</ItemGroup>
</Project>
25 changes: 13 additions & 12 deletions test/NetCorePal.Web.UnitTests/MyWebApplicationFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,21 @@ public class MyWebApplicationFactory : WebApplicationFactory<Program>, IAsyncLif
// private readonly PostgreSqlContainer postgreSqlContainer = new PostgreSqlBuilder()
// .WithUsername("postgres").WithPassword("123456")
// .WithDatabase("demo").Build();

#if NET9_0
private readonly PostgreSqlContainer pgSqlContainer = new PostgreSqlBuilder().Build();
#else
private readonly MySqlContainer mySqlContainer = new MySqlBuilder()
.WithUsername("root").WithPassword("123456")
.WithEnvironment("TZ", "Asia/Shanghai")
.WithDatabase("demo").Build();

#if NET9_0
private readonly MsSqlContainer msSqlContainer = new MsSqlBuilder().Build();
#endif

protected override void ConfigureWebHost(IWebHostBuilder builder)
{
//builder.UseSetting("ConnectionStrings:PostgreSQL", postgreSqlContainer.GetConnectionString());
builder.UseSetting("ConnectionStrings:MySql",
mySqlContainer.GetConnectionString().Replace("demo", $"demo"));
#if NET9_0
builder.UseSetting("ConnectionStrings:MsSql", msSqlContainer.GetConnectionString());
builder.UseSetting("ConnectionStrings:PostgreSql", pgSqlContainer.GetConnectionString());
#else
builder.UseSetting("ConnectionStrings:MySql", mySqlContainer.GetConnectionString());
#endif
builder.UseSetting("ConnectionStrings:Redis", redisContainer.GetConnectionString());
builder.UseSetting("RabbitMQ:HostName", rabbitMqContainer.Hostname);
Expand All @@ -51,19 +50,21 @@ public Task InitializeAsync()
return Task.WhenAll(redisContainer.StartAsync(),
rabbitMqContainer.StartAsync(),
#if NET9_0
msSqlContainer.StartAsync(),
#endif
pgSqlContainer.StartAsync());
#else
mySqlContainer.StartAsync());
#endif
}

public new Task DisposeAsync()
{
return Task.WhenAll(redisContainer.StopAsync(),
rabbitMqContainer.StopAsync(),
#if NET9_0
msSqlContainer.StopAsync(),
#endif
pgSqlContainer.StopAsync());
#else
mySqlContainer.StopAsync());
#endif
}
}
}
5 changes: 2 additions & 3 deletions test/NetCorePal.Web/NetCorePal.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'net9.0'">
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" />
<ProjectReference Include="..\..\src\DistributedTransactions.CAP.MySql\NetCorePal.Extensions.DistributedTransactions.CAP.MySql.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" />
<ProjectReference Include="..\..\src\DistributedTransactions.CAP.SqlServer\NetCorePal.Extensions.DistributedTransactions.CAP.SqlServer.csproj" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" />
<ProjectReference Include="..\..\src\DistributedTransactions.CAP.PostgreSql\NetCorePal.Extensions.DistributedTransactions.CAP.PostgreSql.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 2 additions & 3 deletions test/NetCorePal.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,8 @@
builder.Services.AddDbContext<ApplicationDbContext>(options =>
{
#if NET9_0
options.UseSqlServer(builder.Configuration.GetConnectionString("MsSql"));
options.UseNpgsql(builder.Configuration.GetConnectionString("PostgreSql"));
#else
//options.UseNpgsql(builder.Configuration.GetConnectionString("PostgreSQL"));
options.UseMySql(builder.Configuration.GetConnectionString("Mysql"),
new MySqlServerVersion(new Version(8, 0, 34)),
b => { b.MigrationsAssembly(typeof(Program).Assembly.FullName); });
Expand All @@ -108,7 +107,7 @@

builder.Services.AddUnitOfWork<ApplicationDbContext>();
#if NET9_0
builder.Services.AddSqlServerTransactionHandler();
builder.Services.AddPostgreSqlTransactionHandler();
#else
//builder.Services.AddPostgreSqlTransactionHandler();
builder.Services.AddMySqlTransactionHandler();
Expand Down
2 changes: 1 addition & 1 deletion test/NetCorePal.Web/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"ConnectionStrings": {
"Redis": "",
"Postgres": "",
"PostgreSql": "",
"MsSql": ""
},
"RabbitMQ": {
Expand Down

0 comments on commit dc51c60

Please sign in to comment.