Skip to content

Commit d421906

Browse files
Copilotdavidfowl
andcommitted
Address PR feedback: revert formatting and improve test
- Reverted formatting change in ResourceBuilderExtensions.cs (return statement on one line) - Improved CommandLineArgsCallbackContextHasCorrectExecutionContextDuringPublish test to: - Remove unnecessary IsRunMode check in callback - Capture ExecutionContext to verify it's set correctly - Assert ExecutionContext is not null and in Publish mode Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
1 parent 72ae992 commit d421906

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

src/Aspire.Hosting/ResourceBuilderExtensions.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2327,9 +2327,7 @@ public static IResourceBuilder<T> WithVSCodeDebugSupport<T>(this IResourceBuilde
23272327
});
23282328
}
23292329

2330-
builder.WithAnnotation(new SupportsDebuggingAnnotation(projectPath, debugAdapterId, requiredExtensionId));
2331-
2332-
return builder;
2330+
return builder.WithAnnotation(new SupportsDebuggingAnnotation(projectPath, debugAdapterId, requiredExtensionId));
23332331
}
23342332

23352333
/// <summary>

tests/Aspire.Hosting.Azure.Tests/AzureResourcePreparerTests.cs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -241,30 +241,25 @@ public async Task CommandLineArgsCallbackContextHasCorrectExecutionContextDuring
241241
using var builder = TestDistributedApplicationBuilder.Create(DistributedApplicationOperation.Publish);
242242
builder.AddAzureContainerAppEnvironment("env");
243243

244-
// Create a project with a WithArgs callback that checks IsRunMode before accessing ServiceProvider
245-
// This simulates what WithVSCodeDebugSupport does
244+
DistributedApplicationExecutionContext? capturedExecutionContext = null;
245+
246+
// Create a project with a WithArgs callback that captures the ExecutionContext
246247
var api = builder.AddProject<Project>("api", launchProfileName: null)
247248
.WithArgs(context =>
248249
{
249-
// This simulates WithVSCodeDebugSupport behavior - checking IsRunMode before accessing ServiceProvider
250-
if (!context.ExecutionContext.IsRunMode)
251-
{
252-
return;
253-
}
254-
255-
// This should not be reached during publish mode, but if the ExecutionContext is not set correctly,
256-
// it will default to Run mode and then try to access ServiceProvider which will throw
257-
_ = context.ExecutionContext.ServiceProvider;
250+
// Capture the ExecutionContext to verify it's set correctly
251+
capturedExecutionContext = context.ExecutionContext;
258252
});
259253

260254
using var app = builder.Build();
261255

262-
// This should not throw because ExecutionContext should be set to Publish mode
263-
// and the IsRunMode check should prevent accessing ServiceProvider
256+
// This should not throw - the ExecutionContext should be set correctly
264257
await ExecuteBeforeStartHooksAsync(app, default);
265258

266-
// Test passes if we reach this point without exceptions
267-
Assert.True(true);
259+
// Verify the ExecutionContext was captured and is in Publish mode
260+
Assert.NotNull(capturedExecutionContext);
261+
Assert.True(capturedExecutionContext.IsPublishMode);
262+
Assert.False(capturedExecutionContext.IsRunMode);
268263
}
269264

270265
private sealed class Project : IProjectMetadata

0 commit comments

Comments
 (0)