62 lines
2.2 KiB
C#
62 lines
2.2 KiB
C#
using Microsoft.AspNetCore.Hosting;
|
|
using NeonSprawl.Server.Game.Gathering;
|
|
|
|
namespace NeonSprawl.Server.Tests.Game.Gathering;
|
|
|
|
public sealed class ResourceNodeFixtureApiTests
|
|
{
|
|
private const string FixturePath = "/game/__dev/resource-node-fixture";
|
|
private const string AlphaId = "prototype_resource_node_alpha";
|
|
|
|
[Fact]
|
|
public async Task PostResourceNodeFixture_ShouldRestoreMaxGathers_WhenNodeDepleted()
|
|
{
|
|
// Arrange
|
|
await using var factory = new InMemoryWebApplicationFactory();
|
|
var client = factory.CreateClient();
|
|
var store = factory.Services.GetRequiredService<IResourceNodeInstanceStore>();
|
|
var registry = factory.Services.GetRequiredService<IResourceNodeDefinitionRegistry>();
|
|
registry.TryGetDefinition(AlphaId, out var definition);
|
|
store.TryEnsureInitialized(AlphaId, initialRemainingGathers: 0);
|
|
|
|
// Act
|
|
var response = await client.PostAsJsonAsync(
|
|
FixturePath,
|
|
new ResourceNodeFixtureRequest
|
|
{
|
|
SchemaVersion = ResourceNodeFixtureRequest.CurrentSchemaVersion,
|
|
});
|
|
|
|
// Assert
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
var body = await response.Content.ReadFromJsonAsync<ResourceNodeFixtureResponse>();
|
|
Assert.NotNull(body);
|
|
Assert.True(body!.Applied);
|
|
store.TryGetRemainingGathers(AlphaId, out var snapshot);
|
|
Assert.Equal(definition!.MaxGathers, snapshot.RemainingGathers);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task PostResourceNodeFixture_ShouldReturnNotFound_WhenRouteNotRegistered()
|
|
{
|
|
// Arrange
|
|
await using var factory = new InMemoryWebApplicationFactory();
|
|
var client = factory.WithWebHostBuilder(b =>
|
|
{
|
|
b.UseEnvironment("Production");
|
|
b.UseSetting("Game:EnableResourceNodeFixtureApi", "false");
|
|
}).CreateClient();
|
|
|
|
// Act
|
|
var response = await client.PostAsJsonAsync(
|
|
FixturePath,
|
|
new ResourceNodeFixtureRequest
|
|
{
|
|
SchemaVersion = ResourceNodeFixtureRequest.CurrentSchemaVersion,
|
|
});
|
|
|
|
// Assert
|
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
|
}
|
|
}
|