From 1f33c519779bd197c9d0d6ff2373cebf3a5dd3d9 Mon Sep 17 00:00:00 2001 From: dtparr Date: Wed, 8 Apr 2020 05:17:20 +0000 Subject: [PATCH 1/6] Add Unit Test for the Extras directories. Parameterize the valid extras as well as the null conditions. --- .../Jellyfin.Naming.Tests/Video/ExtraTests.cs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs b/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs index 1646237a0..c2a9ef2da 100644 --- a/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs +++ b/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs @@ -45,6 +45,46 @@ namespace Jellyfin.Naming.Tests.Video Test("300-behindthescenes.mp4", ExtraType.BehindTheScenes, videoOptions); } + [Fact] + public void TestDirectories() + { + var videoOptions = new NamingOptions(); + + (ExtraType Type, string dirName)[] extraDirectoryNameTests = + { + (ExtraType.BehindTheScenes, "behind the scenes" ), + (ExtraType.DeletedScene, "deleted scenes" ), + (ExtraType.Interview, "interviews" ), + (ExtraType.Scene, "scenes" ), + (ExtraType.Sample, "samples" ), + (ExtraType.Clip, "shorts" ), + (ExtraType.Clip, "featurettes" ), + (ExtraType.Unknown, "extras" ), + }; + + foreach ((ExtraType type, string dirName) in extraDirectoryNameTests) + { + Test(dirName + "/300.mp4", type, videoOptions); + Test("300/" + dirName + "/something.mkv", type, videoOptions); + Test("/data/something/Movies/300/" + dirName + "/whoknows.mp4", type, videoOptions); + } + + //Test the null condition + string[] nonExtraDirectoryNames = + { + "gibberish", + "not a scene", + }; + foreach (string dirName in nonExtraDirectoryNames) + { + Test(dirName + "/300.mp4", null, videoOptions); + Test("300/" + dirName + "/something.mkv", null, videoOptions); + Test("/data/something/Movies/300/" + dirName + "/whoknows.mp4", null, videoOptions); + } + Test("/data/something/Movies/not a scene/not a scene.mp4", null, videoOptions); + Test("/data/something/Movies/The Big Short/The Big Short.mp4", null, videoOptions); + } + [Fact] public void TestSample() { From ce86455747f73b45d2fec5e507573d2368e498f5 Mon Sep 17 00:00:00 2001 From: dtparr Date: Fri, 10 Apr 2020 21:18:41 +0000 Subject: [PATCH 2/6] Update to use the Theory/InlineData method to parameterize unit tests --- .../Jellyfin.Naming.Tests/Video/ExtraTests.cs | 59 ++++++++----------- 1 file changed, 25 insertions(+), 34 deletions(-) diff --git a/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs b/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs index c2a9ef2da..6dc5792e2 100644 --- a/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs +++ b/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs @@ -45,44 +45,35 @@ namespace Jellyfin.Naming.Tests.Video Test("300-behindthescenes.mp4", ExtraType.BehindTheScenes, videoOptions); } - [Fact] - public void TestDirectories() + [Theory] + [InlineData(ExtraType.BehindTheScenes, "behind the scenes" )] + [InlineData(ExtraType.DeletedScene, "deleted scenes" )] + [InlineData(ExtraType.Interview, "interviews" )] + [InlineData(ExtraType.Scene, "scenes" )] + [InlineData(ExtraType.Sample, "samples" )] + [InlineData(ExtraType.Clip, "shorts" )] + [InlineData(ExtraType.Clip, "featurettes" )] + [InlineData(ExtraType.Unknown, "extras" )] + public void TestDirectories(ExtraType type, string dirName) { var videoOptions = new NamingOptions(); - (ExtraType Type, string dirName)[] extraDirectoryNameTests = - { - (ExtraType.BehindTheScenes, "behind the scenes" ), - (ExtraType.DeletedScene, "deleted scenes" ), - (ExtraType.Interview, "interviews" ), - (ExtraType.Scene, "scenes" ), - (ExtraType.Sample, "samples" ), - (ExtraType.Clip, "shorts" ), - (ExtraType.Clip, "featurettes" ), - (ExtraType.Unknown, "extras" ), - }; + Test(dirName + "/300.mp4", type, videoOptions); + Test("300/" + dirName + "/something.mkv", type, videoOptions); + Test("/data/something/Movies/300/" + dirName + "/whoknows.mp4", type, videoOptions); + } - foreach ((ExtraType type, string dirName) in extraDirectoryNameTests) - { - Test(dirName + "/300.mp4", type, videoOptions); - Test("300/" + dirName + "/something.mkv", type, videoOptions); - Test("/data/something/Movies/300/" + dirName + "/whoknows.mp4", type, videoOptions); - } - - //Test the null condition - string[] nonExtraDirectoryNames = - { - "gibberish", - "not a scene", - }; - foreach (string dirName in nonExtraDirectoryNames) - { - Test(dirName + "/300.mp4", null, videoOptions); - Test("300/" + dirName + "/something.mkv", null, videoOptions); - Test("/data/something/Movies/300/" + dirName + "/whoknows.mp4", null, videoOptions); - } - Test("/data/something/Movies/not a scene/not a scene.mp4", null, videoOptions); - Test("/data/something/Movies/The Big Short/The Big Short.mp4", null, videoOptions); + [Theory] + [InlineData("gibberish")] + [InlineData("not a scene")] + [InlineData("The Big Short")] + public void TestNonExtraDirectories(string dirName) + { + var videoOptions = new NamingOptions(); + Test(dirName + "/300.mp4", null, videoOptions); + Test("300/" + dirName + "/something.mkv", null, videoOptions); + Test("/data/something/Movies/300/" + dirName + "/whoknows.mp4", null, videoOptions); + Test("/data/something/Movies/" + dirName + "/" + dirName + ".mp4", null, videoOptions); } [Fact] From 8e42d0063d0d13aa3b95f1b6b9e031a5e4deb86f Mon Sep 17 00:00:00 2001 From: dtparr Date: Fri, 10 Apr 2020 21:21:22 +0000 Subject: [PATCH 3/6] Fix tab/space issue causing github oddity --- tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs b/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs index 6dc5792e2..ceaf52bb5 100644 --- a/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs +++ b/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs @@ -45,7 +45,7 @@ namespace Jellyfin.Naming.Tests.Video Test("300-behindthescenes.mp4", ExtraType.BehindTheScenes, videoOptions); } - [Theory] + [Theory] [InlineData(ExtraType.BehindTheScenes, "behind the scenes" )] [InlineData(ExtraType.DeletedScene, "deleted scenes" )] [InlineData(ExtraType.Interview, "interviews" )] From 8e67cb541eac38efc3ebb9ada5f73d46249dc92c Mon Sep 17 00:00:00 2001 From: dtparr Date: Fri, 10 Apr 2020 23:00:30 +0000 Subject: [PATCH 4/6] Refactor the NamingOptions instantiations from both new and pre-existing facts/theories to be a readonly field to save instantiation costs --- .../Jellyfin.Naming.Tests/Video/ExtraTests.cs | 55 +++++++++---------- 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs b/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs index ceaf52bb5..4d730eef3 100644 --- a/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs +++ b/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs @@ -7,6 +7,8 @@ namespace Jellyfin.Naming.Tests.Video { public class ExtraTests : BaseVideoTest { + private readonly NamingOptions _videoOptions = new NamingOptions(); + // Requirements // movie-deleted = ExtraType deletedscene @@ -15,34 +17,32 @@ namespace Jellyfin.Naming.Tests.Video [Fact] public void TestKodiExtras() { - var videoOptions = new NamingOptions(); - Test("trailer.mp4", ExtraType.Trailer, videoOptions); - Test("300-trailer.mp4", ExtraType.Trailer, videoOptions); + Test("trailer.mp4", ExtraType.Trailer, _videoOptions); + Test("300-trailer.mp4", ExtraType.Trailer, _videoOptions); - Test("theme.mp3", ExtraType.ThemeSong, videoOptions); + Test("theme.mp3", ExtraType.ThemeSong, _videoOptions); } [Fact] public void TestExpandedExtras() { - var videoOptions = new NamingOptions(); - Test("trailer.mp4", ExtraType.Trailer, videoOptions); - Test("trailer.mp3", null, videoOptions); - Test("300-trailer.mp4", ExtraType.Trailer, videoOptions); + Test("trailer.mp4", ExtraType.Trailer, _videoOptions); + Test("trailer.mp3", null, _videoOptions); + Test("300-trailer.mp4", ExtraType.Trailer, _videoOptions); - Test("theme.mp3", ExtraType.ThemeSong, videoOptions); - Test("theme.mkv", null, videoOptions); + Test("theme.mp3", ExtraType.ThemeSong, _videoOptions); + Test("theme.mkv", null, _videoOptions); - Test("300-scene.mp4", ExtraType.Scene, videoOptions); - Test("300-scene2.mp4", ExtraType.Scene, videoOptions); - Test("300-clip.mp4", ExtraType.Clip, videoOptions); + Test("300-scene.mp4", ExtraType.Scene, _videoOptions); + Test("300-scene2.mp4", ExtraType.Scene, _videoOptions); + Test("300-clip.mp4", ExtraType.Clip, _videoOptions); - Test("300-deleted.mp4", ExtraType.DeletedScene, videoOptions); - Test("300-deletedscene.mp4", ExtraType.DeletedScene, videoOptions); - Test("300-interview.mp4", ExtraType.Interview, videoOptions); - Test("300-behindthescenes.mp4", ExtraType.BehindTheScenes, videoOptions); + Test("300-deleted.mp4", ExtraType.DeletedScene, _videoOptions); + Test("300-deletedscene.mp4", ExtraType.DeletedScene, _videoOptions); + Test("300-interview.mp4", ExtraType.Interview, _videoOptions); + Test("300-behindthescenes.mp4", ExtraType.BehindTheScenes, _videoOptions); } [Theory] @@ -56,11 +56,9 @@ namespace Jellyfin.Naming.Tests.Video [InlineData(ExtraType.Unknown, "extras" )] public void TestDirectories(ExtraType type, string dirName) { - var videoOptions = new NamingOptions(); - - Test(dirName + "/300.mp4", type, videoOptions); - Test("300/" + dirName + "/something.mkv", type, videoOptions); - Test("/data/something/Movies/300/" + dirName + "/whoknows.mp4", type, videoOptions); + Test(dirName + "/300.mp4", type, _videoOptions); + Test("300/" + dirName + "/something.mkv", type, _videoOptions); + Test("/data/something/Movies/300/" + dirName + "/whoknows.mp4", type, _videoOptions); } [Theory] @@ -69,19 +67,16 @@ namespace Jellyfin.Naming.Tests.Video [InlineData("The Big Short")] public void TestNonExtraDirectories(string dirName) { - var videoOptions = new NamingOptions(); - Test(dirName + "/300.mp4", null, videoOptions); - Test("300/" + dirName + "/something.mkv", null, videoOptions); - Test("/data/something/Movies/300/" + dirName + "/whoknows.mp4", null, videoOptions); - Test("/data/something/Movies/" + dirName + "/" + dirName + ".mp4", null, videoOptions); + Test(dirName + "/300.mp4", null, _videoOptions); + Test("300/" + dirName + "/something.mkv", null, _videoOptions); + Test("/data/something/Movies/300/" + dirName + "/whoknows.mp4", null, _videoOptions); + Test("/data/something/Movies/" + dirName + "/" + dirName + ".mp4", null, _videoOptions); } [Fact] public void TestSample() { - var videoOptions = new NamingOptions(); - - Test("300-sample.mp4", ExtraType.Sample, videoOptions); + Test("300-sample.mp4", ExtraType.Sample, _videoOptions); } private void Test(string input, ExtraType? expectedType, NamingOptions videoOptions) From e027f4645f8db1a702cc31fa98ff24950c8ecefd Mon Sep 17 00:00:00 2001 From: dtparr Date: Sat, 11 Apr 2020 13:33:06 -0500 Subject: [PATCH 5/6] Whitespace fix Co-Authored-By: Bond-009 --- tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs b/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs index 4d730eef3..cdaa644c6 100644 --- a/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs +++ b/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs @@ -17,7 +17,6 @@ namespace Jellyfin.Naming.Tests.Video [Fact] public void TestKodiExtras() { - Test("trailer.mp4", ExtraType.Trailer, _videoOptions); Test("300-trailer.mp4", ExtraType.Trailer, _videoOptions); From 41f6fa0ae817a8346ebc6c216490333efc13a345 Mon Sep 17 00:00:00 2001 From: dtparr Date: Sat, 11 Apr 2020 13:33:16 -0500 Subject: [PATCH 6/6] Whitespace fix Co-Authored-By: Bond-009 --- tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs b/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs index cdaa644c6..a64d17349 100644 --- a/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs +++ b/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs @@ -26,7 +26,6 @@ namespace Jellyfin.Naming.Tests.Video [Fact] public void TestExpandedExtras() { - Test("trailer.mp4", ExtraType.Trailer, _videoOptions); Test("trailer.mp3", null, _videoOptions); Test("300-trailer.mp4", ExtraType.Trailer, _videoOptions);