create, read, playercount

This commit is contained in:
2022-11-09 16:08:04 -06:00
parent a1f996e508
commit da76917490
37 changed files with 999 additions and 814 deletions

View File

@@ -1,5 +1,6 @@
using Shogi.AcceptanceTests.TestSetup;
using Shogi.Contracts.Api;
using Shogi.Contracts.Types;
using System.Net;
using System.Net.Http.Json;
using Xunit.Abstractions;
@@ -21,16 +22,78 @@ public class AcceptanceTests : IClassFixture<GuestTestFixture>
private HttpClient Service => fixture.Service;
[Fact]
public async Task ReadSessionsPlayerCount()
{
try
{
// Arrange
await CreateSession();
// Act
var readAllResponse = await Service
.GetFromJsonAsync<ReadSessionsPlayerCountResponse>(new Uri("Sessions/PlayerCount", UriKind.Relative),
Contracts.ShogiApiJsonSerializerSettings.SystemTextJsonSerializerOptions);
// Assert
readAllResponse.Should().NotBeNull();
readAllResponse!
.AllOtherSessions
.Should()
.ContainSingle(session => session.Name == "Acceptance Tests" && session.PlayerCount == 1);
}
finally
{
// Annul
await DeleteSession();
}
}
[Fact]
public async Task CreateAndReadSession()
{
var createResponse = await Service.PostAsJsonAsync(new Uri("Session", UriKind.Relative), new CreateSessionCommand { Name = "Acceptance Tests" });
createResponse.StatusCode.Should().Be(HttpStatusCode.Created);
var yep = await createResponse.Content.ReadAsStringAsync();
console.WriteLine(yep);
try
{
// Arrange
await CreateSession();
// Act
var response = await Service.GetFromJsonAsync<ReadSessionResponse>(
new Uri("Sessions/Acceptance Tests", UriKind.Relative),
Contracts.ShogiApiJsonSerializerSettings.SystemTextJsonSerializerOptions);
// Assert
response.Should().NotBeNull();
response!.Session.Should().NotBeNull();
response.Session.BoardState.Board.Should().NotBeEmpty();
response.Session.BoardState.Player1Hand.Should().BeEmpty();
response.Session.BoardState.Player2Hand.Should().BeEmpty();
response.Session.BoardState.PlayerInCheck.Should().BeNull();
response.Session.BoardState.WhoseTurn.Should().Be(WhichPlayer.Player1);
response.Session.Player1.Should().NotBeNullOrEmpty();
response.Session.Player2.Should().BeNull();
response.Session.SessionName.Should().Be("Acceptance Tests");
}
finally
{
// Annul
await DeleteSession();
}
}
private async Task CreateSession()
{
var createResponse = await Service.PostAsJsonAsync(
new Uri("Sessions", UriKind.Relative),
new CreateSessionCommand { Name = "Acceptance Tests" },
Contracts.ShogiApiJsonSerializerSettings.SystemTextJsonSerializerOptions);
createResponse.StatusCode.Should().Be(HttpStatusCode.Created);
}
private async Task DeleteSession()
{
var response = await Service.DeleteAsync(new Uri("Sessions/Acceptance Tests", UriKind.Relative));
response.StatusCode.Should().Be(HttpStatusCode.NoContent, because: "Test cleanup should succeed");
var readAllResponse = await Service.GetFromJsonAsync<ReadAllSessionsResponse>(new Uri("Session", UriKind.Relative));
readAllResponse.Should().NotBeNull();
readAllResponse!.AllOtherSessions.Should().ContainSingle(session => session.Name == "Acceptance Tests" && session.PlayerCount == 1);
}
}