Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v4
- name: Run tests
run: dotnet test ./Packages.sln --configuration Release
run: dotnet test --project ./ProjectCommander.UnitTests/ProjectCommander.UnitTests.csproj --configuration Release

deploy:
# Publish only when creating a GitHub Release
Expand Down
38 changes: 0 additions & 38 deletions ProjectCommander.Tests/IntegrationTest1.cs

This file was deleted.

19 changes: 12 additions & 7 deletions ProjectCommander.Tests/ProjectCommander.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting.Testing" Version="13.1.1" />
<PackageReference Include="coverlet.collector" Version="6.0.4">
<PackageReference Include="Aspire.Hosting.Testing" Version="17.0.0" />
<PackageReference Include="coverlet.collector" Version="10.1.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.12.0" />
<PackageReference Include="Moq" Version="4.21.0" />
<PackageReference Include="xunit.v3" Version="4.0.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="4.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand All @@ -30,4 +31,8 @@
<Using Include="Xunit" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Sample\ProjectCommander.AppHost\ProjectCommander.AppHost.csproj" />
</ItemGroup>

</Project>
93 changes: 93 additions & 0 deletions ProjectCommander.Tests/ProjectCommanderEndToEndTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using Aspire.Hosting;
using CommunityToolkit.Aspire.Hosting.ProjectCommander;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Moq;

namespace ProjectCommander.Tests;

public sealed class ProjectCommanderEndToEndTests
{
[Fact]
public async Task StartupFormAndCommandsReachRunningProjects()
{
using var timeout = CancellationTokenSource.CreateLinkedTokenSource(TestContext.Current.CancellationToken);
timeout.CancelAfter(TimeSpan.FromMinutes(5));
var cancellationToken = timeout.Token;

var interactionService = new Mock<IInteractionService>();
interactionService
.Setup(service => service.PromptInputsAsync(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<IReadOnlyList<InteractionInput>>(),
It.IsAny<InputsDialogInteractionOptions>(),
It.IsAny<CancellationToken>()))
.ReturnsAsync(InteractionResult.Ok(new InteractionInputCollection(
[
new InteractionInput { Name = "initialDelay", InputType = InputType.Number, Value = "1" },
new InteractionInput { Name = "mode", InputType = InputType.Choice, Value = "Continuous" }
])));

var builder = await DistributedApplicationTestingBuilder.CreateAsync<Projects.ProjectCommander_AppHost>([], cancellationToken);
builder.Services.RemoveAll<IInteractionService>();
builder.Services.AddSingleton(interactionService.Object);

await using var app = await builder.BuildAsync(cancellationToken);
var applicationStart = app.StartAsync(cancellationToken);

var notifications = app.Services.GetRequiredService<ResourceNotificationService>();
await notifications.WaitForResourceAsync("consumer", KnownResourceStates.Running, cancellationToken);
await notifications.WaitForResourceAsync(
"datagenerator-config",
StartupFormResource.WaitingForConfigurationState,
cancellationToken);

var model = app.Services.GetRequiredService<DistributedApplicationModel>();
var loggerService = app.Services.GetRequiredService<ResourceLoggerService>();
var consumer = model.Resources.Single(resource => resource.Name == "consumer");
var dataGenerator = model.Resources.Single(resource => resource.Name == "datagenerator");
var startupForm = model.Resources.OfType<StartupFormResource>().Single();

var consumerEventLog = WaitForLogAsync(loggerService, consumer, "Partition:", cancellationToken);
var startupFormLog = WaitForLogAsync(loggerService, dataGenerator, "Startup form completed with 2 fields", cancellationToken);
var startupFormCommand = await app.Services.GetRequiredService<ResourceCommandService>()
.ExecuteCommandAsync(startupForm, "projectcommander-configure", cancellationToken);

Assert.True(startupFormCommand.Success, startupFormCommand.Message);
await startupFormLog;
await applicationStart;
await notifications.WaitForResourceAsync("datagenerator", KnownResourceStates.Running, cancellationToken);
await consumerEventLog;

var pauseLog = WaitForLogAsync(loggerService, dataGenerator, "Data generation paused", cancellationToken);
var pauseCommand = await app.Services.GetRequiredService<ResourceCommandService>()
.ExecuteCommandAsync(dataGenerator, "pause", cancellationToken);

Assert.True(pauseCommand.Success, pauseCommand.Message);
await pauseLog;

var resumeLog = WaitForLogAsync(loggerService, dataGenerator, "Data generation resumed", cancellationToken);
var resumeCommand = await app.Services.GetRequiredService<ResourceCommandService>()
.ExecuteCommandAsync(dataGenerator, "resume", cancellationToken);

Assert.True(resumeCommand.Success, resumeCommand.Message);
await resumeLog;
}

private static async Task WaitForLogAsync(
ResourceLoggerService loggerService,
IResource resource,
string expectedText,
CancellationToken cancellationToken)
{
await foreach (var logBatch in loggerService.WatchAsync(resource).WithCancellation(cancellationToken))
{
if (logBatch.Any(log => log.Content.Contains(expectedText, StringComparison.Ordinal)))
{
return;
}
}

throw new InvalidOperationException($"Resource '{resource.Name}' stopped before logging '{expectedText}'.");
}
}
21 changes: 11 additions & 10 deletions ProjectCommander.UnitTests/ProjectCommander.UnitTests.csproj
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
Comment thread
Copilot marked this conversation as resolved.
Resolved
<UseMicrosoftTestingPlatformRunner>true</UseMicrosoftTestingPlatformRunner>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.4">
<PackageReference Include="coverlet.collector" Version="10.1.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="10.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="11.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="11.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="11.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.12.0" />
<PackageReference Include="Moq" Version="4.21.0" />
<PackageReference Include="xunit.v3" Version="4.0.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="4.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
8 changes: 4 additions & 4 deletions ProjectCommander.UnitTests/StartupFormServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public async Task WaitForStartupFormAsync_ReturnsNullWhenNotRequired()
_service.SetStartupFormRequired(false);

// Act
var result = await _service.WaitForStartupFormAsync();
var result = await _service.WaitForStartupFormAsync(TestContext.Current.CancellationToken);

// Assert
Assert.Null(result);
Expand All @@ -91,7 +91,7 @@ public async Task WaitForStartupFormAsync_ReturnsDataWhenAlreadyCompleted()
_service.CompleteStartupForm(formData);

// Act
var result = await _service.WaitForStartupFormAsync();
var result = await _service.WaitForStartupFormAsync(TestContext.Current.CancellationToken);

// Assert
Assert.NotNull(result);
Expand All @@ -109,8 +109,8 @@ public async Task WaitForStartupFormAsync_BlocksUntilFormCompleted()
};

// Act
var waitTask = _service.WaitForStartupFormAsync();
var waitTask = _service.WaitForStartupFormAsync(TestContext.Current.CancellationToken);

// Verify the task is not completed yet
Assert.False(waitTask.IsCompleted);

Expand Down
5 changes: 3 additions & 2 deletions ProjectCommander.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35521.163
# Visual Studio Version 18
VisualStudioVersion = 18.12.12412.261 stable
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nivot.Aspire.Hosting.ProjectCommander", "Src\Nivot.Aspire.Hosting.ProjectCommander\Nivot.Aspire.Hosting.ProjectCommander.csproj", "{BA1F35CD-5AE3-49C8-A0CA-253073F93D10}"
EndProject
Expand All @@ -23,6 +23,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{38700E57-CF17-4094-96D0-FE21AFA0EC5D}"
ProjectSection(SolutionItems) = preProject
Src\Directory.Build.props = Src\Directory.Build.props
README.md = README.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectCommander.Tests", "ProjectCommander.Tests\ProjectCommander.Tests.csproj", "{3FA2AEB2-18B5-4DF8-A556-09492F6408D4}"
Expand Down
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Aspire Project Commander is a set of packages that lets you send simple string c

## Installation

### Compatibility

As of version 3.0, this project expects Aspire 17 or later as APIs have evolved and there are breaking changes.

### AppHost Project

Add the hosting package to your Aspire AppHost project:
Expand Down Expand Up @@ -122,7 +126,7 @@ var builder = DistributedApplication.CreateBuilder(args);

var commander = builder.AddAspireProjectCommander();

var datagenerator = builder.AddProject<Projects.DataGenerator>("datagenerator")
var datagenerator = builder.AddDotnetProject("datagenerator", @"..\DataGenerator\DataGenerator.csproj")
.WithReference(commander)
.WaitFor(commander)
.WithProjectManifest(); // Reads commands and startup form from projectcommander.json
Expand Down Expand Up @@ -199,7 +203,7 @@ var builder = DistributedApplication.CreateBuilder(args);

var commander = builder.AddAspireProjectCommander();

builder.AddProject<Projects.DataGenerator>("eventhub-datagenerator")
builder.AddDotnetProject("datagenerator", @"..\DataGenerator\DataGenerator.csproj")
// provides commander signalr hub connectionstring to integration
.WithReference(commander)
// array of simple tuples with the command string and a display value for the dashboard
Expand Down Expand Up @@ -258,7 +262,7 @@ public sealed class MyProjectCommands(IAspireProjectCommanderClient commander, I
You can use both `WithProjectManifest()` and `WithProjectCommands()` together - the commands will be merged:

```csharp
var datagenerator = builder.AddProject<Projects.DataGenerator>("datagenerator")
var datagenerator = builder.AddDotnetProject("datagenerator", @"..\DataGenerator\DataGenerator.csproj")
.WithReference(commander)
.WaitFor(commander)
.WithProjectManifest() // Commands from manifest + startup form handling
Expand All @@ -275,7 +279,7 @@ var builder = DistributedApplication.CreateBuilder(args);

var commander = builder.AddAspireProjectCommander();

builder.AddProject<Projects.MyService>("myservice")
builder.AddDotnetProject("myservice", @"..\<path>\<project.csproj>")
.WithReference(commander)
.WaitFor(commander)
.WithProjectManifest();
Expand Down Expand Up @@ -324,6 +328,16 @@ public sealed class CommandHandler(IAspireProjectCommanderClient commander, ILog
}
```

## End-to-End Testing

The Aspire integration tests launch the sample AppHost, including its Azure Event Hubs emulator. Docker must be running to execute them:

```bash
dotnet test --project ProjectCommander.Tests/ProjectCommander.Tests.csproj
```

The tests exercise the data-generator startup form and resource commands, then verify the resulting data-generator and consumer logs.

## Sample

See the `Sample` folder for an Aspire example that allows you to signal a data generator project that is writing messages into an emulator instance of Azure Event Hubs.
4 changes: 2 additions & 2 deletions Sample/Consumer/Consumer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspire.Azure.Messaging.EventHubs" Version="13.1.1" />
<PackageReference Include="Aspire.Azure.Messaging.EventHubs" Version="17.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Sample/DataGenerator/DataGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspire.Azure.Messaging.EventHubs" Version="13.1.1" />
<PackageReference Include="Aspire.Azure.Messaging.EventHubs" Version="17.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Sample/ProjectCommander.AppHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

var client = datahub.AddConsumerGroup("client");

var datagenerator = builder.AddProject<Projects.DataGenerator>("datagenerator")
var datagenerator = builder.AddDotnetProject("datagenerator", @"..\DataGenerator\DataGenerator.csproj")
.WithReference(datahub)
.WithReference(commander)
.WaitFor(commander)
.WaitFor(datahub)
.WithProjectManifest(); // Reads commands and startup form from projectcommander.json

builder.AddProject<Projects.Consumer>("consumer")
builder.AddDotnetProject("consumer", @"..\Consumer\Consumer.csproj")
.WithReference(commander)
.WaitFor(commander)
.WithReference(client)
Expand Down
Loading
Loading