NEO-31: structure AbilityCastApiTests in explicit AAA sections
parent
b5b8c10d36
commit
7c327994eb
|
|
@ -23,10 +23,12 @@ public sealed class AbilityCastApiTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task PostAbilityCast_ShouldAccept_WhenLoadoutMatches()
|
public async Task PostAbilityCast_ShouldAccept_WhenLoadoutMatches()
|
||||||
{
|
{
|
||||||
|
// Arrange
|
||||||
await using var factory = new InMemoryWebApplicationFactory();
|
await using var factory = new InMemoryWebApplicationFactory();
|
||||||
var client = factory.CreateClient();
|
var client = factory.CreateClient();
|
||||||
await BindSlot0PulseAsync(client);
|
await BindSlot0PulseAsync(client);
|
||||||
|
|
||||||
|
// Act
|
||||||
var response = await client.PostAsJsonAsync(
|
var response = await client.PostAsJsonAsync(
|
||||||
"/game/players/dev-local-1/ability-cast",
|
"/game/players/dev-local-1/ability-cast",
|
||||||
new AbilityCastRequest
|
new AbilityCastRequest
|
||||||
|
|
@ -38,6 +40,7 @@ public sealed class AbilityCastApiTests
|
||||||
});
|
});
|
||||||
var body = await response.Content.ReadFromJsonAsync<AbilityCastResponse>();
|
var body = await response.Content.ReadFromJsonAsync<AbilityCastResponse>();
|
||||||
|
|
||||||
|
// Assert
|
||||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
Assert.NotNull(body);
|
Assert.NotNull(body);
|
||||||
Assert.True(body!.Accepted);
|
Assert.True(body!.Accepted);
|
||||||
|
|
@ -47,10 +50,12 @@ public sealed class AbilityCastApiTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task PostAbilityCast_ShouldAccept_WithTargetId_WhenLoadoutMatches()
|
public async Task PostAbilityCast_ShouldAccept_WithTargetId_WhenLoadoutMatches()
|
||||||
{
|
{
|
||||||
|
// Arrange
|
||||||
await using var factory = new InMemoryWebApplicationFactory();
|
await using var factory = new InMemoryWebApplicationFactory();
|
||||||
var client = factory.CreateClient();
|
var client = factory.CreateClient();
|
||||||
await BindSlot0PulseAsync(client);
|
await BindSlot0PulseAsync(client);
|
||||||
|
|
||||||
|
// Act
|
||||||
var response = await client.PostAsJsonAsync(
|
var response = await client.PostAsJsonAsync(
|
||||||
"/game/players/dev-local-1/ability-cast",
|
"/game/players/dev-local-1/ability-cast",
|
||||||
new AbilityCastRequest
|
new AbilityCastRequest
|
||||||
|
|
@ -62,6 +67,7 @@ public sealed class AbilityCastApiTests
|
||||||
});
|
});
|
||||||
var body = await response.Content.ReadFromJsonAsync<AbilityCastResponse>();
|
var body = await response.Content.ReadFromJsonAsync<AbilityCastResponse>();
|
||||||
|
|
||||||
|
// Assert
|
||||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
Assert.NotNull(body);
|
Assert.NotNull(body);
|
||||||
Assert.True(body!.Accepted);
|
Assert.True(body!.Accepted);
|
||||||
|
|
@ -70,9 +76,11 @@ public sealed class AbilityCastApiTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task PostAbilityCast_ShouldDenySlotUnbound_WhenSlotEmpty()
|
public async Task PostAbilityCast_ShouldDenySlotUnbound_WhenSlotEmpty()
|
||||||
{
|
{
|
||||||
|
// Arrange
|
||||||
await using var factory = new InMemoryWebApplicationFactory();
|
await using var factory = new InMemoryWebApplicationFactory();
|
||||||
var client = factory.CreateClient();
|
var client = factory.CreateClient();
|
||||||
|
|
||||||
|
// Act
|
||||||
var response = await client.PostAsJsonAsync(
|
var response = await client.PostAsJsonAsync(
|
||||||
"/game/players/dev-local-1/ability-cast",
|
"/game/players/dev-local-1/ability-cast",
|
||||||
new AbilityCastRequest
|
new AbilityCastRequest
|
||||||
|
|
@ -84,6 +92,7 @@ public sealed class AbilityCastApiTests
|
||||||
});
|
});
|
||||||
var body = await response.Content.ReadFromJsonAsync<AbilityCastResponse>();
|
var body = await response.Content.ReadFromJsonAsync<AbilityCastResponse>();
|
||||||
|
|
||||||
|
// Assert
|
||||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
Assert.NotNull(body);
|
Assert.NotNull(body);
|
||||||
Assert.False(body!.Accepted);
|
Assert.False(body!.Accepted);
|
||||||
|
|
@ -93,10 +102,12 @@ public sealed class AbilityCastApiTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task PostAbilityCast_ShouldDenyLoadoutMismatch_WhenAbilityDoesNotMatchSlot()
|
public async Task PostAbilityCast_ShouldDenyLoadoutMismatch_WhenAbilityDoesNotMatchSlot()
|
||||||
{
|
{
|
||||||
|
// Arrange
|
||||||
await using var factory = new InMemoryWebApplicationFactory();
|
await using var factory = new InMemoryWebApplicationFactory();
|
||||||
var client = factory.CreateClient();
|
var client = factory.CreateClient();
|
||||||
await BindSlot0PulseAsync(client);
|
await BindSlot0PulseAsync(client);
|
||||||
|
|
||||||
|
// Act
|
||||||
var response = await client.PostAsJsonAsync(
|
var response = await client.PostAsJsonAsync(
|
||||||
"/game/players/dev-local-1/ability-cast",
|
"/game/players/dev-local-1/ability-cast",
|
||||||
new AbilityCastRequest
|
new AbilityCastRequest
|
||||||
|
|
@ -108,6 +119,7 @@ public sealed class AbilityCastApiTests
|
||||||
});
|
});
|
||||||
var body = await response.Content.ReadFromJsonAsync<AbilityCastResponse>();
|
var body = await response.Content.ReadFromJsonAsync<AbilityCastResponse>();
|
||||||
|
|
||||||
|
// Assert
|
||||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
Assert.NotNull(body);
|
Assert.NotNull(body);
|
||||||
Assert.False(body!.Accepted);
|
Assert.False(body!.Accepted);
|
||||||
|
|
@ -117,10 +129,12 @@ public sealed class AbilityCastApiTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task PostAbilityCast_ShouldDenySlotOutOfBounds()
|
public async Task PostAbilityCast_ShouldDenySlotOutOfBounds()
|
||||||
{
|
{
|
||||||
|
// Arrange
|
||||||
await using var factory = new InMemoryWebApplicationFactory();
|
await using var factory = new InMemoryWebApplicationFactory();
|
||||||
var client = factory.CreateClient();
|
var client = factory.CreateClient();
|
||||||
await BindSlot0PulseAsync(client);
|
await BindSlot0PulseAsync(client);
|
||||||
|
|
||||||
|
// Act
|
||||||
var response = await client.PostAsJsonAsync(
|
var response = await client.PostAsJsonAsync(
|
||||||
"/game/players/dev-local-1/ability-cast",
|
"/game/players/dev-local-1/ability-cast",
|
||||||
new AbilityCastRequest
|
new AbilityCastRequest
|
||||||
|
|
@ -132,6 +146,7 @@ public sealed class AbilityCastApiTests
|
||||||
});
|
});
|
||||||
var body = await response.Content.ReadFromJsonAsync<AbilityCastResponse>();
|
var body = await response.Content.ReadFromJsonAsync<AbilityCastResponse>();
|
||||||
|
|
||||||
|
// Assert
|
||||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
Assert.NotNull(body);
|
Assert.NotNull(body);
|
||||||
Assert.False(body!.Accepted);
|
Assert.False(body!.Accepted);
|
||||||
|
|
@ -141,10 +156,12 @@ public sealed class AbilityCastApiTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task PostAbilityCast_ShouldDenyUnknownAbility_WhenAbilityIdNotInRegistry()
|
public async Task PostAbilityCast_ShouldDenyUnknownAbility_WhenAbilityIdNotInRegistry()
|
||||||
{
|
{
|
||||||
|
// Arrange
|
||||||
await using var factory = new InMemoryWebApplicationFactory();
|
await using var factory = new InMemoryWebApplicationFactory();
|
||||||
var client = factory.CreateClient();
|
var client = factory.CreateClient();
|
||||||
await BindSlot0PulseAsync(client);
|
await BindSlot0PulseAsync(client);
|
||||||
|
|
||||||
|
// Act
|
||||||
var response = await client.PostAsJsonAsync(
|
var response = await client.PostAsJsonAsync(
|
||||||
"/game/players/dev-local-1/ability-cast",
|
"/game/players/dev-local-1/ability-cast",
|
||||||
new AbilityCastRequest
|
new AbilityCastRequest
|
||||||
|
|
@ -156,6 +173,7 @@ public sealed class AbilityCastApiTests
|
||||||
});
|
});
|
||||||
var body = await response.Content.ReadFromJsonAsync<AbilityCastResponse>();
|
var body = await response.Content.ReadFromJsonAsync<AbilityCastResponse>();
|
||||||
|
|
||||||
|
// Assert
|
||||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
Assert.NotNull(body);
|
Assert.NotNull(body);
|
||||||
Assert.False(body!.Accepted);
|
Assert.False(body!.Accepted);
|
||||||
|
|
@ -165,49 +183,58 @@ public sealed class AbilityCastApiTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task PostAbilityCast_ShouldReturnBadRequest_WhenBodyMalformed()
|
public async Task PostAbilityCast_ShouldReturnBadRequest_WhenBodyMalformed()
|
||||||
{
|
{
|
||||||
|
// Arrange
|
||||||
await using var factory = new InMemoryWebApplicationFactory();
|
await using var factory = new InMemoryWebApplicationFactory();
|
||||||
var client = factory.CreateClient();
|
var client = factory.CreateClient();
|
||||||
|
var malformed = new StringContent(
|
||||||
|
"{\"schemaVersion\":1,\"slotIndex\":",
|
||||||
|
Encoding.UTF8,
|
||||||
|
"application/json");
|
||||||
|
|
||||||
var response = await client.PostAsync(
|
// Act
|
||||||
"/game/players/dev-local-1/ability-cast",
|
var response = await client.PostAsync("/game/players/dev-local-1/ability-cast", malformed);
|
||||||
new StringContent("{\"schemaVersion\":1,\"slotIndex\":", Encoding.UTF8, "application/json"));
|
|
||||||
|
|
||||||
|
// Assert
|
||||||
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task PostAbilityCast_ShouldReturnBadRequest_WhenSchemaVersionWrong()
|
public async Task PostAbilityCast_ShouldReturnBadRequest_WhenSchemaVersionWrong()
|
||||||
{
|
{
|
||||||
|
// Arrange
|
||||||
await using var factory = new InMemoryWebApplicationFactory();
|
await using var factory = new InMemoryWebApplicationFactory();
|
||||||
var client = factory.CreateClient();
|
var client = factory.CreateClient();
|
||||||
|
var request = new AbilityCastRequest
|
||||||
|
{
|
||||||
|
SchemaVersion = 999,
|
||||||
|
SlotIndex = 0,
|
||||||
|
AbilityId = PrototypeAbilityRegistry.PrototypePulse,
|
||||||
|
};
|
||||||
|
|
||||||
var response = await client.PostAsJsonAsync(
|
// Act
|
||||||
"/game/players/dev-local-1/ability-cast",
|
var response = await client.PostAsJsonAsync("/game/players/dev-local-1/ability-cast", request);
|
||||||
new AbilityCastRequest
|
|
||||||
{
|
|
||||||
SchemaVersion = 999,
|
|
||||||
SlotIndex = 0,
|
|
||||||
AbilityId = PrototypeAbilityRegistry.PrototypePulse,
|
|
||||||
});
|
|
||||||
|
|
||||||
|
// Assert
|
||||||
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task PostAbilityCast_ShouldReturnNotFound_WhenPlayerUnknown()
|
public async Task PostAbilityCast_ShouldReturnNotFound_WhenPlayerUnknown()
|
||||||
{
|
{
|
||||||
|
// Arrange
|
||||||
await using var factory = new InMemoryWebApplicationFactory();
|
await using var factory = new InMemoryWebApplicationFactory();
|
||||||
var client = factory.CreateClient();
|
var client = factory.CreateClient();
|
||||||
|
var request = new AbilityCastRequest
|
||||||
|
{
|
||||||
|
SchemaVersion = AbilityCastRequest.CurrentSchemaVersion,
|
||||||
|
SlotIndex = 0,
|
||||||
|
AbilityId = PrototypeAbilityRegistry.PrototypePulse,
|
||||||
|
};
|
||||||
|
|
||||||
var response = await client.PostAsJsonAsync(
|
// Act
|
||||||
"/game/players/missing-player/ability-cast",
|
var response = await client.PostAsJsonAsync("/game/players/missing-player/ability-cast", request);
|
||||||
new AbilityCastRequest
|
|
||||||
{
|
|
||||||
SchemaVersion = AbilityCastRequest.CurrentSchemaVersion,
|
|
||||||
SlotIndex = 0,
|
|
||||||
AbilityId = PrototypeAbilityRegistry.PrototypePulse,
|
|
||||||
});
|
|
||||||
|
|
||||||
|
// Assert
|
||||||
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue