using Jellyfin.Plugin.MetaShark.Api; using Jellyfin.Plugin.MetaShark.Core; using Jellyfin.Plugin.MetaShark.Model; using Jellyfin.Plugin.MetaShark.Providers; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Entities; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using Moq; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Jellyfin.Plugin.MetaShark.Test { [TestClass] public class MovieImageProviderTest { ILoggerFactory loggerFactory = LoggerFactory.Create(builder => builder.AddSimpleConsole(options => { options.IncludeScopes = true; options.SingleLine = true; options.TimestampFormat = "hh:mm:ss "; })); [TestMethod] public void TestGetMovieImage() { var info = new MediaBrowser.Controller.Entities.Movies.Movie() { Name = "秒速5厘米", PreferredMetadataLanguage = "zh", ProviderIds = new Dictionary { { BaseProvider.DoubanProviderId, "2043546" }, { MetadataProvider.Tmdb.ToString(), "38142" } } }; var httpClientFactory = new DefaultHttpClientFactory(); var libraryManagerStub = new Mock(); var httpContextAccessorStub = new Mock(); var doubanApi = new DoubanApi(loggerFactory); var tmdbApi = new TmdbApi(loggerFactory); var omdbApi = new OmdbApi(loggerFactory); var imdbApi = new ImdbApi(loggerFactory); Task.Run(async () => { var provider = new MovieImageProvider(httpClientFactory, loggerFactory, libraryManagerStub.Object, httpContextAccessorStub.Object, doubanApi, tmdbApi, omdbApi, imdbApi); var result = await provider.GetImages(info, CancellationToken.None); Assert.IsNotNull(result); var str = result.ToJson(); Console.WriteLine(result.ToJson()); }).GetAwaiter().GetResult(); } [TestMethod] public void TestGetMovieImageFromTMDB() { var info = new MediaBrowser.Controller.Entities.Movies.Movie() { PreferredMetadataLanguage = "zh", ProviderIds = new Dictionary { { MetadataProvider.Tmdb.ToString(), "752" }, { Plugin.ProviderId, MetaSource.Tmdb.ToString() } } }; var httpClientFactory = new DefaultHttpClientFactory(); var libraryManagerStub = new Mock(); var httpContextAccessorStub = new Mock(); var doubanApi = new DoubanApi(loggerFactory); var tmdbApi = new TmdbApi(loggerFactory); var omdbApi = new OmdbApi(loggerFactory); var imdbApi = new ImdbApi(loggerFactory); Task.Run(async () => { var provider = new MovieImageProvider(httpClientFactory, loggerFactory, libraryManagerStub.Object, httpContextAccessorStub.Object, doubanApi, tmdbApi, omdbApi, imdbApi); var result = await provider.GetImages(info, CancellationToken.None); Assert.IsNotNull(result); var str = result.ToJson(); Console.WriteLine(result.ToJson()); }).GetAwaiter().GetResult(); } [TestMethod] public void TestGetImageResponse() { var httpClientFactory = new DefaultHttpClientFactory(); var libraryManagerStub = new Mock(); var httpContextAccessorStub = new Mock(); var doubanApi = new DoubanApi(loggerFactory); var tmdbApi = new TmdbApi(loggerFactory); var omdbApi = new OmdbApi(loggerFactory); var imdbApi = new ImdbApi(loggerFactory); Task.Run(async () => { var provider = new MovieImageProvider(httpClientFactory, loggerFactory, libraryManagerStub.Object, httpContextAccessorStub.Object, doubanApi, tmdbApi, omdbApi, imdbApi); var result = await provider.GetImageResponse("https://img1.doubanio.com/view/photo/m/public/p2893270877.jpg", CancellationToken.None); Assert.IsNotNull(result); var str = result.ToJson(); Console.WriteLine(result.ToJson()); }).GetAwaiter().GetResult(); } } }