99 lines
2.8 KiB
C#
99 lines
2.8 KiB
C#
using Shogi.AcceptanceTests.TestSetup;
|
|
using Shogi.Contracts.Api;
|
|
using Shogi.Contracts.Types;
|
|
using System.Net;
|
|
using System.Net.Http.Json;
|
|
using Xunit.Abstractions;
|
|
|
|
namespace Shogi.AcceptanceTests;
|
|
|
|
#pragma warning disable xUnit1033 // There is a bug which provides a false positive of xUnit1033.
|
|
public class AcceptanceTests : IClassFixture<GuestTestFixture>
|
|
#pragma warning restore xUnit1033
|
|
{
|
|
private readonly GuestTestFixture fixture;
|
|
private readonly ITestOutputHelper console;
|
|
|
|
public AcceptanceTests(GuestTestFixture fixture, ITestOutputHelper console)
|
|
{
|
|
this.fixture = fixture;
|
|
this.console = console;
|
|
}
|
|
|
|
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()
|
|
{
|
|
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");
|
|
|
|
}
|
|
} |