From 86b242448b4a0eb0fa2a07cbe4c3b351dcb1ac0c Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Mon, 10 Oct 2022 00:34:49 +0800 Subject: refactor: Small structure changes --- code/api/src/IOL.GreatOffice.Api.csproj | 3 -- .../ApplicationTests/LoginPageTests.cs | 23 +++++++++++ .../Helpers/Element.cs | 6 +++ .../Helpers/WebServerFixture.cs | 48 ++++++++++++++++++++++ .../IOL.GreatOffice.IntegrationTests.csproj | 21 ++++++++++ .../ApplicationTests/LoginPageTests.cs | 23 ----------- .../Helpers/Element.cs | 6 --- .../Helpers/WebServerFixture.cs | 48 ---------------------- .../IOL.GreatOffice.IntegrationTests.csproj | 21 ---------- 9 files changed, 98 insertions(+), 101 deletions(-) create mode 100644 code/api/tests/IOL.GreatOffice.IntegrationTests/ApplicationTests/LoginPageTests.cs create mode 100644 code/api/tests/IOL.GreatOffice.IntegrationTests/Helpers/Element.cs create mode 100644 code/api/tests/IOL.GreatOffice.IntegrationTests/Helpers/WebServerFixture.cs create mode 100644 code/api/tests/IOL.GreatOffice.IntegrationTests/IOL.GreatOffice.IntegrationTests.csproj delete mode 100644 code/tests/IOL.GreatOffice.IntegrationTests/ApplicationTests/LoginPageTests.cs delete mode 100644 code/tests/IOL.GreatOffice.IntegrationTests/Helpers/Element.cs delete mode 100644 code/tests/IOL.GreatOffice.IntegrationTests/Helpers/WebServerFixture.cs delete mode 100644 code/tests/IOL.GreatOffice.IntegrationTests/IOL.GreatOffice.IntegrationTests.csproj diff --git a/code/api/src/IOL.GreatOffice.Api.csproj b/code/api/src/IOL.GreatOffice.Api.csproj index 0b3d37e..1ffa04b 100644 --- a/code/api/src/IOL.GreatOffice.Api.csproj +++ b/code/api/src/IOL.GreatOffice.Api.csproj @@ -36,9 +36,6 @@ - - README.md - build_and_push.sh diff --git a/code/api/tests/IOL.GreatOffice.IntegrationTests/ApplicationTests/LoginPageTests.cs b/code/api/tests/IOL.GreatOffice.IntegrationTests/ApplicationTests/LoginPageTests.cs new file mode 100644 index 0000000..10525fd --- /dev/null +++ b/code/api/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 +{ + 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/code/api/tests/IOL.GreatOffice.IntegrationTests/Helpers/Element.cs b/code/api/tests/IOL.GreatOffice.IntegrationTests/Helpers/Element.cs new file mode 100644 index 0000000..da83cc3 --- /dev/null +++ b/code/api/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/code/api/tests/IOL.GreatOffice.IntegrationTests/Helpers/WebServerFixture.cs b/code/api/tests/IOL.GreatOffice.IntegrationTests/Helpers/WebServerFixture.cs new file mode 100644 index 0000000..080fa9f --- /dev/null +++ b/code/api/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/code/api/tests/IOL.GreatOffice.IntegrationTests/IOL.GreatOffice.IntegrationTests.csproj b/code/api/tests/IOL.GreatOffice.IntegrationTests/IOL.GreatOffice.IntegrationTests.csproj new file mode 100644 index 0000000..0376a10 --- /dev/null +++ b/code/api/tests/IOL.GreatOffice.IntegrationTests/IOL.GreatOffice.IntegrationTests.csproj @@ -0,0 +1,21 @@ + + + + Exe + true + net6.0 + enable + disable + + + + + + + + + + + + + diff --git a/code/tests/IOL.GreatOffice.IntegrationTests/ApplicationTests/LoginPageTests.cs b/code/tests/IOL.GreatOffice.IntegrationTests/ApplicationTests/LoginPageTests.cs deleted file mode 100644 index 10525fd..0000000 --- a/code/tests/IOL.GreatOffice.IntegrationTests/ApplicationTests/LoginPageTests.cs +++ /dev/null @@ -1,23 +0,0 @@ -using IOL.GreatOffice.IntegrationTests.Helpers; -using Xunit; - -namespace IOL.GreatOffice.IntegrationTests.ApplicationTests; - -public class LoginPageTests : IClassFixture -{ - 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/code/tests/IOL.GreatOffice.IntegrationTests/Helpers/Element.cs b/code/tests/IOL.GreatOffice.IntegrationTests/Helpers/Element.cs deleted file mode 100644 index da83cc3..0000000 --- a/code/tests/IOL.GreatOffice.IntegrationTests/Helpers/Element.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace IOL.GreatOffice.IntegrationTests.Helpers; - -public static class Element -{ - public static string ByName(string name) => $"[pw-name='{name}']"; -} diff --git a/code/tests/IOL.GreatOffice.IntegrationTests/Helpers/WebServerFixture.cs b/code/tests/IOL.GreatOffice.IntegrationTests/Helpers/WebServerFixture.cs deleted file mode 100644 index 080fa9f..0000000 --- a/code/tests/IOL.GreatOffice.IntegrationTests/Helpers/WebServerFixture.cs +++ /dev/null @@ -1,48 +0,0 @@ -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/code/tests/IOL.GreatOffice.IntegrationTests/IOL.GreatOffice.IntegrationTests.csproj b/code/tests/IOL.GreatOffice.IntegrationTests/IOL.GreatOffice.IntegrationTests.csproj deleted file mode 100644 index 0376a10..0000000 --- a/code/tests/IOL.GreatOffice.IntegrationTests/IOL.GreatOffice.IntegrationTests.csproj +++ /dev/null @@ -1,21 +0,0 @@ - - - - Exe - true - net6.0 - enable - disable - - - - - - - - - - - - - -- cgit v1.3