Skip to content

Commit

Permalink
Adding tests for SWA hosting
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronpowell committed Aug 20, 2024
1 parent c07d088 commit 4ffa137
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<ItemGroup>
<ProjectReference Include="..\..\src\CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps\CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps.csproj" />
<ProjectReference Include="..\CommunityToolkit.Aspire.Testing\CommunityToolkit.Aspire.Testing.csproj" />
<ProjectReference Include="..\..\examples\swa\CommunityToolkit.Aspire.StaticWebApps.AppHost\CommunityToolkit.Aspire.StaticWebApps.AppHost.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -175,4 +176,4 @@ public void Port_Will_Be_An_Arg()
Assert.Contains("--port", args);
Assert.Contains("4280", args);
}
}
}
Original file line number Diff line number Diff line change
@@ -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<Projects.CommunityToolkit_Aspire_StaticWebApps_AppHost>(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<WeatherForecast[]>();
Assert.NotNull(forecasts);
forecasts.Length.Should().Be(6);
}

record WeatherForecast(DateTime Date, int TemperatureC, string Summary);
}

0 comments on commit 4ffa137

Please sign in to comment.