41 lines
1.8 KiB
C#
41 lines
1.8 KiB
C#
using System.Net;
|
|
using System.Text;
|
|
using Ludarium.Infrastructure;
|
|
|
|
namespace Ludarium.IntegrationTests;
|
|
|
|
public sealed class RawgGameDiscoveryServiceTests
|
|
{
|
|
[Fact]
|
|
public async Task MissingKeyReportsAnHonestDisabledCapabilityWithoutNetworkAccess()
|
|
{
|
|
using var client = new HttpClient(new StubHandler(_ => throw new InvalidOperationException("Network should not be used.")));
|
|
var response = await new RawgGameDiscoveryService(client, null).SearchAsync("Metroid", CancellationToken.None);
|
|
Assert.False(response.Configured);
|
|
Assert.Empty(response.Results);
|
|
Assert.Contains("RAWG_API_KEY", response.Message);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ConfiguredSearchNormalizesKnownPlatformsAndRetainsProviderIdentity()
|
|
{
|
|
const string json = """{"results":[{"id":42,"name":"Synthetic Quest","released":"2027-01-02","background_image":"https://images.example/42.jpg","slug":"synthetic-quest","platforms":[{"platform":{"slug":"playstation5"}}]}]}""";
|
|
using var client = new HttpClient(new StubHandler(_ => new HttpResponseMessage(HttpStatusCode.OK)
|
|
{
|
|
Content = new StringContent(json, Encoding.UTF8, "application/json")
|
|
}));
|
|
var response = await new RawgGameDiscoveryService(client, "synthetic-key").SearchAsync("Synthetic", CancellationToken.None);
|
|
var item = Assert.Single(response.Results);
|
|
Assert.True(response.Configured);
|
|
Assert.Equal("RAWG", item.Provider);
|
|
Assert.Equal("42", item.ExternalId);
|
|
Assert.Equal("ps5", item.Platform);
|
|
}
|
|
|
|
private sealed class StubHandler(Func<HttpRequestMessage, HttpResponseMessage> response) : HttpMessageHandler
|
|
{
|
|
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) =>
|
|
Task.FromResult(response(request));
|
|
}
|
|
}
|