Přeskočit na hlavní obsah

Test support Testcontainers

Overview

Contains base utilities for building testcontainer-based integration tests.

Install

  • ASOL.Core.QA.TestSupport.Testcontainers

WithEnvironmentIfNotEmpty

ContainerBuilderExtensions.WithEnvironmentIfNotEmpty is a helper extension on IContainerBuilder that conditionally sets an environment variable only when the provided value is not null. This prevents unintentional overrides of default container configuration when an optional setting is absent.

Signature

public static TBuilderEntity WithEnvironmentIfNotEmpty<TBuilderEntity, TContainerEntity, TConfigurationEntity>(
this IContainerBuilder<TBuilderEntity, TContainerEntity, TConfigurationEntity> builder,
string name,
string? value)
ParameterDescription
builderThe container builder instance.
nameThe name of the environment variable to set.
valueThe value to assign. If null, the method is a no-op and returns the builder unchanged.

Usage

builder = builder
.WithEnvironmentIfNotEmpty("MySection__DatabaseName", options?.DatabaseName);