#region ========================================================================= USING ===================================================================================== using Lumina.DataAccess.Core.UoW; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using System.Diagnostics.CodeAnalysis; using System.Threading; using System.Threading.Tasks; using Xunit; #endregion namespace Lumina.Presentation.Api.IntegrationTests.Common.Setup; /// /// Helpers shared by the theme integration tests. /// [ExcludeFromCodeCoverage] public static class ThemeTestHelpers { /// /// Waits until the bundled 'editorial-paper' theme has been installed and activated by the theme detection job at startup. /// /// The shared API factory whose database is polled. /// A task representing the asynchronous operation. public static async Task WaitForBundledThemeAsync(AuthenticatedLuminaApiFactory apiFactory) { const int MAX_ATTEMPTS = 100; const int DELAY_MILLISECONDS = 100; for (int attempt = 0; attempt < MAX_ATTEMPTS; attempt++) { using IServiceScope scope = apiFactory.Services.CreateScope(); LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService(); if (await dbContext.Themes.AnyAsync(theme => theme.ThemeId == "editorial-paper" && theme.IsCurrent == true)) return; await Task.Delay(DELAY_MILLISECONDS); } Assert.Fail("The bundled theme 'editorial-paper' was not installed and activated within the expected time."); } }