microsoft / microsoft/aspire

Starting a resource (WithExplicitStart) in Aspire tests

Open
#8,111 5 comments 0 reactions 0 assignees View on GitHub
area-app-testing
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] 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
```csharp 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
```csharp
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();

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:
```csharp
await appHost.StartResourceAsync(name: "explicit-start-resource-name");
```

### Additional context

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.