dotnet / aspire

Tools, templates, and packages to accelerate building observable, production-ready apps
https://learn.microsoft.com/dotnet/aspire
MIT License
3.93k stars 480 forks source link

Expose `ResourceNotificationService` directly on `DistributedApplicationTestingBuilder` #6795

Open afscrome opened 11 hours ago

afscrome commented 11 hours ago

Is there an existing issue for this?

Is your feature request related to a problem? Please describe the problem.

I've found that I'm using ResourceNotificationService a lot in tests using DistributedApplicationTestingBuilder, and wonder if it's something worth exposing directly, rather than being hidden behind a GetRequiredService call.

Or perhaps rather than exposing ResourceNotificationService, expose something that's little more suited for the automated tests. E.g. a version of WaitForResourceAsync that fails fast if a resource goes to a terminal state, as opposed to the version in ResourceNotificationService which continues to wait as it's possible as it's possible the service starts again at a later date.

Describe the solution you'd like

        var appHost = await DistributedApplicationTestingBuilder.CreateAsync<Projects.AspireApp2_AppHost>();
        await using var app = await appHost.BuildAsync();
        await app.StartAsync();

        await appHost.ResourceNotificationService.WaitForResourceAsync("whatever");
        // Or possibly something more like:
        await appHost.WaitFor*("whatever");

Additional context

No response