Skip to content

Commit

Permalink
Merge branch 'develop' into introduce-janusgraph-module
Browse files Browse the repository at this point in the history
  • Loading branch information
rngcntr authored Mar 23, 2023
2 parents 6301020 + 710987a commit f6dd6ba
Show file tree
Hide file tree
Showing 63 changed files with 880 additions and 560 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
run: dotnet cake --target=Build

- name: Run Tests
run: dotnet cake --target=Tests --test-filter=FullyQualifiedName~${{ startsWith(matrix.os, 'ubuntu') && 'Testcontainers' || 'DotNet.Testcontainers.Tests.Unit.Containers.Windows' }}
run: dotnet cake --target=Tests --test-filter=${{ startsWith(matrix.os, 'ubuntu') && 'FullyQualifiedName~Testcontainers' || 'DockerPlatform=Windows' }}

- name: Upload Test And Coverage Results
uses: actions/upload-artifact@v3
Expand Down
1 change: 0 additions & 1 deletion Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@
<PackageReference Update="Azure.Data.Tables" Version="12.6.1" />
<PackageReference Update="Azure.Storage.Blobs" Version="12.13.0" />
<PackageReference Update="Azure.Storage.Queues" Version="12.11.0" />
<PackageReference Update="Microsoft.Azure.Cosmos" Version="3.30.0" />
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions Testcontainers.dic
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ httpd
identitytoken
initdb
isready
kubeconfig
lipsum
ltsc
memopt
Expand Down
26 changes: 26 additions & 0 deletions Testcontainers.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{673F23AE-769
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.CosmosDb", "src\Testcontainers.CosmosDb\Testcontainers.CosmosDb.csproj", "{A724806F-8C94-4438-8011-04A9A1575318}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Couchbase", "src\Testcontainers.Couchbase\Testcontainers.Couchbase.csproj", "{58E94721-2681-4D82-8D94-0B2F9DB0D575}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.CouchDb", "src\Testcontainers.CouchDb\Testcontainers.CouchDb.csproj", "{DCECB1F6-D9AA-431F-AE42-25D56B9E7DFC}"
Expand All @@ -24,6 +26,7 @@ EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.EventStoreDb", "src\Testcontainers.EventStoreDb\Testcontainers.EventStoreDb.csproj", "{84D707E0-C9FA-4327-85DC-0AFEBEA73572}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.JanusGraph", "src\Testcontainers.JanusGraph\Testcontainers.JanusGraph.csproj", "{C5AF86A8-2F11-41B6-BB01-325AD9016B94}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.K3s", "src\Testcontainers.K3s\Testcontainers.K3s.csproj", "{111B840F-9DB0-4166-83E6-0580FD418F07}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Kafka", "src\Testcontainers.Kafka\Testcontainers.Kafka.csproj", "{E93E40CE-59AA-4561-9B4C-E7B0A686326E}"
EndProject
Expand Down Expand Up @@ -61,6 +64,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers", "src\Testc
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Commons", "tests\Testcontainers.Commons\Testcontainers.Commons.csproj", "{2478673C-B063-469D-ABD1-0C3E0A25541B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.CosmosDb.Tests", "tests\Testcontainers.CosmosDb.Tests\Testcontainers.CosmosDb.Tests.csproj", "{BD445A54-F411-4758-955E-397A1E98680C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Couchbase.Tests", "tests\Testcontainers.Couchbase.Tests\Testcontainers.Couchbase.Tests.csproj", "{809322BA-D690-4F2B-B884-23F895663963}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.CouchDb.Tests", "tests\Testcontainers.CouchDb.Tests\Testcontainers.CouchDb.Tests.csproj", "{E4520FB1-4466-4DCA-AD08-4075102C68D3}"
Expand All @@ -72,6 +77,7 @@ EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.EventStoreDb.Tests", "tests\Testcontainers.EventStoreDb.Tests\Testcontainers.EventStoreDb.Tests.csproj", "{64F8E9B9-78FD-4E13-BDDF-0340E2D4E1D0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.JanusGraph.Tests", "tests\Testcontainers.JanusGraph.Tests\Testcontainers.JanusGraph.Tests.csproj", "{BEFC4109-4511-4FBD-AC4F-3D3B388B8CAD}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.K3s.Tests", "tests\Testcontainers.K3s.Tests\Testcontainers.K3s.Tests.csproj", "{F0F40AE2-70FF-4191-ADDA-26A19E0D1A0F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Kafka.Tests", "tests\Testcontainers.Kafka.Tests\Testcontainers.Kafka.Tests.csproj", "{6F2AEE03-629A-4B49-BD5B-25CA3C61FFB7}"
EndProject
Expand Down Expand Up @@ -122,6 +128,10 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A724806F-8C94-4438-8011-04A9A1575318}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A724806F-8C94-4438-8011-04A9A1575318}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A724806F-8C94-4438-8011-04A9A1575318}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A724806F-8C94-4438-8011-04A9A1575318}.Release|Any CPU.Build.0 = Release|Any CPU
{58E94721-2681-4D82-8D94-0B2F9DB0D575}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{58E94721-2681-4D82-8D94-0B2F9DB0D575}.Debug|Any CPU.Build.0 = Debug|Any CPU
{58E94721-2681-4D82-8D94-0B2F9DB0D575}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -146,6 +156,10 @@ Global
{C5AF86A8-2F11-41B6-BB01-325AD9016B94}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C5AF86A8-2F11-41B6-BB01-325AD9016B94}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C5AF86A8-2F11-41B6-BB01-325AD9016B94}.Release|Any CPU.Build.0 = Release|Any CPU
{111B840F-9DB0-4166-83E6-0580FD418F07}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{111B840F-9DB0-4166-83E6-0580FD418F07}.Debug|Any CPU.Build.0 = Debug|Any CPU
{111B840F-9DB0-4166-83E6-0580FD418F07}.Release|Any CPU.ActiveCfg = Release|Any CPU
{111B840F-9DB0-4166-83E6-0580FD418F07}.Release|Any CPU.Build.0 = Release|Any CPU
{E93E40CE-59AA-4561-9B4C-E7B0A686326E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E93E40CE-59AA-4561-9B4C-E7B0A686326E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E93E40CE-59AA-4561-9B4C-E7B0A686326E}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -218,6 +232,10 @@ Global
{2478673C-B063-469D-ABD1-0C3E0A25541B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2478673C-B063-469D-ABD1-0C3E0A25541B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2478673C-B063-469D-ABD1-0C3E0A25541B}.Release|Any CPU.Build.0 = Release|Any CPU
{BD445A54-F411-4758-955E-397A1E98680C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BD445A54-F411-4758-955E-397A1E98680C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BD445A54-F411-4758-955E-397A1E98680C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BD445A54-F411-4758-955E-397A1E98680C}.Release|Any CPU.Build.0 = Release|Any CPU
{809322BA-D690-4F2B-B884-23F895663963}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{809322BA-D690-4F2B-B884-23F895663963}.Debug|Any CPU.Build.0 = Debug|Any CPU
{809322BA-D690-4F2B-B884-23F895663963}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -242,6 +260,10 @@ Global
{BEFC4109-4511-4FBD-AC4F-3D3B388B8CAD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BEFC4109-4511-4FBD-AC4F-3D3B388B8CAD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BEFC4109-4511-4FBD-AC4F-3D3B388B8CAD}.Release|Any CPU.Build.0 = Release|Any CPU
{F0F40AE2-70FF-4191-ADDA-26A19E0D1A0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F0F40AE2-70FF-4191-ADDA-26A19E0D1A0F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F0F40AE2-70FF-4191-ADDA-26A19E0D1A0F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F0F40AE2-70FF-4191-ADDA-26A19E0D1A0F}.Release|Any CPU.Build.0 = Release|Any CPU
{6F2AEE03-629A-4B49-BD5B-25CA3C61FFB7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6F2AEE03-629A-4B49-BD5B-25CA3C61FFB7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6F2AEE03-629A-4B49-BD5B-25CA3C61FFB7}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -324,12 +346,14 @@ Global
{EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{A724806F-8C94-4438-8011-04A9A1575318} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{58E94721-2681-4D82-8D94-0B2F9DB0D575} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{DCECB1F6-D9AA-431F-AE42-25D56B9E7DFC} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{2EAFA567-9F68-4C52-9DBC-8F3EC11BB2CE} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{641DDEA5-B6E0-41E6-BA11-7A28C0913127} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{84D707E0-C9FA-4327-85DC-0AFEBEA73572} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{C5AF86A8-2F11-41B6-BB01-325AD9016B94} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{111B840F-9DB0-4166-83E6-0580FD418F07} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{E93E40CE-59AA-4561-9B4C-E7B0A686326E} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{3792268A-EF08-4569-8118-991E08FD61C4} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{4B204EB3-C478-422E-9B6F-62DF3871291A} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
Expand All @@ -348,12 +372,14 @@ Global
{64A87DE5-29B0-4A54-9E74-560484D8C7C0} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{EC76857B-A3B8-4B7A-A1B0-8D867A4D1733} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{2478673C-B063-469D-ABD1-0C3E0A25541B} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{BD445A54-F411-4758-955E-397A1E98680C} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{809322BA-D690-4F2B-B884-23F895663963} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{E4520FB1-4466-4DCA-AD08-4075102C68D3} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{101515E6-74C1-40F9-85C8-871F742A378D} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{DD5B3678-468F-4D73-AECE-705E3D66CD43} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{64F8E9B9-78FD-4E13-BDDF-0340E2D4E1D0} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{BEFC4109-4511-4FBD-AC4F-3D3B388B8CAD} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{F0F40AE2-70FF-4191-ADDA-26A19E0D1A0F} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{6F2AEE03-629A-4B49-BD5B-25CA3C61FFB7} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{728CBE16-1D52-4F84-AF01-7229E6013512} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{7F0AE083-9DB8-4BD4-91F7-C199DCC7301D} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
Expand Down
1 change: 1 addition & 0 deletions Testcontainers.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=identitytoken/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=initdb/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=isready/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=kubeconfig/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=lipsum/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ltsc/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=memopt/@EntryIndexedValue">True</s:Boolean>
Expand Down
29 changes: 16 additions & 13 deletions docs/examples/aspnet.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
# ASP.NET Core Blazor

No matter if your tests require databases, message brokers, your own services or even a running instance of your entire application, leveraging Testcontainers in your tests means you can set up the infrastructure fast and reliably. You can also run tests in parallel against multiple lightweight or a single shared heavyweight instance, depending on the use case. xUnit.net’s [shared context][xunit-shared-context] offers several methods to access resources efficiently among different tests and scopes.
No matter if your tests require databases, message brokers, your own services or even a running instance of your entire application, leveraging Testcontainers in your tests means you can set up the infrastructure fast and reliably. You can also run tests in parallel against multiple lightweight or a single shared heavyweight instance, depending on the use case. xUnit.net’s [shared context](https://xunit.net/docs/shared-context) offers several methods to access resources efficiently among different tests and scopes.

The following example adds tests to an ASP.NET Core Blazor application. The tests cover the web front-end including the REST API of a weather forecast application. Testcontainers builds and ships our app in a Docker image, runs it in a Docker container, orchestrates the necessary resources, and executes the tests against it. This setup includes a Microsoft SQL Server to persist data and covers a common use case among many productive .NET applications. You find the entire example in the [testcontainers-dotnet][testcontainers-dotnet-weather-forecast-example] repository.
The following example adds tests to an ASP.NET Core Blazor application. The tests cover the web front-end including the REST API of a weather forecast application. Testcontainers builds and ships our app in a Docker image, runs it in a Docker container, orchestrates the necessary resources, and executes the tests against it. This setup includes a Microsoft SQL Server to persist data and covers a common use case among many productive .NET applications. You find the entire example in the [testcontainers-dotnet](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/examples/WeatherForecast) repository.

To use Testcontainers' pre-configured Microsoft SQL Server module, add the [Testcontainers.MsSql](https://www.nuget.org/packages/Testcontainers.MsSql) NuGet dependency to your test project:

```console
dotnet add package Testcontainers.MsSql --version 3.0.0
```

!!! note

The Microsoft SQL Server Docker image is not compatible with ARM devices, such as Macs with Apple Silicon. Instead, you can use the [SqlEdge](https://www.nuget.org/packages/Testcontainers.SqlEdge) module or [Testcontainers Cloud](https://www.testcontainers.cloud/).

The `WeatherForecastContainer` class configures in the default constructor all dependencies to start the container that hosts our application.

```csharp
const string weatherForecastStorage = "weatherForecastStorage";

var mssqlConfiguration = new MsSqlTestcontainerConfiguration();
mssqlConfiguration.Password = Guid.NewGuid().ToString("D");
mssqlConfiguration.Database = Guid.NewGuid().ToString("D");

var connectionString = $"server={weatherForecastStorage};user id=sa;password={mssqlConfiguration.Password};database={mssqlConfiguration.Database}";
const string connectionString = $"server={weatherForecastStorage};user id={MsSqlBuilder.DefaultUsername};password={MsSqlBuilder.DefaultPassword};database={MsSqlBuilder.DefaultDatabase}";

_weatherForecastNetwork = new NetworkBuilder()
.WithName(Guid.NewGuid().ToString("D"))
.Build();

_mssqlContainer = new ContainerBuilder<MsSqlTestcontainer>()
.WithDatabase(mssqlConfiguration)
_msSqlContainer = new MsSqlBuilder()
.WithNetwork(_weatherForecastNetwork)
.WithNetworkAliases(weatherForecastStorage)
.Build();
Expand All @@ -46,7 +50,7 @@ await Image.InitializeAsync()
await _weatherForecastNetwork.CreateAsync()
.ConfigureAwait(false);

await _mssqlContainer.StartAsync()
await _msSqlContainer.StartAsync()
.ConfigureAwait(false);

await _weatherForecastContainer.StartAsync()
Expand All @@ -57,5 +61,4 @@ xUnit.net passes the `WeatherForecastContainer` class fixture instance to the te

As soon as the container is up and the application is running, each test sends an HTTP request to the weather forecast application and validates the REST or web front-end response. To visualize the web front-end, Selenium takes a screenshot right before and after the test.

[xunit-shared-context]: https://xunit.net/docs/shared-context
[testcontainers-dotnet-weather-forecast-example]: https://github.com/testcontainers/testcontainers-dotnet/tree/develop/examples/WeatherForecast
Testcontainers not only works great for testing an application or service out-of-process, as shown in the example above, but it is probably even better for testing it in-process as shown in [this](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/examples/WeatherForecast/tests/WeatherForecast.InProcess.Tests) example. When used in conjunction with the ASP.NET `WebApplicationFactory<TEntryPoint>` class, Testcontainers spins up the dependent container together with the application, resulting in much faster tests. Depending on the application or service configuration, adding Testcontainers to bootstrap dependent services significantly improves the development experience. There is no longer a need to ensure that dependent services are running and wired up correctly on the development machine or CI environment.
2 changes: 1 addition & 1 deletion docs/examples/compose.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ it is necessary to override Testcontainers' Docker host resolution and set the e
Otherwise, Testcontainers cannot access sibling containers like the Resource Reaper Ryuk or other services running on the Docker host.
A minimal `docker-compose.yml` file that builds a new container image and runs the test inside the container look something like:

```Yaml
```yaml
version: "3"
services:
docker_compose_test:
Expand Down
19 changes: 19 additions & 0 deletions docs/modules/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@

Modules are great examples of Testcontainers' capabilities. To write tests against real dependencies, you can either choose one of the pre-configurations listed below or create your own implementation.

Modules are standalone dependencies that can be installed from [NuGet.org](https://www.nuget.org/profiles/Testcontainers). To use a module in your test project, you need to add it as a dependency first:

```console
dotnet add package Testcontainers.ModuleName
```

All modules follow the same design and come pre-configured with best practices. Usually, you do not need to worry about configuring them yourself. To create and start a container, all you need is:

```csharp
var moduleNameContainer = new ModuleNameBuilder().Build();

await moduleNameContainer.StartAsync()
.ConfigureAwait(false);
```

!!! note

We will be add module-specific documentations soon.

| Module | Image | NuGet | Source |
|---------------|---------------------------------------------------------|----------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------|
| Couchbase | `couchbase:community-7.0.2` | [NuGet](https://www.nuget.org/packages/Testcontainers.Couchbase) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Couchbase) |
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/postgres.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# PostgreSQL

Here is an example of a pre-configured PostgreSQL container. In the example, Testcontainers starts a PostgreSQL database in a [xUnit.net][xunit] test and executes a SQL query against it.
Here is an example of a pre-configured PostgreSQL module. In the example, Testcontainers starts a PostgreSQL database in a [xUnit.net][xunit] test and executes a SQL query against it.

```csharp
public sealed class PostgreSqlContainerTest : IAsyncLifetime
Expand Down
3 changes: 2 additions & 1 deletion examples/WeatherForecast/src/WeatherForecast/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

if (string.IsNullOrWhiteSpace(connectionString))
{
// No database connection string is available. Start and seed a database using Testcontainers for .NET first.
// The application configuration does not include a database connection string, use Testcontainers for .NET to create, start and seed the dependent database.
builder.Services.AddSingleton<DatabaseContainer>();
builder.Services.AddHostedService(services => services.GetRequiredService<DatabaseContainer>());
builder.Services.AddDbContext<WeatherDataContext>((services, options) =>
Expand All @@ -29,6 +29,7 @@
}
else
{
// The application configuration includes a database connection string, use it to establish a connection and seed the database.
builder.Services.AddDbContext<WeatherDataContext>((_, options) => options.UseSqlServer(connectionString));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public sealed class Api : IClassFixture<WeatherForecastTest>, IDisposable

public Api(WeatherForecastTest weatherForecastTest)
{
// Instead of using environment variables to bootstrap our application configuration, we can implement a custom WebApplicationFactory<TEntryPoint>
// that overrides the ConfigureWebHost(IWebHostBuilder) method to add a WeatherDataContext to the service collection.
Environment.SetEnvironmentVariable("ASPNETCORE_URLS", "https://+");
Environment.SetEnvironmentVariable("ASPNETCORE_Kestrel__Certificates__Default__Path", "certificate.crt");
Environment.SetEnvironmentVariable("ASPNETCORE_Kestrel__Certificates__Default__Password", "password");
Expand Down
Loading

0 comments on commit f6dd6ba

Please sign in to comment.