diff --git a/src/Aspire.ProjectTemplates/templates/aspire-mstest/9.1/IntegrationTest1.cs b/src/Aspire.ProjectTemplates/templates/aspire-mstest/9.1/IntegrationTest1.cs index b3aa20241f1..b069bbcc1f6 100644 --- a/src/Aspire.ProjectTemplates/templates/aspire-mstest/9.1/IntegrationTest1.cs +++ b/src/Aspire.ProjectTemplates/templates/aspire-mstest/9.1/IntegrationTest1.cs @@ -1,8 +1,12 @@ +using Microsoft.Extensions.Logging; + namespace Aspire.Tests._1; [TestClass] public class IntegrationTest1 { + private static readonly TimeSpan DefaultTimeout = TimeSpan.FromSeconds(30); + // Instructions: // 1. Add a project reference to the target AppHost project, e.g.: // @@ -17,19 +21,26 @@ public class IntegrationTest1 // { // // Arrange // var appHost = await DistributedApplicationTestingBuilder.CreateAsync(); + // appHost.Services.AddLogging(logging => + // { + // logging.SetMinimumLevel(LogLevel.Debug); + // // Override the logging filters from the app's configuration + // logging.AddFilter(appHost.Environment.ApplicationName, LogLevel.Debug); + // logging.AddFilter("Aspire.", LogLevel.Debug); + // }); // appHost.Services.ConfigureHttpClientDefaults(clientBuilder => // { // clientBuilder.AddStandardResilienceHandler(); // }); - // await using var app = await appHost.BuildAsync(); - // var resourceNotificationService = app.Services.GetRequiredService(); - // await app.StartAsync(); - + // + // await using var app = await appHost.BuildAsync().WaitAsync(DefaultTimeout); + // await app.StartAsync().WaitAsync(DefaultTimeout); + // // // Act // var httpClient = app.CreateHttpClient("webfrontend"); - // await resourceNotificationService.WaitForResourceAsync("webfrontend", KnownResourceStates.Running).WaitAsync(TimeSpan.FromSeconds(30)); + // await app.ResourceNotifications.WaitForResourceHealthyAsync("webfrontend").WaitAsync(DefaultTimeout); // var response = await httpClient.GetAsync("/"); - + // // // Assert // Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); // } diff --git a/src/Aspire.ProjectTemplates/templates/aspire-nunit/9.1/IntegrationTest1.cs b/src/Aspire.ProjectTemplates/templates/aspire-nunit/9.1/IntegrationTest1.cs index 626cb2c564a..4b7997e116d 100644 --- a/src/Aspire.ProjectTemplates/templates/aspire-nunit/9.1/IntegrationTest1.cs +++ b/src/Aspire.ProjectTemplates/templates/aspire-nunit/9.1/IntegrationTest1.cs @@ -1,7 +1,11 @@ +using Microsoft.Extensions.Logging; + namespace Aspire.Tests._1; public class IntegrationTest1 { + private static readonly TimeSpan DefaultTimeout = TimeSpan.FromSeconds(30); + // Instructions: // 1. Add a project reference to the target AppHost project, e.g.: // @@ -16,19 +20,26 @@ public class IntegrationTest1 // { // // Arrange // var appHost = await DistributedApplicationTestingBuilder.CreateAsync(); + // appHost.Services.AddLogging(logging => + // { + // logging.SetMinimumLevel(LogLevel.Debug); + // // Override the logging filters from the app's configuration + // logging.AddFilter(appHost.Environment.ApplicationName, LogLevel.Debug); + // logging.AddFilter("Aspire.", LogLevel.Debug); + // }); // appHost.Services.ConfigureHttpClientDefaults(clientBuilder => // { // clientBuilder.AddStandardResilienceHandler(); // }); - // await using var app = await appHost.BuildAsync(); - // var resourceNotificationService = app.Services.GetRequiredService(); - // await app.StartAsync(); - + // + // await using var app = await appHost.BuildAsync().WaitAsync(DefaultTimeout); + // await app.StartAsync().WaitAsync(DefaultTimeout); + // // // Act // var httpClient = app.CreateHttpClient("webfrontend"); - // await resourceNotificationService.WaitForResourceAsync("webfrontend", KnownResourceStates.Running).WaitAsync(TimeSpan.FromSeconds(30)); + // await app.ResourceNotifications.WaitForResourceHealthyAsync("webfrontend").WaitAsync(DefaultTimeout); // var response = await httpClient.GetAsync("/"); - + // // // Assert // Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK)); // } diff --git a/src/Aspire.ProjectTemplates/templates/aspire-starter/9.1/Aspire-StarterApplication.1.Tests/WebTests.cs b/src/Aspire.ProjectTemplates/templates/aspire-starter/9.1/Aspire-StarterApplication.1.Tests/WebTests.cs index d0b0d6f1cc0..3a355ff95e1 100644 --- a/src/Aspire.ProjectTemplates/templates/aspire-starter/9.1/Aspire-StarterApplication.1.Tests/WebTests.cs +++ b/src/Aspire.ProjectTemplates/templates/aspire-starter/9.1/Aspire-StarterApplication.1.Tests/WebTests.cs @@ -1,3 +1,5 @@ +using Microsoft.Extensions.Logging; + namespace Aspire_StarterApplication._1.Tests; #if (TestFramework == "MSTest") @@ -5,6 +7,8 @@ namespace Aspire_StarterApplication._1.Tests; #endif public class WebTests { + private static readonly TimeSpan DefaultTimeout = TimeSpan.FromSeconds(30); + #if (TestFramework == "MSTest") [TestMethod] #elif (TestFramework == "NUnit") @@ -16,21 +20,27 @@ public async Task GetWebResourceRootReturnsOkStatusCode() { // Arrange var appHost = await DistributedApplicationTestingBuilder.CreateAsync(); + appHost.Services.AddLogging(logging => + { + logging.SetMinimumLevel(LogLevel.Debug); + // Override the logging filters from the app's configuration + logging.AddFilter(appHost.Environment.ApplicationName, LogLevel.Debug); + logging.AddFilter("Aspire.", LogLevel.Debug); +#if (TestFramework == "xUnit.net") + // To output logs to the xUnit.net ITestOutputHelper, consider adding a package from https://www.nuget.org/packages?q=xunit+logging +#endif + }); appHost.Services.ConfigureHttpClientDefaults(clientBuilder => { clientBuilder.AddStandardResilienceHandler(); }); -#if (TestFramework == "xUnit.net") - // To output logs to the xUnit.net ITestOutputHelper, consider adding a package from https://www.nuget.org/packages?q=xunit+logging -#endif - await using var app = await appHost.BuildAsync(); - var resourceNotificationService = app.Services.GetRequiredService(); - await app.StartAsync(); + await using var app = await appHost.BuildAsync().WaitAsync(DefaultTimeout); + await app.StartAsync().WaitAsync(DefaultTimeout); // Act var httpClient = app.CreateHttpClient("webfrontend"); - await resourceNotificationService.WaitForResourceAsync("webfrontend", KnownResourceStates.Running).WaitAsync(TimeSpan.FromSeconds(30)); + await app.ResourceNotifications.WaitForResourceHealthyAsync("webfrontend").WaitAsync(DefaultTimeout); var response = await httpClient.GetAsync("/"); // Assert diff --git a/src/Aspire.ProjectTemplates/templates/aspire-xunit/9.1/IntegrationTest1.cs b/src/Aspire.ProjectTemplates/templates/aspire-xunit/9.1/IntegrationTest1.cs index dafcbf38f00..d9c9c409c6a 100644 --- a/src/Aspire.ProjectTemplates/templates/aspire-xunit/9.1/IntegrationTest1.cs +++ b/src/Aspire.ProjectTemplates/templates/aspire-xunit/9.1/IntegrationTest1.cs @@ -1,7 +1,11 @@ +using Microsoft.Extensions.Logging; + namespace Aspire.Tests._1.Tests; public class IntegrationTest1 { + private static readonly TimeSpan DefaultTimeout = TimeSpan.FromSeconds(30); + // Instructions: // 1. Add a project reference to the target AppHost project, e.g.: // @@ -16,21 +20,27 @@ public class IntegrationTest1 // { // // Arrange // var appHost = await DistributedApplicationTestingBuilder.CreateAsync(); + // appHost.Services.AddLogging(logging => + // { + // logging.SetMinimumLevel(LogLevel.Debug); + // // Override the logging filters from the app's configuration + // logging.AddFilter(appHost.Environment.ApplicationName, LogLevel.Debug); + // logging.AddFilter("Aspire.", LogLevel.Debug); + // // To output logs to the xUnit.net ITestOutputHelper, consider adding a package from https://www.nuget.org/packages?q=xunit+logging + // }); // appHost.Services.ConfigureHttpClientDefaults(clientBuilder => // { // clientBuilder.AddStandardResilienceHandler(); // }); - // // To output logs to the xUnit.net ITestOutputHelper, consider adding a package from https://www.nuget.org/packages?q=xunit+logging // - // await using var app = await appHost.BuildAsync(); - // var resourceNotificationService = app.Services.GetRequiredService(); - // await app.StartAsync(); - + // await using var app = await appHost.BuildAsync().WaitAsync(DefaultTimeout); + // await app.StartAsync().WaitAsync(DefaultTimeout); + // // // Act // var httpClient = app.CreateHttpClient("webfrontend"); - // await resourceNotificationService.WaitForResourceAsync("webfrontend", KnownResourceStates.Running).WaitAsync(TimeSpan.FromSeconds(30)); + // await app.ResourceNotifications.WaitForResourceHealthyAsync("webfrontend").WaitAsync(DefaultTimeout); // var response = await httpClient.GetAsync("/"); - + // // // Assert // Assert.Equal(HttpStatusCode.OK, response.StatusCode); // }