From 608a91162ae5550eb98f313a2c1fe6845e4b6c98 Mon Sep 17 00:00:00 2001 From: Joe Rogers <1337joe@gmail.com> Date: Tue, 16 Nov 2021 01:19:00 +0100 Subject: [PATCH] Add test for #6830 --- .../Manager/ItemImageProviderTests.cs | 70 ++++++++++++++++--- 1 file changed, 61 insertions(+), 9 deletions(-) diff --git a/tests/Jellyfin.Providers.Tests/Manager/ItemImageProviderTests.cs b/tests/Jellyfin.Providers.Tests/Manager/ItemImageProviderTests.cs index 2ba5c47d7..9aa9e2c32 100644 --- a/tests/Jellyfin.Providers.Tests/Manager/ItemImageProviderTests.cs +++ b/tests/Jellyfin.Providers.Tests/Manager/ItemImageProviderTests.cs @@ -336,8 +336,7 @@ namespace Jellyfin.Providers.Tests.Manager remoteInfo[i] = new RemoteImageInfo { Type = imageType, - Url = "image url " + i, - Width = 1 // min width is set to 0, this will always pass + Url = "image url " + i }; } @@ -403,11 +402,10 @@ namespace Jellyfin.Providers.Tests.Manager var remoteInfo = new RemoteImageInfo[targetImageCount]; for (int i = 0; i < targetImageCount; i++) { - remoteInfo[i] = new RemoteImageInfo() + remoteInfo[i] = new RemoteImageInfo { Type = imageType, - Url = "image url " + i, - Width = 1 // min width is set to 0, this will always pass + Url = "image url " + i }; } @@ -449,11 +447,10 @@ namespace Jellyfin.Providers.Tests.Manager var remoteInfo = new RemoteImageInfo[remoteInfoCount]; for (int i = 0; i < remoteInfoCount; i++) { - remoteInfo[i] = new RemoteImageInfo() + remoteInfo[i] = new RemoteImageInfo { Type = imageType, - Url = "image url " + i, - Width = 1 // min width is set to 0, this will always pass + Url = "image url " + i }; } @@ -500,6 +497,62 @@ namespace Jellyfin.Providers.Tests.Manager Assert.Equal(imageCount, item.GetImages(imageType).Count()); } + [Theory] + [InlineData(9, false)] + [InlineData(10, true)] + [InlineData(null, true)] + public async void RefreshImages_ProviderRemote_FiltersByWidth(int? remoteImageWidth, bool expectedToUpdate) + { + var imageType = ImageType.Primary; + + var item = new Video(); + + var libraryOptions = new LibraryOptions + { + TypeOptions = new[] + { + new TypeOptions + { + Type = item.GetType().Name, + ImageOptions = new[] + { + new ImageOption + { + Type = imageType, + MinWidth = 10 + } + } + } + } + }; + + var remoteProvider = new Mock(MockBehavior.Strict); + remoteProvider.Setup(rp => rp.Name).Returns("MockRemoteProvider"); + remoteProvider.Setup(rp => rp.GetSupportedImages(item)) + .Returns(new[] { imageType }); + + var refreshOptions = new ImageRefreshOptions(Mock.Of()); + + // set width on image from remote + var remoteInfo = new[] + { + new RemoteImageInfo() + { + Type = imageType, + Url = "image url", + Width = remoteImageWidth + } + }; + + var providerManager = new Mock(MockBehavior.Strict); + providerManager.Setup(pm => pm.GetAvailableRemoteImages(It.IsAny(), It.IsAny(), It.IsAny())) + .ReturnsAsync(remoteInfo); + var itemImageProvider = GetItemImageProvider(providerManager.Object, null); + var result = await itemImageProvider.RefreshImages(item, libraryOptions, new List { remoteProvider.Object }, refreshOptions, CancellationToken.None); + + Assert.Equal(expectedToUpdate, result.UpdateType.HasFlag(ItemUpdateType.ImageUpdate)); + } + private static ItemImageProvider GetItemImageProvider(IProviderManager? providerManager, Mock? mockFileSystem) { // strict to ensure this isn't accidentally used where a prepared mock is intended @@ -586,7 +639,6 @@ namespace Jellyfin.Providers.Tests.Manager { Type = type, Limit = count, - MinWidth = 0 } } }