diff options
Diffstat (limited to 'tests/Jellyfin.Server.Implementations.Tests')
4 files changed, 135 insertions, 11 deletions
diff --git a/tests/Jellyfin.Server.Implementations.Tests/IO/ManagedFileSystemTests.cs b/tests/Jellyfin.Server.Implementations.Tests/IO/ManagedFileSystemTests.cs index d991f5574..95a5b8179 100644 --- a/tests/Jellyfin.Server.Implementations.Tests/IO/ManagedFileSystemTests.cs +++ b/tests/Jellyfin.Server.Implementations.Tests/IO/ManagedFileSystemTests.cs @@ -20,26 +20,37 @@ namespace Jellyfin.Server.Implementations.Tests.IO _sut = _fixture.Create<ManagedFileSystem>(); } - [Theory] + [SkippableTheory] [InlineData("/Volumes/Library/Sample/Music/Playlists/", "../Beethoven/Misc/Moonlight Sonata.mp3", "/Volumes/Library/Sample/Music/Beethoven/Misc/Moonlight Sonata.mp3")] [InlineData("/Volumes/Library/Sample/Music/Playlists/", "../../Beethoven/Misc/Moonlight Sonata.mp3", "/Volumes/Library/Sample/Beethoven/Misc/Moonlight Sonata.mp3")] [InlineData("/Volumes/Library/Sample/Music/Playlists/", "Beethoven/Misc/Moonlight Sonata.mp3", "/Volumes/Library/Sample/Music/Playlists/Beethoven/Misc/Moonlight Sonata.mp3")] - public void MakeAbsolutePathCorrectlyHandlesRelativeFilePaths( + [InlineData("/Volumes/Library/Sample/Music/Playlists/", "/mnt/Beethoven/Misc/Moonlight Sonata.mp3", "/mnt/Beethoven/Misc/Moonlight Sonata.mp3")] + public void MakeAbsolutePathCorrectlyHandlesRelativeFilePathsOnUnixLike( string folderPath, string filePath, string expectedAbsolutePath) { + Skip.If(OperatingSystem.IsWindows()); + + var generatedPath = _sut.MakeAbsolutePath(folderPath, filePath); + Assert.Equal(expectedAbsolutePath, generatedPath); + } + + [SkippableTheory] + [InlineData(@"C:\\Volumes\Library\Sample\Music\Playlists\", @"..\Beethoven\Misc\Moonlight Sonata.mp3", @"C:\Volumes\Library\Sample\Music\Beethoven\Misc\Moonlight Sonata.mp3")] + [InlineData(@"C:\\Volumes\Library\Sample\Music\Playlists\", @"..\..\Beethoven\Misc\Moonlight Sonata.mp3", @"C:\Volumes\Library\Sample\Beethoven\Misc\Moonlight Sonata.mp3")] + [InlineData(@"C:\\Volumes\Library\Sample\Music\Playlists\", @"Beethoven\Misc\Moonlight Sonata.mp3", @"C:\Volumes\Library\Sample\Music\Playlists\Beethoven\Misc\Moonlight Sonata.mp3")] + [InlineData(@"C:\\Volumes\Library\Sample\Music\Playlists\", @"D:\\Beethoven\Misc\Moonlight Sonata.mp3", @"D:\\Beethoven\Misc\Moonlight Sonata.mp3")] + public void MakeAbsolutePathCorrectlyHandlesRelativeFilePathsOnWindows( + string folderPath, + string filePath, + string expectedAbsolutePath) + { + Skip.If(!OperatingSystem.IsWindows()); + var generatedPath = _sut.MakeAbsolutePath(folderPath, filePath); - if (OperatingSystem.IsWindows()) - { - var expectedWindowsPath = expectedAbsolutePath.Replace('/', '\\'); - Assert.Equal(expectedWindowsPath, generatedPath.Split(':')[1]); - } - else - { - Assert.Equal(expectedAbsolutePath, generatedPath); - } + Assert.Equal(expectedAbsolutePath, generatedPath); } [Theory] diff --git a/tests/Jellyfin.Server.Implementations.Tests/Library/PathExtensionsTests.cs b/tests/Jellyfin.Server.Implementations.Tests/Library/PathExtensionsTests.cs index d1be07aa2..940e3c2b1 100644 --- a/tests/Jellyfin.Server.Implementations.Tests/Library/PathExtensionsTests.cs +++ b/tests/Jellyfin.Server.Implementations.Tests/Library/PathExtensionsTests.cs @@ -18,6 +18,12 @@ namespace Jellyfin.Server.Implementations.Tests.Library [InlineData("Superman: Red Son [tmdbid=618355][imdbid=tt10985510]", "imdbid", "tt10985510")] [InlineData("Superman: Red Son [tmdbid-618355][imdbid-tt10985510]", "imdbid", "tt10985510")] [InlineData("Superman: Red Son [tmdbid-618355][imdbid-tt10985510]", "tmdbid", "618355")] + [InlineData("Superman: Red Son [providera-id=1]", "providera-id", "1")] + [InlineData("Superman: Red Son [providerb-id=2]", "providerb-id", "2")] + [InlineData("Superman: Red Son [providera id=4]", "providera id", "4")] + [InlineData("Superman: Red Son [providerb id=5]", "providerb id", "5")] + [InlineData("Superman: Red Son [tmdbid=3]", "tmdbid", "3")] + [InlineData("Superman: Red Son [tvdbid-6]", "tvdbid", "6")] [InlineData("[tmdbid=618355]", "tmdbid", "618355")] [InlineData("[tmdbid-618355]", "tmdbid", "618355")] [InlineData("tmdbid=111111][tmdbid=618355]", "tmdbid", "618355")] diff --git a/tests/Jellyfin.Server.Implementations.Tests/Localization/LocalizationManagerTests.cs b/tests/Jellyfin.Server.Implementations.Tests/Localization/LocalizationManagerTests.cs index 09e4709da..0a4a836cb 100644 --- a/tests/Jellyfin.Server.Implementations.Tests/Localization/LocalizationManagerTests.cs +++ b/tests/Jellyfin.Server.Implementations.Tests/Localization/LocalizationManagerTests.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Runtime.InteropServices; using System.Threading.Tasks; using Emby.Server.Implementations.Localization; using MediaBrowser.Controller.Configuration; @@ -127,6 +128,22 @@ namespace Jellyfin.Server.Implementations.Tests.Localization Assert.Equal(expectedLevel, level!); } + [Theory] + [InlineData("0", 0)] + [InlineData("1", 1)] + [InlineData("6", 6)] + [InlineData("12", 12)] + [InlineData("42", 42)] + [InlineData("9999", 9999)] + public async Task GetRatingLevel_GivenValidAge_Success(string value, int expectedLevel) + { + var localizationManager = Setup(new ServerConfiguration { MetadataCountryCode = "nl" }); + await localizationManager.LoadAll(); + var level = localizationManager.GetRatingLevel(value); + Assert.NotNull(level); + Assert.Equal(expectedLevel, level); + } + [Fact] public async Task GetRatingLevel_GivenUnratedString_Success() { @@ -142,6 +159,20 @@ namespace Jellyfin.Server.Implementations.Tests.Localization } [Theory] + [InlineData("-NO RATING SHOWN-")] + [InlineData(":NO RATING SHOWN:")] + public async Task GetRatingLevel_Split_Success(string value) + { + var localizationManager = Setup(new ServerConfiguration() + { + UICulture = "en-US" + }); + await localizationManager.LoadAll(); + + Assert.Null(localizationManager.GetRatingLevel(value)); + } + + [Theory] [InlineData("Default", "Default")] [InlineData("HeaderLiveTV", "Live TV")] public void GetLocalizedString_Valid_Success(string key, string expected) diff --git a/tests/Jellyfin.Server.Implementations.Tests/Sorting/PremiereDateComparerTests.cs b/tests/Jellyfin.Server.Implementations.Tests/Sorting/PremiereDateComparerTests.cs new file mode 100644 index 000000000..9dfacb2bf --- /dev/null +++ b/tests/Jellyfin.Server.Implementations.Tests/Sorting/PremiereDateComparerTests.cs @@ -0,0 +1,76 @@ +using System; +using Emby.Server.Implementations.Sorting; +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities.Movies; +using Xunit; + +namespace Jellyfin.Server.Implementations.Tests.Sorting +{ + public class PremiereDateComparerTests + { + private readonly PremiereDateComparer _cmp = new PremiereDateComparer(); + + [Theory] + [ClassData(typeof(PremiereDateTestData))] + public void PremiereDateCompareTest(BaseItem x, BaseItem y, int expected) + { + Assert.Equal(expected, _cmp.Compare(x, y)); + Assert.Equal(-expected, _cmp.Compare(y, x)); + } + + private sealed class PremiereDateTestData : TheoryData<BaseItem, BaseItem, int> + { + public PremiereDateTestData() + { + // Happy case - Both have premier date + // Expected: x listed first + Add( + new Movie { PremiereDate = new DateTime(2018, 1, 1) }, + new Movie { PremiereDate = new DateTime(2018, 1, 3) }, + -1); + + // Both have premiere date, but y has invalid date + // Expected: y listed first + Add( + new Movie { PremiereDate = new DateTime(2019, 1, 1) }, + new Movie { PremiereDate = new DateTime(03, 1, 1) }, + 1); + + // Only x has premiere date, with earlier year than y + // Expected: x listed first + Add( + new Movie { PremiereDate = new DateTime(2020, 1, 1) }, + new Movie { ProductionYear = 2021 }, + -1); + + // Only x has premiere date, with same year as y + // Expected: y listed first + Add( + new Movie { PremiereDate = new DateTime(2022, 1, 2) }, + new Movie { ProductionYear = 2022 }, + 1); + + // Only x has a premiere date, with later year than y + // Expected: y listed first + Add( + new Movie { PremiereDate = new DateTime(2024, 3, 1) }, + new Movie { ProductionYear = 2023 }, + 1); + + // Only x has a premiere date, y has an invalid year + // Expected: y listed first + Add( + new Movie { PremiereDate = new DateTime(2025, 1, 1) }, + new Movie { ProductionYear = 0 }, + 1); + + // Only x has a premiere date, y has neither date nor year + // Expected: y listed first + Add( + new Movie { PremiereDate = new DateTime(2026, 1, 1) }, + new Movie(), + 1); + } + } + } +} |
