diff options
Diffstat (limited to 'tests/IOL.GreatOffice.IntegrationTests')
4 files changed, 102 insertions, 0 deletions
diff --git a/tests/IOL.GreatOffice.IntegrationTests/ApplicationTests/LoginPageTests.cs b/tests/IOL.GreatOffice.IntegrationTests/ApplicationTests/LoginPageTests.cs new file mode 100644 index 0000000..10525fd --- /dev/null +++ b/tests/IOL.GreatOffice.IntegrationTests/ApplicationTests/LoginPageTests.cs @@ -0,0 +1,23 @@ +using IOL.GreatOffice.IntegrationTests.Helpers; +using Xunit; + +namespace IOL.GreatOffice.IntegrationTests.ApplicationTests; + +public class LoginPageTests : IClassFixture<WebServerFixture> +{ + private readonly WebServerFixture _fixture; + + public LoginPageTests(WebServerFixture fixture) { + _fixture = fixture; + } + + [Fact] + public async Task LoginPageTestsRenders() { + var page = await _fixture.Browser.NewPageAsync(); + await page.GotoAsync(_fixture.BaseUrl); + + var actual = await page.TextContentAsync(Element.ByName("Page Title")); + + Assert.Equal("Welcome", actual); + } +} diff --git a/tests/IOL.GreatOffice.IntegrationTests/Helpers/Element.cs b/tests/IOL.GreatOffice.IntegrationTests/Helpers/Element.cs new file mode 100644 index 0000000..da83cc3 --- /dev/null +++ b/tests/IOL.GreatOffice.IntegrationTests/Helpers/Element.cs @@ -0,0 +1,6 @@ +namespace IOL.GreatOffice.IntegrationTests.Helpers; + +public static class Element +{ + public static string ByName(string name) => $"[pw-name='{name}']"; +} diff --git a/tests/IOL.GreatOffice.IntegrationTests/Helpers/WebServerFixture.cs b/tests/IOL.GreatOffice.IntegrationTests/Helpers/WebServerFixture.cs new file mode 100644 index 0000000..080fa9f --- /dev/null +++ b/tests/IOL.GreatOffice.IntegrationTests/Helpers/WebServerFixture.cs @@ -0,0 +1,48 @@ +using System.Net; +using System.Net.Sockets; +using Microsoft.AspNetCore.Builder; +using Microsoft.Playwright; +using Xunit; +using Program = IOL.GreatOffice.Api.Program; + +namespace IOL.GreatOffice.IntegrationTests.Helpers; + +// ReSharper disable once ClassNeverInstantiated.Global +public class WebServerFixture : IAsyncLifetime, IDisposable +{ + private readonly WebApplication Host; + private IPlaywright Playwright { get; set; } + public IBrowser Browser { get; private set; } + public string BaseUrl { get; } = $"https://localhost:{GetRandomUnusedPort()}"; + + public WebServerFixture() { + Host = Program.CreateWebApplication(Program.CreateAppBuilder(default)); + } + + public async Task InitializeAsync() { + Playwright = await Microsoft.Playwright.Playwright.CreateAsync(); + Browser = await Playwright.Chromium.LaunchAsync(); + await Host.StartAsync(); + } + + public async Task DisposeAsync() { + await Host.StopAsync(); + await Host.DisposeAsync(); + Playwright?.Dispose(); + } + + public void Dispose() { + Host.StopAsync(); + Host.DisposeAsync(); + Playwright?.Dispose(); + GC.SuppressFinalize(this); + } + + private static int GetRandomUnusedPort() { + var listener = new TcpListener(IPAddress.Any, 0); + listener.Start(); + var port = ((IPEndPoint)listener.LocalEndpoint).Port; + listener.Stop(); + return port; + } +} diff --git a/tests/IOL.GreatOffice.IntegrationTests/IOL.GreatOffice.IntegrationTests.csproj b/tests/IOL.GreatOffice.IntegrationTests/IOL.GreatOffice.IntegrationTests.csproj new file mode 100644 index 0000000..92ed6b2 --- /dev/null +++ b/tests/IOL.GreatOffice.IntegrationTests/IOL.GreatOffice.IntegrationTests.csproj @@ -0,0 +1,25 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <ImplicitUsings>true</ImplicitUsings> + <TargetFramework>net6.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>disable</Nullable> + </PropertyGroup> + + <ItemGroup> + <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" /> + <PackageReference Include="Microsoft.Playwright" Version="1.22.0" /> + <PackageReference Include="xunit" Version="2.4.1" /> + </ItemGroup> + + <ItemGroup> + <ProjectReference Include="..\..\server\IOL.GreatOffice.Api.csproj" /> + <ProjectReference Include="..\..\server\src\IOL.GreatOffice.Api.csproj" /> + </ItemGroup> + + <ItemGroup> + <Folder Include="ServerTests" /> + </ItemGroup> +</Project> |
