Add backend test harness with mock SQLite
This commit is contained in:
71
GameList.Tests/SuggestionTests.cs
Normal file
71
GameList.Tests/SuggestionTests.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using System.Net;
|
||||
using System.Net;
|
||||
using System.Net.Http.Json;
|
||||
using GameList.Tests.Support;
|
||||
|
||||
namespace GameList.Tests;
|
||||
|
||||
public class SuggestionTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task Player_cannot_exceed_five_suggestions()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
var client = factory.CreateClientWithCookies();
|
||||
await client.RegisterAsync("suggestor");
|
||||
|
||||
for (var i = 0; i < 5; i++)
|
||||
{
|
||||
var resp = await client.PostAsJsonAsync("/api/suggestions", new
|
||||
{
|
||||
Name = $"Game {i}",
|
||||
Genre = (string?)null,
|
||||
Description = (string?)null,
|
||||
ScreenshotUrl = (string?)null,
|
||||
YoutubeUrl = (string?)null,
|
||||
GameUrl = (string?)null,
|
||||
MinPlayers = (int?)null,
|
||||
MaxPlayers = (int?)null
|
||||
});
|
||||
resp.EnsureSuccessStatusCode();
|
||||
}
|
||||
|
||||
var sixth = await client.PostAsJsonAsync("/api/suggestions", new
|
||||
{
|
||||
Name = "Overflow",
|
||||
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, sixth.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Unreachable_screenshot_url_is_rejected()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
factory.HttpHandler.SetResponder(_ => new HttpResponseMessage(HttpStatusCode.BadRequest));
|
||||
|
||||
var client = factory.CreateClientWithCookies();
|
||||
await client.RegisterAsync("imgtester");
|
||||
|
||||
var response = await client.PostAsJsonAsync("/api/suggestions", new
|
||||
{
|
||||
Name = "Needs image",
|
||||
Genre = (string?)null,
|
||||
Description = (string?)null,
|
||||
ScreenshotUrl = "http://example.com/image.png",
|
||||
YoutubeUrl = (string?)null,
|
||||
GameUrl = (string?)null,
|
||||
MinPlayers = (int?)null,
|
||||
MaxPlayers = (int?)null
|
||||
});
|
||||
|
||||
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user