How to use TUnit.Aspire with custom environment variables #4973
-
|
I need to pass custom environment variables to my AppHost so that my db uses Session lifetime and doesn't get reused. public class Fixture : AspireFixture<AppHost>
{
protected override Task WaitForResourcesAsync(DistributedApplication app, CancellationToken cancellationToken) =>
app.ResourceNotifications.WaitForResourceHealthyAsync("api", cancellationToken)
.WithTimeout(TimeSpan.FromSeconds(60));
public override async Task InitializeAsync()
{
// This will work, but now I can't use `base.App` anymore, as well as any other functionality from the base class..
var appHost = await DistributedApplicationTestingBuilder.CreateAsync<AppHost>([
"UseVolumes=false",
"UsePostgresWithPersistentLifetime=false",
"UsePostgresWithSessionLifetime=true"
]);
ConfigureBuilder(appHost);
}
protected override void ConfigureBuilder(IDistributedApplicationTestingBuilder builder)
{
// These calls will not work, since `ConfigureBuilder` is called after DistributedApplicationTestingBuilder.CreateAsync
builder.Configuration["UseVolumes"] = "false";
builder.Configuration["UsePostgresWithPersistentLifetime"] = "false";
builder.Configuration["UsePostgresWithSessionLifetime"] = "true";
// ...
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
@toni-schmitt I've just pushed an update that lets you set your own overrideable public class AppFixture : AspireFixture<Projects.MyAppHost>
{
protected override string[] Args =>
[
"--UseVolumes=false",
"--UsePostgresWithPersistentLifetime=false",
"--UsePostgresWithSessionLifetime=true"
];
} |
Beta Was this translation helpful? Give feedback.
@toni-schmitt I've just pushed an update that lets you set your own overrideable
Argsproperty