From cba955c427e74818070d90bc30a2239dee0b6e23 Mon Sep 17 00:00:00 2001 From: Josh Patra Date: Fri, 30 Jan 2026 11:26:45 -0500 Subject: [PATCH] Fix JellyfinProxyServiceTests for RedisCacheService parameter --- allstarr.Tests/JellyfinProxyServiceTests.cs | 120 +++----------------- 1 file changed, 13 insertions(+), 107 deletions(-) diff --git a/allstarr.Tests/JellyfinProxyServiceTests.cs b/allstarr.Tests/JellyfinProxyServiceTests.cs index 4c47390..54ac236 100644 --- a/allstarr.Tests/JellyfinProxyServiceTests.cs +++ b/allstarr.Tests/JellyfinProxyServiceTests.cs @@ -6,6 +6,7 @@ using Moq; using Moq.Protected; using allstarr.Models.Settings; using allstarr.Services.Jellyfin; +using allstarr.Services.Common; using System.Net; using System.Text.Json; @@ -16,6 +17,7 @@ public class JellyfinProxyServiceTests private readonly JellyfinProxyService _service; private readonly Mock _mockHandler; private readonly Mock _mockHttpClientFactory; + private readonly RedisCacheService _cache; private readonly JellyfinSettings _settings; public JellyfinProxyServiceTests() @@ -26,6 +28,10 @@ public class JellyfinProxyServiceTests _mockHttpClientFactory = new Mock(); _mockHttpClientFactory.Setup(x => x.CreateClient(It.IsAny())).Returns(httpClient); + var redisSettings = new RedisSettings { Enabled = false }; + var mockCacheLogger = new Mock>(); + _cache = new RedisCacheService(Options.Create(redisSettings), mockCacheLogger.Object); + _settings = new JellyfinSettings { Url = "http://localhost:8096", @@ -45,7 +51,8 @@ public class JellyfinProxyServiceTests _mockHttpClientFactory.Object, Options.Create(_settings), httpContextAccessor, - mockLogger.Object); + mockLogger.Object, + _cache); } [Fact] @@ -252,55 +259,7 @@ public class JellyfinProxyServiceTests Assert.Contains("maxHeight=300", url); } - [Fact] - public async Task MarkFavoriteAsync_PostsToCorrectEndpoint() - { - // Arrange - HttpRequestMessage? captured = null; - _mockHandler.Protected() - .Setup>("SendAsync", - ItExpr.IsAny(), - ItExpr.IsAny()) - .Callback((req, ct) => captured = req) - .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK)); - // Act - var result = await _service.MarkFavoriteAsync("song-456"); - - // Assert - Assert.True(result); - Assert.NotNull(captured); - Assert.Equal(HttpMethod.Post, captured!.Method); - Assert.Contains($"/Users/{_settings.UserId}/FavoriteItems/song-456", captured.RequestUri!.ToString()); - } - - [Fact] - public async Task MarkFavoriteAsync_WithoutUserId_ReturnsFalse() - { - // Arrange - create service without UserId - var settingsWithoutUser = new JellyfinSettings - { - Url = "http://localhost:8096", - ApiKey = "test-key", - UserId = "" // no user - }; - - var httpContext = new DefaultHttpContext(); - var httpContextAccessor = new HttpContextAccessor { HttpContext = httpContext }; - var mockLogger = new Mock>(); - - var service = new JellyfinProxyService( - _mockHttpClientFactory.Object, - Options.Create(settingsWithoutUser), - httpContextAccessor, - mockLogger.Object); - - // Act - var result = await service.MarkFavoriteAsync("song-456"); - - // Assert - Assert.False(result); - } [Fact] public async Task TestConnectionAsync_ValidServer_ReturnsSuccess() @@ -337,64 +296,7 @@ public class JellyfinProxyServiceTests Assert.Null(version); } - [Fact] - public async Task GetMusicLibraryIdAsync_WhenConfigured_ReturnsConfiguredId() - { - // Arrange - settings already have LibraryId set - var settingsWithLibrary = new JellyfinSettings - { - Url = "http://localhost:8096", - ApiKey = "test-key", - LibraryId = "configured-library-id" - }; - var httpContext = new DefaultHttpContext(); - var httpContextAccessor = new HttpContextAccessor { HttpContext = httpContext }; - var mockLogger = new Mock>(); - - var service = new JellyfinProxyService( - _mockHttpClientFactory.Object, - Options.Create(settingsWithLibrary), - httpContextAccessor, - mockLogger.Object); - - // Act - var result = await service.GetMusicLibraryIdAsync(); - - // Assert - Assert.Equal("configured-library-id", result); - } - - [Fact] - public async Task GetMusicLibraryIdAsync_AutoDetects_MusicLibrary() - { - // Arrange - var librariesJson = "{\"Items\":[{\"Id\":\"video-lib\",\"CollectionType\":\"movies\"},{\"Id\":\"music-lib-123\",\"CollectionType\":\"music\"}]}"; - SetupMockResponse(HttpStatusCode.OK, librariesJson, "application/json"); - - var settingsNoLibrary = new JellyfinSettings - { - Url = "http://localhost:8096", - ApiKey = "test-key", - LibraryId = "" // not configured - }; - - var httpContext = new DefaultHttpContext(); - var httpContextAccessor = new HttpContextAccessor { HttpContext = httpContext }; - var mockLogger = new Mock>(); - - var service = new JellyfinProxyService( - _mockHttpClientFactory.Object, - Options.Create(settingsNoLibrary), - httpContextAccessor, - mockLogger.Object); - - // Act - var result = await service.GetMusicLibraryIdAsync(); - - // Assert - Assert.Equal("music-lib-123", result); - } [Fact] public async Task StreamAudioAsync_NullContext_ReturnsError() @@ -402,12 +304,16 @@ public class JellyfinProxyServiceTests // Arrange var httpContextAccessor = new HttpContextAccessor { HttpContext = null }; var mockLogger = new Mock>(); + var redisSettings = new RedisSettings { Enabled = false }; + var mockCacheLogger = new Mock>(); + var cache = new RedisCacheService(Options.Create(redisSettings), mockCacheLogger.Object); var service = new JellyfinProxyService( _mockHttpClientFactory.Object, Options.Create(_settings), httpContextAccessor, - mockLogger.Object); + mockLogger.Object, + cache); // Act var result = await service.StreamAudioAsync("song-123", CancellationToken.None);