C# formatting
This commit is contained in:
@@ -12,7 +12,7 @@ public class AdminTests
|
||||
[Fact]
|
||||
public async Task Admin_vote_status_marks_ready_when_all_finalized()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var admin = factory.CreateClientWithCookies();
|
||||
await admin.RegisterAsync("admin", admin: true);
|
||||
await admin.PostAsJsonAsync("/api/me/phase/next", new { }); // move to Vote
|
||||
@@ -25,9 +25,17 @@ public class AdminTests
|
||||
|
||||
var s1 = await p1.CreateSuggestionAsync("A");
|
||||
await p1.PostAsJsonAsync("/api/me/phase/next", new { });
|
||||
await p1.PostAsJsonAsync("/api/votes", new { SuggestionId = s1, Score = 5 });
|
||||
await p1.PostAsJsonAsync("/api/votes", new
|
||||
{
|
||||
SuggestionId = s1,
|
||||
Score = 5
|
||||
});
|
||||
await p1.PostAsJsonAsync("/api/votes/finalize", new { Final = true });
|
||||
await p2.PostAsJsonAsync("/api/votes", new { SuggestionId = s1, Score = 7 });
|
||||
await p2.PostAsJsonAsync("/api/votes", new
|
||||
{
|
||||
SuggestionId = s1,
|
||||
Score = 7
|
||||
});
|
||||
await p2.PostAsJsonAsync("/api/votes/finalize", new { Final = true });
|
||||
await admin.PostAsJsonAsync("/api/votes/finalize", new { Final = true });
|
||||
|
||||
@@ -40,7 +48,7 @@ public class AdminTests
|
||||
[Fact]
|
||||
public async Task Grant_joker_only_in_vote_phase()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var admin = factory.CreateClientWithCookies();
|
||||
await admin.RegisterAsync("admin", admin: true);
|
||||
|
||||
@@ -54,7 +62,7 @@ public class AdminTests
|
||||
[Fact]
|
||||
public async Task Delete_player_cascades_suggestions_and_votes()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var admin = factory.CreateClientWithCookies();
|
||||
await admin.RegisterAsync("admin", admin: true);
|
||||
|
||||
@@ -63,23 +71,37 @@ public class AdminTests
|
||||
var suggestionId = await player.CreateSuggestionAsync("DeleteGame");
|
||||
|
||||
await player.PostAsJsonAsync("/api/me/phase/next", new { });
|
||||
await player.PostAsJsonAsync("/api/votes", new { SuggestionId = suggestionId, Score = 8 });
|
||||
await player.PostAsJsonAsync("/api/votes", new
|
||||
{
|
||||
SuggestionId = suggestionId,
|
||||
Score = 8
|
||||
});
|
||||
|
||||
var resp = await admin.DeleteAsync($"/api/admin/players/{await player.GetProfileIdAsync()}");
|
||||
resp.EnsureSuccessStatusCode();
|
||||
|
||||
await factory.WithDbContextAsync(async db =>
|
||||
await factory.WithDbContextAsync(db =>
|
||||
{
|
||||
Assert.Single(db.Players); // admin remains
|
||||
Assert.Empty(db.Suggestions);
|
||||
Assert.Empty(db.Votes);
|
||||
try
|
||||
{
|
||||
Assert.Single(db.Players); // admin remains
|
||||
|
||||
Assert.Empty(db.Suggestions);
|
||||
|
||||
Assert.Empty(db.Votes);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
return Task.FromException(exception);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Link_suggestions_errors_on_same_id_and_already_linked()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var admin = factory.CreateClientWithCookies();
|
||||
await admin.RegisterAsync("admin", admin: true);
|
||||
var player = factory.CreateClientWithCookies();
|
||||
@@ -91,20 +113,32 @@ public class AdminTests
|
||||
await player.PostAsJsonAsync("/api/me/phase/next", new { });
|
||||
await admin.PostAsJsonAsync("/api/me/phase/next", new { });
|
||||
|
||||
var same = await admin.PostAsJsonAsync("/api/admin/link-suggestions", new { SourceSuggestionId = a, TargetSuggestionId = a });
|
||||
var same = await admin.PostAsJsonAsync("/api/admin/link-suggestions", new
|
||||
{
|
||||
SourceSuggestionId = a,
|
||||
TargetSuggestionId = a
|
||||
});
|
||||
Assert.Equal(HttpStatusCode.BadRequest, same.StatusCode);
|
||||
|
||||
var first = await admin.PostAsJsonAsync("/api/admin/link-suggestions", new { SourceSuggestionId = a, TargetSuggestionId = b });
|
||||
var first = await admin.PostAsJsonAsync("/api/admin/link-suggestions", new
|
||||
{
|
||||
SourceSuggestionId = a,
|
||||
TargetSuggestionId = b
|
||||
});
|
||||
first.EnsureSuccessStatusCode();
|
||||
|
||||
var already = await admin.PostAsJsonAsync("/api/admin/link-suggestions", new { SourceSuggestionId = a, TargetSuggestionId = b });
|
||||
var already = await admin.PostAsJsonAsync("/api/admin/link-suggestions", new
|
||||
{
|
||||
SourceSuggestionId = a,
|
||||
TargetSuggestionId = b
|
||||
});
|
||||
Assert.Equal(HttpStatusCode.BadRequest, already.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Unlink_suggestions_clears_group_votes()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var admin = factory.CreateClientWithCookies();
|
||||
await admin.RegisterAsync("admin", admin: true);
|
||||
var player = factory.CreateClientWithCookies();
|
||||
@@ -114,24 +148,41 @@ public class AdminTests
|
||||
var b = await player.CreateSuggestionAsync("Game B");
|
||||
await player.PostAsJsonAsync("/api/me/phase/next", new { });
|
||||
await admin.PostAsJsonAsync("/api/me/phase/next", new { });
|
||||
await admin.PostAsJsonAsync("/api/admin/link-suggestions", new { SourceSuggestionId = a, TargetSuggestionId = b });
|
||||
await admin.PostAsJsonAsync("/api/admin/link-suggestions", new
|
||||
{
|
||||
SourceSuggestionId = a,
|
||||
TargetSuggestionId = b
|
||||
});
|
||||
|
||||
await player.PostAsJsonAsync("/api/votes", new { SuggestionId = a, Score = 6 });
|
||||
await player.PostAsJsonAsync("/api/votes", new
|
||||
{
|
||||
SuggestionId = a,
|
||||
Score = 6
|
||||
});
|
||||
|
||||
var resp = await admin.PostAsJsonAsync("/api/admin/unlink-suggestions", new { suggestionId = a });
|
||||
resp.EnsureSuccessStatusCode();
|
||||
|
||||
await factory.WithDbContextAsync(async db =>
|
||||
await factory.WithDbContextAsync(db =>
|
||||
{
|
||||
Assert.Empty(db.Votes);
|
||||
Assert.All(db.Suggestions, s => Assert.Null(s.ParentSuggestionId));
|
||||
try
|
||||
{
|
||||
Assert.Empty(db.Votes);
|
||||
|
||||
Assert.All(db.Suggestions, s => Assert.Null(s.ParentSuggestionId));
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
return Task.FromException(exception);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Reset_and_factory_reset_clear_state()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var admin = factory.CreateClientWithCookies();
|
||||
await admin.RegisterAsync("admin", admin: true);
|
||||
var player = factory.CreateClientWithCookies();
|
||||
@@ -141,27 +192,46 @@ public class AdminTests
|
||||
var reset = await admin.PostAsJsonAsync("/api/admin/reset", new { });
|
||||
reset.EnsureSuccessStatusCode();
|
||||
|
||||
await factory.WithDbContextAsync(async db =>
|
||||
await factory.WithDbContextAsync(db =>
|
||||
{
|
||||
Assert.Empty(db.Suggestions);
|
||||
Assert.Empty(db.Votes);
|
||||
Assert.All(db.Players, p => Assert.Equal(Phase.Suggest, p.CurrentPhase));
|
||||
try
|
||||
{
|
||||
Assert.Empty(db.Suggestions);
|
||||
|
||||
Assert.Empty(db.Votes);
|
||||
|
||||
Assert.All(db.Players, p => Assert.Equal(Phase.Suggest, p.CurrentPhase));
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
return Task.FromException(exception);
|
||||
}
|
||||
});
|
||||
|
||||
var factoryReset = await admin.PostAsJsonAsync("/api/admin/factory-reset", new { });
|
||||
factoryReset.EnsureSuccessStatusCode();
|
||||
|
||||
await factory.WithDbContextAsync(async db =>
|
||||
await factory.WithDbContextAsync(db =>
|
||||
{
|
||||
Assert.Empty(db.Players);
|
||||
Assert.Single(db.AppState);
|
||||
try
|
||||
{
|
||||
Assert.Empty(db.Players);
|
||||
|
||||
Assert.Single(db.AppState);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
return Task.FromException(exception);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Admin_results_closing_moves_back_to_vote_and_clears_finalize()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var admin = factory.CreateClientWithCookies();
|
||||
await admin.RegisterAsync("admin", admin: true);
|
||||
var player = factory.CreateClientWithCookies();
|
||||
@@ -196,7 +266,7 @@ public class AdminTests
|
||||
[Fact]
|
||||
public async Task Vote_status_lists_waiting_players()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var admin = factory.CreateClientWithCookies();
|
||||
await admin.RegisterAsync("admin", admin: true);
|
||||
await admin.PostAsJsonAsync("/api/me/phase/next", new { });
|
||||
@@ -208,7 +278,11 @@ public class AdminTests
|
||||
var s = await p1.CreateSuggestionAsync("Game");
|
||||
await p1.PostAsJsonAsync("/api/me/phase/next", new { });
|
||||
await p2.PostAsJsonAsync("/api/me/phase/next", new { });
|
||||
await p1.PostAsJsonAsync("/api/votes", new { SuggestionId = s, Score = 5 });
|
||||
await p1.PostAsJsonAsync("/api/votes", new
|
||||
{
|
||||
SuggestionId = s,
|
||||
Score = 5
|
||||
});
|
||||
await p1.PostAsJsonAsync("/api/votes/finalize", new { Final = true });
|
||||
|
||||
var status = await admin.GetFromJsonAsync<JsonElement>("/api/admin/vote-status");
|
||||
@@ -220,7 +294,7 @@ public class AdminTests
|
||||
[Fact]
|
||||
public async Task Grant_joker_in_vote_sets_flag_and_unfinalizes()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var admin = factory.CreateClientWithCookies();
|
||||
await admin.RegisterAsync("admin", admin: true);
|
||||
|
||||
@@ -243,7 +317,7 @@ public class AdminTests
|
||||
[Fact]
|
||||
public async Task Link_requires_vote_phase_and_reparents_votes_reset()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var admin = factory.CreateClientWithCookies();
|
||||
await admin.RegisterAsync("admin", admin: true);
|
||||
var player = factory.CreateClientWithCookies();
|
||||
@@ -252,16 +326,28 @@ public class AdminTests
|
||||
var a = await player.CreateSuggestionAsync("A");
|
||||
var b = await player.CreateSuggestionAsync("B");
|
||||
|
||||
var beforeVotePhase = await admin.PostAsJsonAsync("/api/admin/link-suggestions", new { SourceSuggestionId = a, TargetSuggestionId = b });
|
||||
var beforeVotePhase = await admin.PostAsJsonAsync("/api/admin/link-suggestions", new
|
||||
{
|
||||
SourceSuggestionId = a,
|
||||
TargetSuggestionId = b
|
||||
});
|
||||
Assert.Equal(HttpStatusCode.BadRequest, beforeVotePhase.StatusCode);
|
||||
|
||||
await admin.PostAsJsonAsync("/api/me/phase/next", new { });
|
||||
await player.PostAsJsonAsync("/api/me/phase/next", new { });
|
||||
|
||||
await player.PostAsJsonAsync("/api/votes", new { SuggestionId = a, Score = 3 });
|
||||
await player.PostAsJsonAsync("/api/votes", new
|
||||
{
|
||||
SuggestionId = a,
|
||||
Score = 3
|
||||
});
|
||||
await player.PostAsJsonAsync("/api/votes/finalize", new { Final = true });
|
||||
|
||||
var link = await admin.PostAsJsonAsync("/api/admin/link-suggestions", new { SourceSuggestionId = a, TargetSuggestionId = b });
|
||||
var link = await admin.PostAsJsonAsync("/api/admin/link-suggestions", new
|
||||
{
|
||||
SourceSuggestionId = a,
|
||||
TargetSuggestionId = b
|
||||
});
|
||||
link.EnsureSuccessStatusCode();
|
||||
|
||||
await factory.WithDbContextAsync(async db =>
|
||||
@@ -276,7 +362,7 @@ public class AdminTests
|
||||
[Fact]
|
||||
public async Task Unlink_not_found_returns_empty_payload()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var admin = factory.CreateClientWithCookies();
|
||||
await admin.RegisterAsync("admin", admin: true);
|
||||
await admin.PostAsJsonAsync("/api/me/phase/next", new { });
|
||||
@@ -290,7 +376,7 @@ public class AdminTests
|
||||
[Fact]
|
||||
public async Task Reset_clears_flags_and_factory_reset_seeds_defaults()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
await using var factory = new TestWebApplicationFactory();
|
||||
var admin = factory.CreateClientWithCookies();
|
||||
await admin.RegisterAsync("admin", admin: true);
|
||||
var p = factory.CreateClientWithCookies();
|
||||
|
||||
Reference in New Issue
Block a user