Repository navigation
update net10 and aspire 17 #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
21
ProjectCommander.UnitTests/ProjectCommander.UnitTests.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.