Skip to content

Starting a resource (WithExplicitStart) in Aspire tests #8111

Open
@m03chv13h

Description

@m03chv13h

Is there an existing issue for this?

  • I have searched the existing issues

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

Maybe there is already a solution for that but I cannot find it.

I want to start my resource via the code in the tests which I added with .WithExplicitStart() in my AppHost Program.cs file.

Program.cs

// ...
builder.AddExecutable("explicit-start-resource-name", ...)
    .WithExplicitStart();
// ...

In my tests I start the app host and want to start this resource manually via the code.

AppHostTests.cs

public class AppHostTests
{
    private static readonly TimeSpan BuildStopTimeout = TimeSpan.FromSeconds(15);
    private static readonly TimeSpan StartStopTimeout = TimeSpan.FromSeconds(120);

    [Fact]
    public async Task Test_ExplicitStartResource()
    {
        // Act
        var appHostBuilder = await DistributedApplicationTestingBuilder.CreateAsync<Projects.AppHost>();
        
        await using var appHost = await appHostBuilder.BuildAsync().WaitAsync(BuildStopTimeout);
        
        await appHost.StartAsync().WaitAsync(StartStopTimeout);
        
        // Some code here.

        // Arrange
        // Now I want to start the resource with a specific name.
        // For example: await appHost.StartResourceAsync(name: "explicit-start-resource-name");

        // Assert
    }
}

How can I do that? Is there already a possibility for example with the ResourceNotificationService?

Describe the solution you'd like

For example:

await appHost.StartResourceAsync(name: "explicit-start-resource-name");

Additional context

Aspire.Hosting.AppHost 9.1.0
Aspire.Hosting.Testing 9.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-app-testingIssues pertaining to the APIs in Aspire.Hosting.Testing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions