From b7adc9e259faec5c91eaa148540b3a6149b8be3a Mon Sep 17 00:00:00 2001 From: Devon Chessher Date: Sun, 1 Oct 2023 21:55:08 -0400 Subject: [PATCH 1/2] Added test cases for checking additional audiobook list resolver parameters. --- .../Properties/launchSettings.json | 17 +-- .../AudioBook/AudioBookListResolverTests.cs | 108 ++++++++++++++++++ 2 files changed, 117 insertions(+), 8 deletions(-) diff --git a/Jellyfin.Server/Properties/launchSettings.json b/Jellyfin.Server/Properties/launchSettings.json index 20d432afc4..00b767766d 100644 --- a/Jellyfin.Server/Properties/launchSettings.json +++ b/Jellyfin.Server/Properties/launchSettings.json @@ -3,27 +3,28 @@ "Jellyfin.Server": { "commandName": "Project", "launchBrowser": true, - "applicationUrl": "http://localhost:8096", "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } + "ASPNETCORE_ENVIRONMENT": "Development", + "JELLYFIN_WEB_DIR": "C:\\Users\\devon\\source\\repos\\jellyfin-web\\dist" + }, + "applicationUrl": "http://localhost:8096" }, "Jellyfin.Server (nowebclient)": { "commandName": "Project", + "commandLineArgs": "--nowebclient", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" - }, - "commandLineArgs": "--nowebclient" + } }, "Jellyfin.Server (API Docs)": { "commandName": "Project", + "commandLineArgs": "--nowebclient", "launchBrowser": true, "launchUrl": "api-docs/swagger", - "applicationUrl": "http://localhost:8096", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, - "commandLineArgs": "--nowebclient" + "applicationUrl": "http://localhost:8096" } } -} +} \ No newline at end of file diff --git a/tests/Jellyfin.Naming.Tests/AudioBook/AudioBookListResolverTests.cs b/tests/Jellyfin.Naming.Tests/AudioBook/AudioBookListResolverTests.cs index d9e77dd2e0..656eca339a 100644 --- a/tests/Jellyfin.Naming.Tests/AudioBook/AudioBookListResolverTests.cs +++ b/tests/Jellyfin.Naming.Tests/AudioBook/AudioBookListResolverTests.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using Emby.Naming.AudioBook; using Emby.Naming.Common; @@ -257,6 +258,113 @@ namespace Jellyfin.Naming.Tests.AudioBook Assert.Empty(result); } + [Fact] + public void Resolve_EmptyFileList_ShouldReturnEmptyList() + { + // Arrange + var resolver = GetResolver(); + var files = new List(); + + // Act + var result = resolver.Resolve(files); + + // Assert + Assert.Empty(result); + } + + [Fact] + public void Resolve_WithValidFiles_ShouldReturnAudioBookInfo() + { + // Arrange + var resolver = GetResolver(); + var files = new List + { + new FileSystemMetadata { IsDirectory = false, FullName = "SampleAudioBookFile1.mp3" }, + new FileSystemMetadata { IsDirectory = false, FullName = "SampleAudioBookFile2.mp3" } + }; + + // Act + var result = resolver.Resolve(files); + + // Assert + Assert.NotEmpty(result); + } + + [Fact] + public void Resolve_WithAlternativeFiles_ShouldIncludeAlternativesInAudioBookInfo() + { + // Arrange + var resolver = GetResolver(); + var files = new List + { + new FileSystemMetadata { IsDirectory = false, FullName = "SampleAudioBookFile1.mp3" }, + new FileSystemMetadata { IsDirectory = false, FullName = "SampleAudioBookFile2.mp3" }, + new FileSystemMetadata { IsDirectory = false, FullName = "SampleAudioBookFile2_alternate.mp3" } + }; + + // Act + var result = resolver.Resolve(files); + + // Assert + var audioBookInfo = Assert.Single(result); + Assert.NotEmpty(audioBookInfo.AlternateVersions); + } + + [Fact] + public void Resolve_WithValidFiles_ShouldExtractNameAndYear() + { + // Arrange + var resolver = GetResolver(); + var files = new[] + { + new FileSystemMetadata { IsDirectory = false, FullName = "Harry Potter and the Deathly Hallows (2007)/Chapter 1.ogg" }, + new FileSystemMetadata { IsDirectory = false, FullName = "Batman (2020).ogg" }, + new FileSystemMetadata { IsDirectory = false, FullName = "Batman( 2021 ).mp3" }, + new FileSystemMetadata { IsDirectory = false, FullName = "Batman(*2021*).mp3" }, + new FileSystemMetadata { IsDirectory = false, FullName = "Batman.mp3" }, + new FileSystemMetadata { IsDirectory = false, FullName = " + Batman . .mp3" }, + new FileSystemMetadata { IsDirectory = false, FullName = " .mp3" } + }; + + // Act + var result = resolver.Resolve(files).ToList(); // Convert to a list once + + // Assert + Assert.Equal(files.Length, result.Count); + Assert.Equal("Harry Potter and the Deathly Hallows", result[0].Name); + Assert.Equal(2007, result[0].Year); + Assert.Equal("Batman", result[1].Name); + Assert.Equal(2020, result[1].Year); + Assert.Equal("Batman", result[2].Name); + Assert.Equal(2021, result[2].Year); + Assert.Equal("Batman(*2021*)", result[3].Name); + Assert.Null(result[3].Year); + Assert.Equal("Batman", result[4].Name); + Assert.Null(result[4].Year); + Assert.Equal("+ Batman .", result[5].Name); + Assert.Null(result[5].Year); + Assert.Equal(" ", result[6].Name); + Assert.Null(result[6].Year); + } + + [Fact] + public void Resolve_WithMetadataFiles_ShouldIgnoreMetadataFiles() + { + // Arrange + var resolver = GetResolver(); + var files = new List + { + new FileSystemMetadata { IsDirectory = false, FullName = "Harry Potter and the Deathly Hallows/Chapter 1.ogg" }, + new FileSystemMetadata { IsDirectory = false, FullName = "Harry Potter and the Deathly Hallows/Harry Potter and the Deathly Hallows.nfo" } + }; + + // Act + var result = resolver.Resolve(files); + + // Assert + Assert.Single(result); + } + private AudioBookListResolver GetResolver() { return new AudioBookListResolver(_namingOptions); From b4b58b1c3164b372b1a13ee2e963c0a6cf5e79d1 Mon Sep 17 00:00:00 2001 From: Devon Chessher Date: Sun, 1 Oct 2023 21:59:46 -0400 Subject: [PATCH 2/2] Reverted launchSettings.json to original configuration. --- Jellyfin.Server/Properties/launchSettings.json | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Jellyfin.Server/Properties/launchSettings.json b/Jellyfin.Server/Properties/launchSettings.json index 00b767766d..20d432afc4 100644 --- a/Jellyfin.Server/Properties/launchSettings.json +++ b/Jellyfin.Server/Properties/launchSettings.json @@ -3,28 +3,27 @@ "Jellyfin.Server": { "commandName": "Project", "launchBrowser": true, + "applicationUrl": "http://localhost:8096", "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development", - "JELLYFIN_WEB_DIR": "C:\\Users\\devon\\source\\repos\\jellyfin-web\\dist" - }, - "applicationUrl": "http://localhost:8096" + "ASPNETCORE_ENVIRONMENT": "Development" + } }, "Jellyfin.Server (nowebclient)": { "commandName": "Project", - "commandLineArgs": "--nowebclient", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" - } + }, + "commandLineArgs": "--nowebclient" }, "Jellyfin.Server (API Docs)": { "commandName": "Project", - "commandLineArgs": "--nowebclient", "launchBrowser": true, "launchUrl": "api-docs/swagger", + "applicationUrl": "http://localhost:8096", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, - "applicationUrl": "http://localhost:8096" + "commandLineArgs": "--nowebclient" } } -} \ No newline at end of file +}