From 582879226d55aa8641474fec0be750189d1d4787 Mon Sep 17 00:00:00 2001 From: sikutisa Date: Mon, 9 Dec 2024 17:12:27 +0900 Subject: [PATCH] add apphost test Related to: #199 --- .../Pages/AdminUpdateEventTests.cs | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 test/AzureOpenAIProxy.AppHost.Tests/PlaygroundApp/Pages/AdminUpdateEventTests.cs diff --git a/test/AzureOpenAIProxy.AppHost.Tests/PlaygroundApp/Pages/AdminUpdateEventTests.cs b/test/AzureOpenAIProxy.AppHost.Tests/PlaygroundApp/Pages/AdminUpdateEventTests.cs new file mode 100644 index 00000000..88919572 --- /dev/null +++ b/test/AzureOpenAIProxy.AppHost.Tests/PlaygroundApp/Pages/AdminUpdateEventTests.cs @@ -0,0 +1,81 @@ +using System.Net; + +using AzureOpenAIProxy.AppHost.Tests.Fixtures; + +using FluentAssertions; + +namespace AzureOpenAIProxy.AppHost.Tests.PlaygroundApp.Pages; + +public class AdminUpdateEventPageTests(AspireAppHostFixture host) : IClassFixture +{ + [Fact] + public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_OK() + { + // Arrange + using var httpClient = host.App!.CreateHttpClient("playgroundapp"); + await host.ResourceNotificationService.WaitForResourceAsync("playgroundapp", KnownResourceStates.Running).WaitAsync(TimeSpan.FromSeconds(30)); + + var eventId = Guid.NewGuid(); + var expectedUrl = $"/admin/events/edit/{eventId}"; + + // Act + var response = await httpClient.GetAsync(expectedUrl); + + // Assert + response.StatusCode.Should().Be(HttpStatusCode.OK); + } + + [Theory] + [InlineData("_content/Microsoft.FluentUI.AspNetCore.Components/css/reboot.css")] + public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_CSS_Elements(string expected) + { + // Arrange + using var httpClient = host.App!.CreateHttpClient("playgroundapp"); + await host.ResourceNotificationService.WaitForResourceAsync("playgroundapp", KnownResourceStates.Running).WaitAsync(TimeSpan.FromSeconds(30)); + + var eventId = Guid.NewGuid(); + var expectedUrl = $"/admin/events/edit/{eventId}"; + + // Act + var html = await httpClient.GetStringAsync(expectedUrl); + + // Assert + html.Should().Contain(expected); + } + + [Theory] + [InlineData("_content/Microsoft.FluentUI.AspNetCore.Components/Microsoft.FluentUI.AspNetCore.Components.lib.module.js")] + public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_JavaScript_Elements(string expected) + { + // Arrange + using var httpClient = host.App!.CreateHttpClient("playgroundapp"); + await host.ResourceNotificationService.WaitForResourceAsync("playgroundapp", KnownResourceStates.Running).WaitAsync(TimeSpan.FromSeconds(30)); + + var eventId = Guid.NewGuid(); + var expectedUrl = $"/admin/events/edit/{eventId}"; + + // Act + var html = await httpClient.GetStringAsync(expectedUrl); + + // Assert + html.Should().Contain(expected); + } + + [Theory] + [InlineData("
")] + public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_HTML_Elements(string expected) + { + // Arrange + using var httpClient = host.App!.CreateHttpClient("playgroundapp"); + await host.ResourceNotificationService.WaitForResourceAsync("playgroundapp", KnownResourceStates.Running).WaitAsync(TimeSpan.FromSeconds(30)); + + var eventId = Guid.NewGuid(); + var expectedUrl = $"/admin/events/edit/{eventId}"; + + // Act + var html = await httpClient.GetStringAsync(expectedUrl); + + // Assert + html.Should().Contain(expected); + } +} \ No newline at end of file