Add season nfo parser test

This commit is contained in:
David 2021-01-20 20:02:03 +01:00
parent dbd70bd394
commit ccea02fbb2
2 changed files with 169 additions and 0 deletions

View File

@ -0,0 +1,83 @@
#pragma warning disable CA5369
using System;
using System.Linq;
using System.Threading;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Entities.TV;
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<IProviderManager>();
providerManager.Setup(x => x.GetExternalIdInfos(It.IsAny<IHasProviderIds>()))
.Returns(Enumerable.Empty<ExternalIdInfo>());
var config = new Mock<IConfigurationManager>();
config.Setup(x => x.GetConfiguration(It.IsAny<string>()))
.Returns(new XbmcMetadataOptions());
_parser = new SeasonNfoParser(new NullLogger<SeasonNfoParser>(), config.Object, providerManager.Object);
}
[Fact]
public void Fetch_Valid_Succes()
{
var result = new MetadataResult<Season>()
{
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<Season>();
Assert.Throws<ArgumentException>(() => _parser.Fetch(result, "Test Data/Season 01.nfo", CancellationToken.None));
}
[Fact]
public void Fetch_NullResult_ThrowsArgumentException()
{
var result = new MetadataResult<Season>()
{
Item = new Season()
};
Assert.Throws<ArgumentException>(() => _parser.Fetch(result, string.Empty, CancellationToken.None));
}
}
}

View File

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<season>
<plot />
<outline />
<lockdata>false</lockdata>
<dateadded>2020-06-14 17:26:51</dateadded>
<title>Season 1</title>
<year>2019</year>
<tvdbid>359728</tvdbid>
<premiered>2019-11-08</premiered>
<releasedate>2019-11-08</releasedate>
<art>
<poster>/media/Serien/High School Musical The Musical The Series (2019)/Season 1/Season 1.jpeg</poster>
</art>
<actor>
<name>Olivia Rodrigo</name>
<role>Nini</role>
<type>Actor</type>
<sortorder>0</sortorder>
<thumb>/config/metadata/People/O/Olivia Rodrigo/poster.jpg</thumb>
</actor>
<actor>
<name>Kate Reinders</name>
<role>Miss Jenn</role>
<type>Actor</type>
<sortorder>1</sortorder>
<thumb>/config/metadata/People/K/Kate Reinders/poster.jpg</thumb>
</actor>
<actor>
<name>Sofia Wylie</name>
<role>Gina</role>
<type>Actor</type>
<sortorder>2</sortorder>
<thumb>/config/metadata/People/S/Sofia Wylie/poster.jpg</thumb>
</actor>
<actor>
<name>Matt Cornett</name>
<role>E.J.</role>
<type>Actor</type>
<sortorder>3</sortorder>
<thumb>/config/metadata/People/M/Matt Cornett/poster.jpg</thumb>
</actor>
<actor>
<name>Dara Reneé</name>
<role>Kourtney</role>
<type>Actor</type>
<sortorder>4</sortorder>
<thumb>/config/metadata/People/D/Dara Reneé/poster.jpg</thumb>
</actor>
<actor>
<name>Julia Lester</name>
<role>Ashlyn</role>
<type>Actor</type>
<sortorder>5</sortorder>
<thumb>/config/metadata/People/J/Julia Lester/poster.jpg</thumb>
</actor>
<actor>
<name>Joshua Bassett</name>
<role>Ricky</role>
<type>Actor</type>
<sortorder>6</sortorder>
<thumb>/config/metadata/People/J/Joshua Bassett/poster.jpg</thumb>
</actor>
<actor>
<name>Frankie A. Rodriguez</name>
<role>Carlos</role>
<type>Actor</type>
<sortorder>7</sortorder>
<thumb>/config/metadata/People/F/Frankie A. Rodriguez/poster.jpg</thumb>
</actor>
<actor>
<name>Larry Saperstein</name>
<role>Big Red</role>
<type>Actor</type>
<sortorder>8</sortorder>
<thumb>/config/metadata/People/L/Larry Saperstein/poster.jpg</thumb>
</actor>
<actor>
<name>Mark St. Cyr</name>
<role>Mr. Mazzara</role>
<type>Actor</type>
<sortorder>9</sortorder>
<thumb>/config/metadata/People/M/Mark St. Cyr/poster.jpg</thumb>
</actor>
<seasonnumber>1</seasonnumber>
</season>