82 lines
3.2 KiB
C#
82 lines
3.2 KiB
C#
using System.Net;
|
|
using System.Net.Http.Json;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using NeonSprawl.Server.Game.Combat;
|
|
using NeonSprawl.Server.Game.Npc;
|
|
using NeonSprawl.Server.Tests;
|
|
using Xunit;
|
|
|
|
namespace NeonSprawl.Server.Tests.Game.Combat;
|
|
|
|
public sealed class CombatTargetFixtureApiTests
|
|
{
|
|
private const string FixturePath = "/game/__dev/combat-targets-fixture";
|
|
|
|
[Fact]
|
|
public async Task PostCombatTargetFixture_ShouldResetPrototypeTargets_WhenEnabled()
|
|
{
|
|
// Arrange
|
|
await using var factory = new InMemoryWebApplicationFactory();
|
|
var client = factory.CreateClient();
|
|
var store = factory.Services.GetRequiredService<ICombatEntityHealthStore>();
|
|
var threatStore = factory.Services.GetRequiredService<IThreatStateStore>();
|
|
var runtimeStore = factory.Services.GetRequiredService<INpcRuntimeStateStore>();
|
|
_ = store.TryApplyDamage(PrototypeNpcRegistry.PrototypeNpcMeleeId, 100, out _);
|
|
_ = threatStore.TrySetHolder(PrototypeNpcRegistry.PrototypeNpcMeleeId, "dev-local-1");
|
|
var windupStarted = new DateTimeOffset(2026, 5, 27, 12, 0, 0, TimeSpan.Zero);
|
|
_ = runtimeStore.TryWrite(
|
|
PrototypeNpcRegistry.PrototypeNpcMeleeId,
|
|
new NpcRuntimeStateSnapshot(
|
|
PrototypeNpcRegistry.PrototypeNpcMeleeId,
|
|
NpcBehaviorState.TelegraphWindup,
|
|
windupStarted,
|
|
new ActiveTelegraphSnapshot("prototype_npc_melee:test", windupStarted)));
|
|
|
|
// Act
|
|
var response = await client.PostAsJsonAsync(
|
|
FixturePath,
|
|
new CombatTargetFixtureRequest
|
|
{
|
|
SchemaVersion = CombatTargetFixtureRequest.CurrentSchemaVersion,
|
|
});
|
|
|
|
// Assert
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
var body = await response.Content.ReadFromJsonAsync<CombatTargetFixtureResponse>();
|
|
Assert.NotNull(body);
|
|
Assert.True(body!.Applied);
|
|
store.TryGet(PrototypeNpcRegistry.PrototypeNpcMeleeId, out var melee);
|
|
Assert.Equal(100, melee.CurrentHp);
|
|
Assert.False(melee.Defeated);
|
|
threatStore.TryGet(PrototypeNpcRegistry.PrototypeNpcMeleeId, out var threat);
|
|
Assert.Null(threat.AggroHolderPlayerId);
|
|
runtimeStore.TryGet(PrototypeNpcRegistry.PrototypeNpcMeleeId, out var runtime);
|
|
Assert.Equal(NpcBehaviorState.Idle, runtime.BehaviorState);
|
|
Assert.Null(runtime.ActiveTelegraph);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task PostCombatTargetFixture_ShouldReturnNotFound_WhenRouteNotRegistered()
|
|
{
|
|
// Arrange
|
|
await using var factory = new InMemoryWebApplicationFactory();
|
|
var client = factory.WithWebHostBuilder(b =>
|
|
{
|
|
b.UseEnvironment("Production");
|
|
b.UseSetting("Game:EnableCombatTargetFixtureApi", "false");
|
|
}).CreateClient();
|
|
|
|
// Act
|
|
var response = await client.PostAsJsonAsync(
|
|
FixturePath,
|
|
new CombatTargetFixtureRequest
|
|
{
|
|
SchemaVersion = CombatTargetFixtureRequest.CurrentSchemaVersion,
|
|
});
|
|
|
|
// Assert
|
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
|
}
|
|
}
|