C# formatting
This commit is contained in:
@@ -2,7 +2,6 @@ using System.Net;
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json;
|
||||
using GameList.Tests.Support;
|
||||
using GameList.Domain;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace GameList.Tests;
|
||||
@@ -12,7 +11,7 @@ public class SuggestionTests
|
||||
[Fact]
|
||||
public async Task Player_cannot_exceed_five_suggestions()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var client = factory.CreateClientWithCookies();
|
||||
await client.RegisterAsync("suggestor");
|
||||
|
||||
@@ -50,7 +49,7 @@ public class SuggestionTests
|
||||
[Fact]
|
||||
public async Task Rejects_invalid_image_extension_and_player_counts()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var client = factory.CreateClientWithCookies();
|
||||
await client.RegisterAsync("validate");
|
||||
|
||||
@@ -84,7 +83,7 @@ public class SuggestionTests
|
||||
[Fact]
|
||||
public async Task Joker_allows_single_extra_suggestion_and_unfinalizes_votes()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var player = factory.CreateClientWithCookies();
|
||||
await player.RegisterAsync("joker");
|
||||
var other = factory.CreateClientWithCookies();
|
||||
@@ -126,7 +125,7 @@ public class SuggestionTests
|
||||
[Fact]
|
||||
public async Task Admin_can_update_during_vote_phase()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var admin = factory.CreateClientWithCookies();
|
||||
await admin.RegisterAsync("admin", admin: true);
|
||||
|
||||
@@ -152,7 +151,7 @@ public class SuggestionTests
|
||||
[Fact]
|
||||
public async Task Phase_gate_blocks_player_update_in_vote_phase()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var player = factory.CreateClientWithCookies();
|
||||
await player.RegisterAsync("phase");
|
||||
var id = await player.CreateSuggestionAsync("Lock");
|
||||
@@ -180,7 +179,7 @@ public class SuggestionTests
|
||||
[Fact]
|
||||
public async Task Player_cannot_edit_suggestion_in_results_phase()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var player = factory.CreateClientWithCookies();
|
||||
await player.RegisterAsync("results");
|
||||
var id = await player.CreateSuggestionAsync("Frozen");
|
||||
@@ -217,7 +216,7 @@ public class SuggestionTests
|
||||
[Fact]
|
||||
public async Task Player_cannot_edit_other_players_suggestion()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var owner = factory.CreateClientWithCookies();
|
||||
await owner.RegisterAsync("owner");
|
||||
var other = factory.CreateClientWithCookies();
|
||||
@@ -243,7 +242,7 @@ public class SuggestionTests
|
||||
[Fact]
|
||||
public async Task Joker_allows_unlimited_extra_suggestions_when_granted_multiple_times()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var client = factory.CreateClientWithCookies();
|
||||
await client.RegisterAsync("sixth");
|
||||
|
||||
@@ -327,7 +326,7 @@ public class SuggestionTests
|
||||
[Fact]
|
||||
public async Task Unreachable_screenshot_url_is_rejected()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
factory.HttpHandler.SetResponder(_ => new HttpResponseMessage(HttpStatusCode.BadRequest));
|
||||
|
||||
var client = factory.CreateClientWithCookies();
|
||||
@@ -351,7 +350,7 @@ public class SuggestionTests
|
||||
[Fact]
|
||||
public async Task Get_all_requires_vote_phase()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var client = factory.CreateClientWithCookies();
|
||||
await client.RegisterAsync("viewer");
|
||||
|
||||
@@ -362,13 +361,33 @@ public class SuggestionTests
|
||||
[Fact]
|
||||
public async Task Mine_returns_ordered_list()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var client = factory.CreateClientWithCookies();
|
||||
await client.RegisterAsync("mine");
|
||||
|
||||
await client.PostAsJsonAsync("/api/suggestions", new { Name = "Second", Genre = (string?)null, Description = (string?)null, ScreenshotUrl = (string?)null, YoutubeUrl = (string?)null, GameUrl = (string?)null, MinPlayers = (int?)null, MaxPlayers = (int?)null });
|
||||
await client.PostAsJsonAsync("/api/suggestions", new
|
||||
{
|
||||
Name = "Second",
|
||||
Genre = (string?)null,
|
||||
Description = (string?)null,
|
||||
ScreenshotUrl = (string?)null,
|
||||
YoutubeUrl = (string?)null,
|
||||
GameUrl = (string?)null,
|
||||
MinPlayers = (int?)null,
|
||||
MaxPlayers = (int?)null
|
||||
});
|
||||
await Task.Delay(10);
|
||||
await client.PostAsJsonAsync("/api/suggestions", new { Name = "Third", Genre = (string?)null, Description = (string?)null, ScreenshotUrl = (string?)null, YoutubeUrl = (string?)null, GameUrl = (string?)null, MinPlayers = (int?)null, MaxPlayers = (int?)null });
|
||||
await client.PostAsJsonAsync("/api/suggestions", new
|
||||
{
|
||||
Name = "Third",
|
||||
Genre = (string?)null,
|
||||
Description = (string?)null,
|
||||
ScreenshotUrl = (string?)null,
|
||||
YoutubeUrl = (string?)null,
|
||||
GameUrl = (string?)null,
|
||||
MinPlayers = (int?)null,
|
||||
MaxPlayers = (int?)null
|
||||
});
|
||||
|
||||
var mine = await client.GetFromJsonAsync<List<JsonElement>>("/api/suggestions/mine");
|
||||
Assert.Equal("Second", mine![0].GetProperty("name").GetString());
|
||||
@@ -377,7 +396,7 @@ public class SuggestionTests
|
||||
[Fact]
|
||||
public async Task Create_requires_suggest_phase_and_display_name()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var client = factory.CreateClientWithCookies();
|
||||
await client.RegisterAsync("phasegate");
|
||||
|
||||
@@ -389,7 +408,17 @@ public class SuggestionTests
|
||||
await db.SaveChangesAsync();
|
||||
});
|
||||
|
||||
var badPhase = await client.PostAsJsonAsync("/api/suggestions", new { Name = "Nope", Genre = (string?)null, Description = (string?)null, ScreenshotUrl = (string?)null, YoutubeUrl = (string?)null, GameUrl = (string?)null, MinPlayers = (int?)null, MaxPlayers = (int?)null });
|
||||
var badPhase = await client.PostAsJsonAsync("/api/suggestions", new
|
||||
{
|
||||
Name = "Nope",
|
||||
Genre = (string?)null,
|
||||
Description = (string?)null,
|
||||
ScreenshotUrl = (string?)null,
|
||||
YoutubeUrl = (string?)null,
|
||||
GameUrl = (string?)null,
|
||||
MinPlayers = (int?)null,
|
||||
MaxPlayers = (int?)null
|
||||
});
|
||||
Assert.Equal(HttpStatusCode.BadRequest, badPhase.StatusCode);
|
||||
|
||||
await factory.WithDbContextAsync(async db =>
|
||||
@@ -399,37 +428,97 @@ public class SuggestionTests
|
||||
await db.SaveChangesAsync();
|
||||
});
|
||||
|
||||
var noDisplay = await client.PostAsJsonAsync("/api/suggestions", new { Name = "NoDisplay", Genre = (string?)null, Description = (string?)null, ScreenshotUrl = (string?)null, YoutubeUrl = (string?)null, GameUrl = (string?)null, MinPlayers = (int?)null, MaxPlayers = (int?)null });
|
||||
var noDisplay = await client.PostAsJsonAsync("/api/suggestions", new
|
||||
{
|
||||
Name = "NoDisplay",
|
||||
Genre = (string?)null,
|
||||
Description = (string?)null,
|
||||
ScreenshotUrl = (string?)null,
|
||||
YoutubeUrl = (string?)null,
|
||||
GameUrl = (string?)null,
|
||||
MinPlayers = (int?)null,
|
||||
MaxPlayers = (int?)null
|
||||
});
|
||||
Assert.Equal(HttpStatusCode.BadRequest, noDisplay.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Rejects_invalid_urls_name_length_and_player_counts()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var client = factory.CreateClientWithCookies();
|
||||
await client.RegisterAsync("validate2");
|
||||
|
||||
var badGame = await client.PostAsJsonAsync("/api/suggestions", new { Name = "Bad", Genre = (string?)null, Description = (string?)null, ScreenshotUrl = (string?)null, YoutubeUrl = (string?)null, GameUrl = "ftp://bad", MinPlayers = (int?)null, MaxPlayers = (int?)null });
|
||||
var badGame = await client.PostAsJsonAsync("/api/suggestions", new
|
||||
{
|
||||
Name = "Bad",
|
||||
Genre = (string?)null,
|
||||
Description = (string?)null,
|
||||
ScreenshotUrl = (string?)null,
|
||||
YoutubeUrl = (string?)null,
|
||||
GameUrl = "ftp://bad",
|
||||
MinPlayers = (int?)null,
|
||||
MaxPlayers = (int?)null
|
||||
});
|
||||
Assert.Equal(HttpStatusCode.BadRequest, badGame.StatusCode);
|
||||
|
||||
var badYoutube = await client.PostAsJsonAsync("/api/suggestions", new { Name = "BadYt", Genre = (string?)null, Description = (string?)null, ScreenshotUrl = (string?)null, YoutubeUrl = "file://bad", GameUrl = (string?)null, MinPlayers = (int?)null, MaxPlayers = (int?)null });
|
||||
var badYoutube = await client.PostAsJsonAsync("/api/suggestions", new
|
||||
{
|
||||
Name = "BadYt",
|
||||
Genre = (string?)null,
|
||||
Description = (string?)null,
|
||||
ScreenshotUrl = (string?)null,
|
||||
YoutubeUrl = "file://bad",
|
||||
GameUrl = (string?)null,
|
||||
MinPlayers = (int?)null,
|
||||
MaxPlayers = (int?)null
|
||||
});
|
||||
Assert.Equal(HttpStatusCode.BadRequest, badYoutube.StatusCode);
|
||||
|
||||
var longName = await client.PostAsJsonAsync("/api/suggestions", new { Name = new string('x', 101), Genre = (string?)null, Description = (string?)null, ScreenshotUrl = (string?)null, YoutubeUrl = (string?)null, GameUrl = (string?)null, MinPlayers = (int?)null, MaxPlayers = (int?)null });
|
||||
var longName = await client.PostAsJsonAsync("/api/suggestions", new
|
||||
{
|
||||
Name = new string('x', 101),
|
||||
Genre = (string?)null,
|
||||
Description = (string?)null,
|
||||
ScreenshotUrl = (string?)null,
|
||||
YoutubeUrl = (string?)null,
|
||||
GameUrl = (string?)null,
|
||||
MinPlayers = (int?)null,
|
||||
MaxPlayers = (int?)null
|
||||
});
|
||||
Assert.Equal(HttpStatusCode.BadRequest, longName.StatusCode);
|
||||
|
||||
var minOnly = await client.PostAsJsonAsync("/api/suggestions", new { Name = "MinOnly", Genre = (string?)null, Description = (string?)null, ScreenshotUrl = (string?)null, YoutubeUrl = (string?)null, GameUrl = (string?)null, MinPlayers = 2, MaxPlayers = (int?)null });
|
||||
var minOnly = await client.PostAsJsonAsync("/api/suggestions", new
|
||||
{
|
||||
Name = "MinOnly",
|
||||
Genre = (string?)null,
|
||||
Description = (string?)null,
|
||||
ScreenshotUrl = (string?)null,
|
||||
YoutubeUrl = (string?)null,
|
||||
GameUrl = (string?)null,
|
||||
MinPlayers = 2,
|
||||
MaxPlayers = (int?)null
|
||||
});
|
||||
Assert.Equal(HttpStatusCode.BadRequest, minOnly.StatusCode);
|
||||
|
||||
var maxTooHigh = await client.PostAsJsonAsync("/api/suggestions", new { Name = "MaxHigh", Genre = (string?)null, Description = (string?)null, ScreenshotUrl = (string?)null, YoutubeUrl = (string?)null, GameUrl = (string?)null, MinPlayers = 2, MaxPlayers = 40 });
|
||||
var maxTooHigh = await client.PostAsJsonAsync("/api/suggestions", new
|
||||
{
|
||||
Name = "MaxHigh",
|
||||
Genre = (string?)null,
|
||||
Description = (string?)null,
|
||||
ScreenshotUrl = (string?)null,
|
||||
YoutubeUrl = (string?)null,
|
||||
GameUrl = (string?)null,
|
||||
MinPlayers = 2,
|
||||
MaxPlayers = 40
|
||||
});
|
||||
Assert.Equal(HttpStatusCode.BadRequest, maxTooHigh.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Trims_and_truncates_optional_fields()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var client = factory.CreateClientWithCookies();
|
||||
await client.RegisterAsync("trim");
|
||||
|
||||
@@ -460,7 +549,7 @@ public class SuggestionTests
|
||||
[Fact]
|
||||
public async Task Mine_excludes_other_players()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var a = factory.CreateClientWithCookies();
|
||||
await a.RegisterAsync("alice");
|
||||
var b = factory.CreateClientWithCookies();
|
||||
@@ -470,14 +559,15 @@ public class SuggestionTests
|
||||
await b.CreateSuggestionAsync("BobGame");
|
||||
|
||||
var mine = await a.GetFromJsonAsync<List<JsonElement>>("/api/suggestions/mine");
|
||||
Assert.Single(mine!);
|
||||
Assert.NotNull(mine);
|
||||
Assert.Single(mine);
|
||||
Assert.Equal("AliceGame", mine[0].GetProperty("name").GetString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task All_returns_link_metadata_and_ordering()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var client = factory.CreateClientWithCookies();
|
||||
await client.RegisterAsync("owner");
|
||||
|
||||
@@ -507,7 +597,7 @@ public class SuggestionTests
|
||||
[Fact]
|
||||
public async Task Delete_respects_phase_and_clears_links_and_votes()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var owner = factory.CreateClientWithCookies();
|
||||
await owner.RegisterAsync("deleter");
|
||||
var other = factory.CreateClientWithCookies();
|
||||
@@ -524,7 +614,11 @@ public class SuggestionTests
|
||||
|
||||
await owner.PostAsJsonAsync("/api/me/phase/next", new { }); // Vote
|
||||
await other.PostAsJsonAsync("/api/me/phase/next", new { });
|
||||
await other.PostAsJsonAsync("/api/votes", new { SuggestionId = id, Score = 5 });
|
||||
await other.PostAsJsonAsync("/api/votes", new
|
||||
{
|
||||
SuggestionId = id,
|
||||
Score = 5
|
||||
});
|
||||
|
||||
var blocked = await owner.DeleteAsync($"/api/suggestions/{id}");
|
||||
Assert.Equal(HttpStatusCode.BadRequest, blocked.StatusCode);
|
||||
|
||||
Reference in New Issue
Block a user