65 lines
3.8 KiB
C#
65 lines
3.8 KiB
C#
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Mvc.Testing;
|
|
using Microsoft.Extensions.Configuration;
|
|
using NeonSprawl.Server.Game.Combat;
|
|
using NeonSprawl.Server.Game.Crafting;
|
|
using NeonSprawl.Server.Game.Gathering;
|
|
using NeonSprawl.Server.Game.Items;
|
|
using NeonSprawl.Server.Game.Mastery;
|
|
|
|
namespace NeonSprawl.Server.Tests.Game.PositionState;
|
|
|
|
/// <summary>Integration host with <see cref="PositionStateServiceCollectionExtensions.NeonSprawlConnectionStringName"/> bound from environment.</summary>
|
|
public sealed class PostgresWebApplicationFactory : WebApplicationFactory<Program>
|
|
{
|
|
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
|
{
|
|
var cs = Environment.GetEnvironmentVariable("ConnectionStrings__NeonSprawl");
|
|
PostgresDockerHelper.EnsurePostgresOrStartDockerBlocking(cs);
|
|
if (string.IsNullOrWhiteSpace(cs))
|
|
{
|
|
throw new InvalidOperationException(
|
|
"Set ConnectionStrings__NeonSprawl for Postgres integration tests (see server/README.md).");
|
|
}
|
|
|
|
builder.UseEnvironment("Testing");
|
|
|
|
var skillsDir = SkillCatalogPathResolution.TryDiscoverSkillsDirectory(AppContext.BaseDirectory)
|
|
?? throw new InvalidOperationException(
|
|
"Could not discover repo content/skills from AppContext.BaseDirectory; run tests from the neon-sprawl clone.");
|
|
var masteryDir = MasteryCatalogPathResolution.TryDiscoverMasteryDirectory(AppContext.BaseDirectory)
|
|
?? throw new InvalidOperationException(
|
|
"Could not discover repo content/mastery from AppContext.BaseDirectory; run tests from the neon-sprawl clone.");
|
|
var itemsDir = ItemCatalogPathResolution.TryDiscoverItemsDirectory(AppContext.BaseDirectory)
|
|
?? throw new InvalidOperationException(
|
|
"Could not discover repo content/items from AppContext.BaseDirectory; run tests from the neon-sprawl clone.");
|
|
var resourceNodesDir = ResourceNodeCatalogPathResolution.TryDiscoverResourceNodesDirectory(AppContext.BaseDirectory)
|
|
?? throw new InvalidOperationException(
|
|
"Could not discover repo content/resource-nodes from AppContext.BaseDirectory; run tests from the neon-sprawl clone.");
|
|
var recipesDir = RecipeCatalogPathResolution.TryDiscoverRecipesDirectory(AppContext.BaseDirectory)
|
|
?? throw new InvalidOperationException(
|
|
"Could not discover repo content/recipes from AppContext.BaseDirectory; run tests from the neon-sprawl clone.");
|
|
var abilitiesDir = AbilityCatalogPathResolution.TryDiscoverAbilitiesDirectory(AppContext.BaseDirectory)
|
|
?? throw new InvalidOperationException(
|
|
"Could not discover repo content/abilities from AppContext.BaseDirectory; run tests from the neon-sprawl clone.");
|
|
var npcBehaviorsDir = NpcBehaviorCatalogPathResolution.TryDiscoverNpcBehaviorsDirectory(AppContext.BaseDirectory)
|
|
?? throw new InvalidOperationException(
|
|
"Could not discover repo content/npc-behaviors from AppContext.BaseDirectory; run tests from the neon-sprawl clone.");
|
|
builder.UseSetting("Content:SkillsDirectory", skillsDir);
|
|
builder.UseSetting("Content:MasteryDirectory", masteryDir);
|
|
builder.UseSetting("Content:ItemsDirectory", itemsDir);
|
|
builder.UseSetting("Content:ResourceNodesDirectory", resourceNodesDir);
|
|
builder.UseSetting("Content:RecipesDirectory", recipesDir);
|
|
builder.UseSetting("Content:AbilitiesDirectory", abilitiesDir);
|
|
builder.UseSetting("Content:NpcBehaviorsDirectory", npcBehaviorsDir);
|
|
|
|
builder.ConfigureAppConfiguration((_, config) =>
|
|
{
|
|
config.AddInMemoryCollection(new Dictionary<string, string?>
|
|
{
|
|
["ConnectionStrings:NeonSprawl"] = cs.Trim(),
|
|
});
|
|
});
|
|
}
|
|
}
|