diff --git a/tests/CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps.Tests/CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps.Tests.csproj b/tests/CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps.Tests/CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps.Tests.csproj index 5482759a..a692760d 100644 --- a/tests/CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps.Tests/CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps.Tests.csproj +++ b/tests/CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps.Tests/CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps.Tests.csproj @@ -8,6 +8,7 @@ + diff --git a/tests/CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps.Tests/ResourceCreationTests.cs b/tests/CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps.Tests/ResourceCreationTests.cs index 90067cfb..f637a2e6 100644 --- a/tests/CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps.Tests/ResourceCreationTests.cs +++ b/tests/CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps.Tests/ResourceCreationTests.cs @@ -1,5 +1,6 @@ using Aspire.Hosting; using Aspire.Hosting.ApplicationModel; +using CommunityToolkit.Aspire.Testing; using Microsoft.Extensions.DependencyInjection; namespace CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps.Tests; @@ -175,4 +176,4 @@ public void Port_Will_Be_An_Arg() Assert.Contains("--port", args); Assert.Contains("4280", args); } -} \ No newline at end of file +} diff --git a/tests/CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps.Tests/SwaHostingComponentTests.cs b/tests/CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps.Tests/SwaHostingComponentTests.cs new file mode 100644 index 00000000..862c3baa --- /dev/null +++ b/tests/CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps.Tests/SwaHostingComponentTests.cs @@ -0,0 +1,39 @@ +using CommunityToolkit.Aspire.Testing; +using FluentAssertions; +using System.Net; +using System.Net.Http.Json; +using Xunit.Abstractions; + +namespace CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps.Tests; + +public class SwaHostingComponentTests(ITestOutputHelper testOutput) : AspireIntegrationTest(testOutput) +{ + [Fact] + public async Task EmulatorLaunchesOnDefaultPort() + { + var httpClient = app.CreateHttpClient("swa"); + + await ResourceNotificationService.WaitForResourceAsync("swa", KnownResourceStates.Running).WaitAsync(TimeSpan.FromSeconds(30)); + + var response = await httpClient.GetAsync("/"); + + response.StatusCode.Should().Be(HttpStatusCode.OK); + } + + [Fact] + public async Task CanAccessApi() + { + var httpClient = app.CreateHttpClient("swa"); + + await ResourceNotificationService.WaitForResourceAsync("swa", KnownResourceStates.Running).WaitAsync(TimeSpan.FromSeconds(30)); + + var response = await httpClient.GetAsync("/api/weather"); + + response.StatusCode.Should().Be(HttpStatusCode.OK); + var forecasts = await response.Content.ReadFromJsonAsync(); + Assert.NotNull(forecasts); + forecasts.Length.Should().Be(6); + } + + record WeatherForecast(DateTime Date, int TemperatureC, string Summary); +} \ No newline at end of file