Open
Description
It would be useful to be able to stop a running resource in a testing scenario for the purposes of verifying behavior when dependencies aren't running. I imagine this would be a method on DistributedApplication
or perhaps a new type that can be resolved from the DI container to allow stopping a resource. DCP already supports stopping resources it started.
e.g.:
[Fact]
public async Task HomePageReturnsOkIfRedisIsUnavailable()
{
var appHost = await DistributedApplicationTestingBuilder.CreateAsync<Program>();
await using var app = await appHost.BuildAsync();
await app.StartAsync();
var httpClient = app.CreateHttpClient("webfrontend");
await httpClient.GetStringAsync("/"); // This will retry until the webfrontend has started successfully
await app.StopResourceAsync("cache"); // Now stop the cache container
var response = await httpClient.GetAsync("/");
Assert.Equal(HttpStatus.OK, response.StatusCode);
}