Working on "Join Game" feature.
This commit is contained in:
@@ -15,22 +15,36 @@ public class GuestTestFixture : IAsyncLifetime, IDisposable
|
||||
.AddJsonFile("appsettings.json")
|
||||
.Build();
|
||||
|
||||
Service = new HttpClient
|
||||
var baseUrl = Configuration["ServiceUrl"] ?? throw new InvalidOperationException("ServiceUrl configuration missing.");
|
||||
var baseAddress = new Uri(baseUrl, UriKind.Absolute);
|
||||
Guest1ServiceClient = new HttpClient
|
||||
{
|
||||
BaseAddress = new Uri(Configuration["ServiceUrl"], UriKind.Absolute)
|
||||
BaseAddress = baseAddress
|
||||
};
|
||||
Guest2ServiceClient = new HttpClient
|
||||
{
|
||||
BaseAddress = baseAddress
|
||||
};
|
||||
}
|
||||
|
||||
public IConfiguration Configuration { get; private set; }
|
||||
public HttpClient Service { get; }
|
||||
public HttpClient Guest2ServiceClient { get; }
|
||||
public HttpClient Guest1ServiceClient { get; }
|
||||
|
||||
public async Task InitializeAsync()
|
||||
public async Task InitializeAsync()
|
||||
{
|
||||
// Log in as a guest account and retain the session cookie for future requests.
|
||||
var loginResponse = await Service.GetAsync(new Uri("User/LoginAsGuest", UriKind.Relative));
|
||||
// Log in as some guest accounts and retain the session cookie for future requests.
|
||||
var guestLoginUri = new Uri("User/LoginAsGuest", UriKind.Relative);
|
||||
|
||||
var loginResponse = await Guest1ServiceClient.GetAsync(guestLoginUri);
|
||||
loginResponse.IsSuccessStatusCode.Should().BeTrue(because: "Guest accounts should work");
|
||||
var guestSessionCookie = loginResponse.Headers.GetValues("Set-Cookie").SingleOrDefault();
|
||||
Service.DefaultRequestHeaders.Add("Set-Cookie", guestSessionCookie);
|
||||
var guestSessionCookie = loginResponse.Headers.GetValues("Set-Cookie").Single();
|
||||
Guest1ServiceClient.DefaultRequestHeaders.Add("Set-Cookie", guestSessionCookie);
|
||||
|
||||
loginResponse = await Guest2ServiceClient.GetAsync(guestLoginUri);
|
||||
loginResponse.IsSuccessStatusCode.Should().BeTrue(because: "Guest accounts should work twice");
|
||||
guestSessionCookie = loginResponse.Headers.GetValues("Set-Cookie").Single();
|
||||
Guest2ServiceClient.DefaultRequestHeaders.Add("Set-Cookie", guestSessionCookie);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
@@ -39,7 +53,7 @@ public class GuestTestFixture : IAsyncLifetime, IDisposable
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
Service.Dispose();
|
||||
Guest1ServiceClient.Dispose();
|
||||
}
|
||||
|
||||
disposedValue = true;
|
||||
|
||||
Reference in New Issue
Block a user