neon-sprawl/server/NeonSprawl.Server.Tests/Game/PositionState/PositionStateApiTests.cs

66 lines
2.2 KiB
C#

using System.Net;
using System.Net.Http.Json;
using NeonSprawl.Server.Game.PositionState;
using Xunit;
namespace NeonSprawl.Server.Tests.Game.PositionState;
/// <summary>Integration tests for <see cref="NeonSprawl.Server.Game.PositionState.PositionStateApi"/> GET routes.</summary>
public class PositionStateApiTests(InMemoryWebApplicationFactory factory)
: IClassFixture<InMemoryWebApplicationFactory>
{
private readonly HttpClient httpClient = factory.CreateClient();
[Fact]
public async Task GetPosition_ShouldReturnVersionedPayloadAtOrigin_WhenDevPlayerRequested()
{
// Arrange
const string url = "/game/players/dev-local-1/position";
// Act
var response = await httpClient.GetAsync(url);
// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
var body = await response.Content.ReadFromJsonAsync<PositionStateResponse>();
Assert.NotNull(body);
Assert.Equal(PositionStateResponse.CurrentSchemaVersion, body.SchemaVersion);
Assert.Equal("dev-local-1", body.PlayerId);
Assert.NotNull(body.Position);
Assert.Equal(-5, body.Position.X);
Assert.Equal(0.9, body.Position.Y);
Assert.Equal(-5, body.Position.Z);
}
[Fact]
public async Task GetPosition_ShouldReturnOk_WhenPathIdDiffersOnlyByCase()
{
// Arrange
const string url = "/game/players/DEV-LOCAL-1/position";
// Act
var response = await httpClient.GetAsync(url);
// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
var body = await response.Content.ReadFromJsonAsync<PositionStateResponse>();
Assert.NotNull(body);
Assert.Equal(PositionStateResponse.CurrentSchemaVersion, body!.SchemaVersion);
Assert.Equal("DEV-LOCAL-1", body.PlayerId);
Assert.Equal(-5, body.Position!.X);
}
[Fact]
public async Task GetPosition_ShouldReturnNotFound_WhenPlayerIsUnknown()
{
// Arrange
const string url = "/game/players/unknown-player/position";
// Act
var response = await httpClient.GetAsync(url);
// Assert
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
}
}