#pragma warning disable CA5369 using System; using System.Linq; using System.Threading; using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Providers; using MediaBrowser.XbmcMetadata.Parsers; using Microsoft.Extensions.Logging.Abstractions; using Moq; using Xunit; namespace Jellyfin.XbmcMetadata.Tests.Parsers { public class SeasonNfoProviderTests { private readonly SeasonNfoParser _parser; public SeasonNfoProviderTests() { var providerManager = new Mock(); providerManager.Setup(x => x.GetExternalIdInfos(It.IsAny())) .Returns(Enumerable.Empty()); var config = new Mock(); config.Setup(x => x.GetConfiguration(It.IsAny())) .Returns(new XbmcMetadataOptions()); var user = new Mock(); var userData = new Mock(); _parser = new SeasonNfoParser(new NullLogger(), config.Object, providerManager.Object, user.Object, userData.Object); } [Fact] public void Fetch_Valid_Success() { var result = new MetadataResult() { Item = new Season() }; _parser.Fetch(result, "Test Data/Season 01.nfo", CancellationToken.None); var item = result.Item; Assert.Equal("Season 1", item.Name); Assert.Equal(1, item.IndexNumber); Assert.False(item.IsLocked); Assert.Equal(2019, item.ProductionYear); Assert.Equal(new DateTime(2019, 11, 08), item.PremiereDate); Assert.Equal(new DateTime(2020, 06, 14, 17, 26, 51), item.DateCreated); Assert.Equal(10, result.People.Count); Assert.True(result.People.All(x => x.Type == PersonType.Actor)); // Only test one actor var nini = result.People.FirstOrDefault(x => x.Role.Equals("Nini", StringComparison.Ordinal)); Assert.NotNull(nini); Assert.Equal("Olivia Rodrigo", nini!.Name); Assert.Equal(0, nini!.SortOrder); Assert.Equal("/config/metadata/People/O/Olivia Rodrigo/poster.jpg", nini!.ImageUrl); } [Fact] public void Fetch_WithNullItem_ThrowsArgumentException() { var result = new MetadataResult(); Assert.Throws(() => _parser.Fetch(result, "Test Data/Season 01.nfo", CancellationToken.None)); } [Fact] public void Fetch_NullResult_ThrowsArgumentException() { var result = new MetadataResult() { Item = new Season() }; Assert.Throws(() => _parser.Fetch(result, string.Empty, CancellationToken.None)); } } }