This repository has been archived by the owner on Oct 13, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e94a46a
commit b4c683e
Showing
10 changed files
with
656 additions
and
138 deletions.
There are no files selected for viewing
115 changes: 115 additions & 0 deletions
115
Jellyfin.Plugin.Themerr.Tests/BootstrapJellyfinServer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
using MetadataProvider = MediaBrowser.Model.Entities.MetadataProvider; | ||
using Movie = MediaBrowser.Controller.Entities.Movies.Movie; | ||
|
||
namespace Jellyfin.Plugin.Themerr.Tests; | ||
|
||
[CollectionDefinition("Bootstrapped Collection")] | ||
public class BootstrappedCollection : ICollectionFixture<BootstrapJellyfinServer> | ||
{ | ||
// This class doesn't need to have any code, or even be long-lived. | ||
// All it needs is to just exist, and be annotated with CollectionDefinition. | ||
} | ||
|
||
/// <summary> | ||
/// This class is used to bootstrap a Jellyfin server with mock movies | ||
/// </summary> | ||
public class BootstrapJellyfinServer | ||
{ | ||
/// <summary> | ||
/// Mock movies to use for testing | ||
/// </summary> | ||
/// <returns></returns> | ||
public static List<Movie> MockMovies() | ||
{ | ||
return new List<Movie> | ||
{ | ||
new() | ||
{ | ||
Name = "Elephants Dream", | ||
ProductionYear = 2006, | ||
ProviderIds = new Dictionary<string, string> | ||
{ | ||
{ MetadataProvider.Imdb.ToString(), "tt0807840"}, | ||
{ MetadataProvider.Tmdb.ToString(), "9761"}, | ||
} | ||
}, | ||
new() | ||
{ | ||
Name = "Sita Sings the Blues", | ||
ProductionYear = 2008, | ||
ProviderIds = new Dictionary<string, string> | ||
{ | ||
{ MetadataProvider.Imdb.ToString(), "tt1172203"}, | ||
{ MetadataProvider.Tmdb.ToString(), "20529"}, | ||
} | ||
}, | ||
new() | ||
{ | ||
Name = "Big Buck Bunny", | ||
ProductionYear = 2008, | ||
ProviderIds = new Dictionary<string, string> | ||
{ | ||
{ MetadataProvider.Imdb.ToString(), "tt1254207"}, | ||
{ MetadataProvider.Tmdb.ToString(), "10378"}, | ||
} | ||
}, | ||
new() | ||
{ | ||
Name = "Sintel", | ||
ProductionYear = 2010, | ||
ProviderIds = new Dictionary<string, string> | ||
{ | ||
{ MetadataProvider.Imdb.ToString(), "tt1727587"}, | ||
{ MetadataProvider.Tmdb.ToString(), "45745"}, | ||
} | ||
}, | ||
}; | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Create mock movies from stub video | ||
/// </summary> | ||
[Fact] | ||
[Trait("Category", "Init")] | ||
private void CreateMockMovies() | ||
{ | ||
var mockMovies = MockMovies(); | ||
|
||
// get the stub video path based on the directory of this file | ||
var stubVideoPath = Path.Combine( | ||
Directory.GetCurrentDirectory(), | ||
"data", | ||
"video_stub.mp4" | ||
); | ||
|
||
Assert.True(File.Exists(stubVideoPath), "Could not find ./data/video_stub.mp4"); | ||
|
||
foreach (var movie in mockMovies) | ||
{ | ||
// copy the ./data/video_stub.mp4 to the movie folder "movie.Name (movie.ProductionYear)" | ||
var movieFolder = Path.Combine( | ||
"themerr_jellyfin_tests", | ||
$"{movie.Name} ({movie.ProductionYear})" | ||
); | ||
|
||
// create the movie folder | ||
Directory.CreateDirectory(movieFolder); | ||
|
||
// copy the video_stub.mp4 to the movie folder, renaming it based on movie name | ||
var movieVideoPath = Path.Combine( | ||
movieFolder, | ||
$"{movie.Name} ({movie.ProductionYear}).mp4" | ||
); | ||
|
||
// if file does not exist | ||
if (!File.Exists(movieVideoPath)) | ||
{ | ||
// copy the stub video to the movie folder | ||
File.Copy(stubVideoPath, movieVideoPath); | ||
} | ||
|
||
Assert.True(File.Exists(movieVideoPath), $"Could not find {movieVideoPath}"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
namespace Jellyfin.Plugin.Themerr.Tests | ||
{ | ||
/// <summary> | ||
/// A simple logger for tests | ||
/// </summary> | ||
public static class TestLogger | ||
{ | ||
// log a message to console | ||
private static ITestOutputHelper? _output; | ||
|
||
public static void Initialize(ITestOutputHelper output) | ||
{ | ||
_output = output ?? throw new ArgumentNullException(nameof(output)); | ||
} | ||
|
||
/// <summary> | ||
/// Logs a message to the test output | ||
/// </summary> | ||
/// <param name="message"></param> | ||
/// <param name="type"></param> | ||
public static void Log(string message, string type = "INFO") | ||
{ | ||
_output?.WriteLine($"[{type}] {message}"); | ||
} | ||
|
||
/// <summary> | ||
/// Logs a critical message to the test output | ||
/// </summary> | ||
/// <param name="message"></param> | ||
public static void Critical(string message) | ||
{ | ||
Log(message, "CRITICAL"); | ||
} | ||
|
||
/// <summary> | ||
/// Logs a debug message to the test output | ||
/// </summary> | ||
/// <param name="message"></param> | ||
public static void Debug(string message) | ||
{ | ||
Log(message, "DEBUG"); | ||
} | ||
|
||
/// <summary> | ||
/// Logs an error message to the test output | ||
/// </summary> | ||
/// <param name="message"></param> | ||
public static void Error(string message) | ||
{ | ||
Log(message, "ERROR"); | ||
} | ||
|
||
/// <summary> | ||
/// Logs an info message to the test output | ||
/// </summary> | ||
/// <param name="message"></param> | ||
public static void Info(string message) | ||
{ | ||
Log(message, "INFO"); | ||
} | ||
|
||
/// <summary> | ||
/// Logs a warning message to the test output | ||
/// </summary> | ||
/// <param name="message"></param> | ||
public static void Warn(string message) | ||
{ | ||
Log(message, "WARN"); | ||
} | ||
} | ||
} |
Oops, something went wrong.