Working on "Join Game" feature.
This commit is contained in:
@@ -12,16 +12,62 @@ namespace Shogi.AcceptanceTests;
|
||||
public class AcceptanceTests : IClassFixture<GuestTestFixture>
|
||||
#pragma warning restore xUnit1033
|
||||
{
|
||||
private readonly GuestTestFixture fixture;
|
||||
private readonly HttpClient guest1HttpClient;
|
||||
private readonly HttpClient guest2HttpClient;
|
||||
private readonly ITestOutputHelper console;
|
||||
|
||||
public AcceptanceTests(GuestTestFixture fixture, ITestOutputHelper console)
|
||||
{
|
||||
this.fixture = fixture;
|
||||
this.guest1HttpClient = fixture.Guest1ServiceClient;
|
||||
this.guest2HttpClient = fixture.Guest2ServiceClient;
|
||||
this.console = console;
|
||||
}
|
||||
|
||||
private HttpClient Service => fixture.Service;
|
||||
[Fact]
|
||||
public async Task JoinSession_Player2IsNotSet_SetsPlayer2()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Arrange
|
||||
await SetupTestSession();
|
||||
|
||||
// Act
|
||||
var joinResponse = await guest2HttpClient.PatchAsync(new Uri("Sessions/Acceptance Tests/Join", UriKind.Relative), null);
|
||||
|
||||
// Assert
|
||||
joinResponse.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||
var readSessionResponse = await ReadTestSession();
|
||||
readSessionResponse.Session.Player2.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
finally
|
||||
{
|
||||
await DeleteTestSession();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task JoinSession_SessionIsFull_Conflict()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Arrange
|
||||
await SetupTestSession();
|
||||
var joinResponse = await guest2HttpClient.PatchAsync(new Uri("Sessions/Acceptance Tests/Join", UriKind.Relative), null);
|
||||
joinResponse.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||
var readSessionResponse = await ReadTestSession();
|
||||
readSessionResponse.Session.Player2.Should().NotBeNullOrEmpty();
|
||||
|
||||
// Act
|
||||
joinResponse = await guest2HttpClient.PatchAsync(new Uri("Sessions/Acceptance Tests/Join", UriKind.Relative), null);
|
||||
|
||||
// Assert
|
||||
joinResponse.StatusCode.Should().Be(HttpStatusCode.Conflict);
|
||||
}
|
||||
finally
|
||||
{
|
||||
await DeleteTestSession();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReadSessionsPlayerCount()
|
||||
@@ -32,7 +78,7 @@ public class AcceptanceTests : IClassFixture<GuestTestFixture>
|
||||
await SetupTestSession();
|
||||
|
||||
// Act
|
||||
var readAllResponse = await Service
|
||||
var readAllResponse = await guest1HttpClient
|
||||
.GetFromJsonAsync<ReadSessionsPlayerCountResponse>(new Uri("Sessions/PlayerCount", UriKind.Relative),
|
||||
Contracts.ShogiApiJsonSerializerSettings.SystemTextJsonSerializerOptions);
|
||||
|
||||
@@ -42,7 +88,7 @@ public class AcceptanceTests : IClassFixture<GuestTestFixture>
|
||||
.PlayerHasJoinedSessions
|
||||
.Should()
|
||||
.ContainSingle(session => session.Name == "Acceptance Tests" && session.PlayerCount == 1);
|
||||
readAllResponse.AllOtherSessions.Should().BeEmpty();
|
||||
readAllResponse.AllOtherSessions.Should().NotBeNull();
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -60,7 +106,7 @@ public class AcceptanceTests : IClassFixture<GuestTestFixture>
|
||||
await SetupTestSession();
|
||||
|
||||
// Act
|
||||
var response = await Service.GetFromJsonAsync<ReadSessionResponse>(
|
||||
var response = await guest1HttpClient.GetFromJsonAsync<ReadSessionResponse>(
|
||||
new Uri("Sessions/Acceptance Tests", UriKind.Relative),
|
||||
Contracts.ShogiApiJsonSerializerSettings.SystemTextJsonSerializerOptions);
|
||||
|
||||
@@ -273,7 +319,7 @@ public class AcceptanceTests : IClassFixture<GuestTestFixture>
|
||||
};
|
||||
|
||||
// Act
|
||||
var response = await Service.PatchAsync(new Uri("Sessions/Acceptance Tests/Move", UriKind.Relative), JsonContent.Create(movePawnCommand));
|
||||
var response = await guest1HttpClient.PatchAsync(new Uri("Sessions/Acceptance Tests/Move", UriKind.Relative), JsonContent.Create(movePawnCommand));
|
||||
response.StatusCode.Should().Be(HttpStatusCode.NoContent, because: await response.Content.ReadAsStringAsync());
|
||||
|
||||
// Assert
|
||||
@@ -293,7 +339,7 @@ public class AcceptanceTests : IClassFixture<GuestTestFixture>
|
||||
|
||||
private async Task SetupTestSession()
|
||||
{
|
||||
var createResponse = await Service.PostAsJsonAsync(
|
||||
var createResponse = await guest1HttpClient.PostAsJsonAsync(
|
||||
new Uri("Sessions", UriKind.Relative),
|
||||
new CreateSessionCommand { Name = "Acceptance Tests" },
|
||||
Contracts.ShogiApiJsonSerializerSettings.SystemTextJsonSerializerOptions);
|
||||
@@ -302,12 +348,12 @@ public class AcceptanceTests : IClassFixture<GuestTestFixture>
|
||||
|
||||
private Task<ReadSessionResponse> ReadTestSession()
|
||||
{
|
||||
return Service.GetFromJsonAsync<ReadSessionResponse>(new Uri("Sessions/Acceptance Tests", UriKind.Relative))!;
|
||||
return guest1HttpClient.GetFromJsonAsync<ReadSessionResponse>(new Uri("Sessions/Acceptance Tests", UriKind.Relative))!;
|
||||
}
|
||||
|
||||
private async Task DeleteTestSession()
|
||||
{
|
||||
var response = await Service.DeleteAsync(new Uri("Sessions/Acceptance Tests", UriKind.Relative));
|
||||
var response = await guest1HttpClient.DeleteAsync(new Uri("Sessions/Acceptance Tests", UriKind.Relative));
|
||||
response.StatusCode.Should().Be(HttpStatusCode.NoContent, because: await response.Content.ReadAsStringAsync());
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user