74 lines
2.5 KiB
C#
74 lines
2.5 KiB
C#
using System.Net;
|
|
using ErsatzTV.Core;
|
|
using ErsatzTV.Core.Domain;
|
|
using ErsatzTV.Core.Interfaces.Jellyfin;
|
|
using ErsatzTV.Core.Interfaces.Metadata;
|
|
using ErsatzTV.Infrastructure.Jellyfin;
|
|
using LanguageExt;
|
|
using Microsoft.Extensions.Caching.Memory;
|
|
using Microsoft.Extensions.Logging;
|
|
using NSubstitute;
|
|
using NUnit.Framework;
|
|
using Shouldly;
|
|
|
|
namespace ErsatzTV.Infrastructure.Tests.Jellyfin;
|
|
|
|
public class JellyfinApiClientTests
|
|
{
|
|
[TestFixture]
|
|
public class GetLibraries
|
|
{
|
|
[Test]
|
|
public async Task Should_Project_MusicVideo_Libraries()
|
|
{
|
|
const string response = """
|
|
[
|
|
{
|
|
"Name": "Concerts",
|
|
"CollectionType": "musicvideos",
|
|
"ItemId": "library-1",
|
|
"LibraryOptions": {
|
|
"PathInfos": []
|
|
}
|
|
}
|
|
]
|
|
""";
|
|
|
|
var client = new JellyfinApiClient(
|
|
new MemoryCache(new MemoryCacheOptions()),
|
|
Substitute.For<IJellyfinPathReplacementService>(),
|
|
Substitute.For<IFallbackMetadataProvider>(),
|
|
new SingleResponseHttpClientFactory(response),
|
|
Substitute.For<ILogger<JellyfinApiClient>>());
|
|
|
|
Either<BaseError, List<JellyfinLibrary>> result =
|
|
await client.GetLibraries("http://jellyfin.example", "MediaBrowser Token=abc");
|
|
|
|
result.IsRight.ShouldBeTrue();
|
|
List<JellyfinLibrary> libraries = result.RightToSeq().Single();
|
|
libraries.Count.ShouldBe(1);
|
|
libraries[0].Name.ShouldBe("Concerts");
|
|
libraries[0].ItemId.ShouldBe("library-1");
|
|
libraries[0].MediaKind.ShouldBe(LibraryMediaKind.MusicVideos);
|
|
libraries[0].ShouldSyncItems.ShouldBeFalse();
|
|
libraries[0].Paths.Single().Path.ShouldBe("jellyfin://library-1");
|
|
}
|
|
}
|
|
|
|
private sealed class SingleResponseHttpClientFactory(string response) : IHttpClientFactory
|
|
{
|
|
public HttpClient CreateClient(string name) => new(new SingleResponseHttpMessageHandler(response));
|
|
}
|
|
|
|
private sealed class SingleResponseHttpMessageHandler(string response) : HttpMessageHandler
|
|
{
|
|
protected override Task<HttpResponseMessage> SendAsync(
|
|
HttpRequestMessage request,
|
|
CancellationToken cancellationToken) =>
|
|
Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)
|
|
{
|
|
Content = new StringContent(response)
|
|
});
|
|
}
|
|
}
|