40 lines
1.2 KiB
C#
40 lines
1.2 KiB
C#
using System.Net;
|
|
using GameList.Tests.Support;
|
|
|
|
namespace GameList.Tests;
|
|
|
|
public class MiddlewareTests
|
|
{
|
|
[Fact]
|
|
public async Task Deleted_player_cookie_is_signed_out()
|
|
{
|
|
using var factory = new TestWebApplicationFactory();
|
|
var client = factory.CreateClientWithCookies();
|
|
await client.RegisterAsync("ghost");
|
|
|
|
var playerId = await client.GetProfileIdAsync();
|
|
|
|
await factory.WithDbContextAsync(async db =>
|
|
{
|
|
var player = await db.Players.FindAsync(playerId);
|
|
db.Players.Remove(player!);
|
|
await db.SaveChangesAsync();
|
|
});
|
|
|
|
var resp = await client.GetAsync("/api/state");
|
|
Assert.Equal(HttpStatusCode.Unauthorized, resp.StatusCode);
|
|
Assert.Contains(resp.Headers, h => h.Key.Equals("Set-Cookie", StringComparison.OrdinalIgnoreCase));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Existing_player_passes_through_middleware()
|
|
{
|
|
using var factory = new TestWebApplicationFactory();
|
|
var client = factory.CreateClientWithCookies();
|
|
await client.RegisterAsync("live");
|
|
|
|
var resp = await client.GetAsync("/api/state");
|
|
Assert.Equal(HttpStatusCode.OK, resp.StatusCode);
|
|
}
|
|
}
|