Skip to content

Commit 0a11a89

Browse files
authored
Merge branch 'develop' into feat/smtp4dev
2 parents 455e1c9 + 76ce3e0 commit 0a11a89

File tree

26 files changed

+107
-91
lines changed

26 files changed

+107
-91
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project>
33
<PropertyGroup>
44
<PackageId>$(AssemblyName)</PackageId>
5-
<Version>4.3.0</Version>
5+
<Version>4.4.0</Version>
66
<AssemblyVersion>$(Version)</AssemblyVersion>
77
<FileVersion>$(Version)</FileVersion>
88
<Product>Testcontainers</Product>

docs/modules/cassandra.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Apache Cassandra
2+
3+
[Apache Cassandra](https://cassandra.apache.org/) is a powerful, open-source, distributed NoSQL database that is highly available and fault-tolerant, used to store, manage, and retrieve structured data.
4+
5+
Add the following dependency to your project file:
6+
7+
```shell title="NuGet"
8+
dotnet add package Testcontainers.Cassandra
9+
```
10+
11+
You can start an Apache Cassandra container instance from any .NET application. This example uses xUnit.net's `IAsyncLifetime` interface to manage the lifecycle of the container. The container is started in the `InitializeAsync` method before the test method runs, ensuring that the environment is ready for testing. After the test completes, the container is removed in the `DisposeAsync` method.
12+
13+
=== "Usage Example"
14+
```csharp
15+
--8<-- "tests/Testcontainers.Cassandra.Tests/CassandraContainerTest.cs:UseCassandraContainer"
16+
```
17+
18+
The test example uses the following NuGet dependencies:
19+
20+
=== "Package References"
21+
```xml
22+
--8<-- "tests/Testcontainers.Cassandra.Tests/Testcontainers.Cassandra.Tests.csproj:PackageReferences"
23+
```
24+
25+
To execute the tests, use the command `dotnet test` from a terminal.
26+
27+
--8<-- "docs/modules/_call_out_test_projects.txt"

examples/Flyway/Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<ItemGroup>
77
<!-- Unit and integration test dependencies: -->
88
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1"/>
9-
<PackageVersion Include="Testcontainers.PostgreSql" Version="4.0.0"/>
9+
<PackageVersion Include="Testcontainers.PostgreSql" Version="4.2.0"/>
1010
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2"/>
1111
<PackageVersion Include="xunit" Version="2.9.2"/>
1212
<!-- Third-party client dependencies to connect and interact with the containers: -->

examples/Respawn/Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<ItemGroup>
77
<!-- Unit and integration test dependencies: -->
88
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1"/>
9-
<PackageVersion Include="Testcontainers.PostgreSql" Version="4.0.0"/>
9+
<PackageVersion Include="Testcontainers.PostgreSql" Version="4.2.0"/>
1010
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2"/>
1111
<PackageVersion Include="xunit" Version="2.9.2"/>
1212
<!-- Third-party client dependencies to connect and interact with the containers: -->

examples/WeatherForecast/Directory.Packages.props

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
55
</PropertyGroup>
66
<ItemGroup>
7-
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.1"/>
8-
<PackageVersion Include="Microsoft.Fast.Components.FluentUI" Version="3.5.4"/>
9-
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.2"/>
7+
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.13"/>
8+
<PackageVersion Include="Microsoft.Fast.Components.FluentUI" Version="3.5.5"/>
9+
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.11"/>
1010
<!-- Unit and integration test dependencies: -->
11-
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
12-
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.1"/>
13-
<PackageVersion Include="Testcontainers.PostgreSql" Version="3.8.0"/>
14-
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.7"/>
15-
<PackageVersion Include="xunit" Version="2.7.0"/>
11+
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1"/>
12+
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.13"/>
13+
<PackageVersion Include="Testcontainers.PostgreSql" Version="4.2.0"/>
14+
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2"/>
15+
<PackageVersion Include="xunit" Version="2.9.2"/>
1616
<!-- Third-party client dependencies to connect and interact with the containers: -->
1717
<PackageVersion Include="Selenium.WebDriver.ChromeDriver" Version="106.0.5249.6100"/>
1818
<PackageVersion Include="Selenium.WebDriver" Version="4.9.1"/>
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
global using System;
22
global using System.Collections.Generic;
33
global using System.Linq;
4-
global using System.Threading;
54
global using System.Threading.Tasks;
65
global using JetBrains.Annotations;
76
global using WeatherForecast.Entities;

examples/WeatherForecast/src/WeatherForecast/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
builder.Services.AddRazorPages();
55
builder.Services.AddServerSideBlazor();
66

7-
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
7+
var postgreSqlConnectionString = builder.Configuration.GetConnectionString("PostgreSQL");
88

9-
if (string.IsNullOrWhiteSpace(connectionString))
9+
if (string.IsNullOrWhiteSpace(postgreSqlConnectionString))
1010
{
1111
// The application configuration does not include a database connection string, use Testcontainers for .NET to create, start and seed the dependent database.
1212
builder.Services.AddSingleton<DatabaseContainer>();
@@ -20,7 +20,7 @@
2020
else
2121
{
2222
// The application configuration includes a database connection string, use it to establish a connection and seed the database.
23-
builder.Services.AddDbContext<WeatherDataContext>((_, options) => options.UseNpgsql(connectionString));
23+
builder.Services.AddDbContext<WeatherDataContext>((_, options) => options.UseNpgsql(postgreSqlConnectionString));
2424
}
2525

2626
builder.Services.AddScoped<IWeatherDataReadOnlyRepository, WeatherDataReadOnlyContext>();

examples/WeatherForecast/tests/WeatherForecast.InProcess.Tests/Usings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
global using System.Collections.Generic;
33
global using System.Linq;
44
global using System.Net;
5-
global using System.Net.Http;
65
global using System.Text.Json;
76
global using System.Threading.Tasks;
87
global using JetBrains.Annotations;
8+
global using Microsoft.AspNetCore.Hosting;
99
global using Microsoft.AspNetCore.Mvc.Testing;
1010
global using Microsoft.Extensions.DependencyInjection;
1111
global using Testcontainers.PostgreSql;

examples/WeatherForecast/tests/WeatherForecast.InProcess.Tests/WeatherForecastTest.cs

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,19 @@ public Task DisposeAsync()
1515
return _postgreSqlContainer.DisposeAsync().AsTask();
1616
}
1717

18-
public sealed class Api : IClassFixture<WeatherForecastTest>, IDisposable
18+
public sealed class Api : WebApplicationFactory<Program>, IClassFixture<WeatherForecastTest>
1919
{
20-
private readonly WebApplicationFactory<Program> _webApplicationFactory;
21-
22-
private readonly IServiceScope _serviceScope;
23-
24-
private readonly HttpClient _httpClient;
20+
private readonly string _postgreSqlConnectionString;
2521

2622
public Api(WeatherForecastTest weatherForecastTest)
2723
{
28-
// Instead of using environment variables to bootstrap our application configuration, we can implement a custom WebApplicationFactory<TEntryPoint>
29-
// that overrides the ConfigureWebHost(IWebHostBuilder) method to add a WeatherDataContext to the service collection.
30-
Environment.SetEnvironmentVariable("ASPNETCORE_URLS", "https://+");
31-
Environment.SetEnvironmentVariable("ASPNETCORE_Kestrel__Certificates__Default__Path", "certificate.crt");
32-
Environment.SetEnvironmentVariable("ASPNETCORE_Kestrel__Certificates__Default__Password", "password");
33-
Environment.SetEnvironmentVariable("ConnectionStrings__DefaultConnection", weatherForecastTest._postgreSqlContainer.GetConnectionString());
34-
_webApplicationFactory = new WebApplicationFactory<Program>();
35-
_serviceScope = _webApplicationFactory.Services.GetRequiredService<IServiceScopeFactory>().CreateScope();
36-
_httpClient = _webApplicationFactory.CreateClient();
24+
_postgreSqlConnectionString = weatherForecastTest._postgreSqlContainer.GetConnectionString();
3725
}
3826

39-
public void Dispose()
27+
protected override void ConfigureWebHost(IWebHostBuilder builder)
4028
{
41-
_httpClient.Dispose();
42-
_serviceScope.Dispose();
43-
_webApplicationFactory.Dispose();
29+
builder.UseSetting("URLS", "https://+");
30+
builder.UseSetting("ConnectionStrings:PostgreSQL", _postgreSqlConnectionString);
4431
}
4532

4633
[Fact]
@@ -50,8 +37,10 @@ public async Task Get_WeatherForecast_ReturnsSevenDays()
5037
// Given
5138
const string path = "api/WeatherForecast";
5239

40+
using var httpClient = CreateClient();
41+
5342
// When
54-
var response = await _httpClient.GetAsync(path)
43+
var response = await httpClient.GetAsync(path)
5544
.ConfigureAwait(true);
5645

5746
var weatherForecastStream = await response.Content.ReadAsStreamAsync()
@@ -72,7 +61,9 @@ public async Task Get_WeatherForecast_ReturnsThreeDays()
7261
// Given
7362
const int threeDays = 3;
7463

75-
var weatherDataReadOnlyRepository = _serviceScope.ServiceProvider.GetRequiredService<IWeatherDataReadOnlyRepository>();
64+
using var serviceScope = Services.CreateScope();
65+
66+
var weatherDataReadOnlyRepository = serviceScope.ServiceProvider.GetRequiredService<IWeatherDataReadOnlyRepository>();
7667

7768
// When
7869
var weatherForecast = await weatherDataReadOnlyRepository.GetAllAsync(string.Empty, string.Empty, DateTime.Today, DateTime.Today.AddDays(threeDays))

examples/WeatherForecast/tests/WeatherForecast.Tests/WeatherForecastContainer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public WeatherForecastContainer()
2222
{
2323
const string weatherForecastStorage = "weatherForecastStorage";
2424

25-
const string connectionString = $"Host={weatherForecastStorage};Username={PostgreSqlBuilder.DefaultUsername};Password={PostgreSqlBuilder.DefaultPassword};Database={PostgreSqlBuilder.DefaultDatabase}";
25+
const string postgreSqlConnectionString = $"Host={weatherForecastStorage};Username={PostgreSqlBuilder.DefaultUsername};Password={PostgreSqlBuilder.DefaultPassword};Database={PostgreSqlBuilder.DefaultDatabase}";
2626

2727
_weatherForecastNetwork = new NetworkBuilder()
2828
.Build();
@@ -39,7 +39,7 @@ public WeatherForecastContainer()
3939
.WithEnvironment("ASPNETCORE_URLS", "https://+")
4040
.WithEnvironment("ASPNETCORE_Kestrel__Certificates__Default__Path", WeatherForecastImage.CertificateFilePath)
4141
.WithEnvironment("ASPNETCORE_Kestrel__Certificates__Default__Password", WeatherForecastImage.CertificatePassword)
42-
.WithEnvironment("ConnectionStrings__DefaultConnection", connectionString)
42+
.WithEnvironment("ConnectionStrings__PostgreSQL", postgreSqlConnectionString)
4343
.WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(WeatherForecastImage.HttpsPort))
4444
.Build();
4545
}

0 commit comments

Comments
 (0)