From 585821954da6971209c0baab424551d91fcf7fd8 Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Sat, 9 Jan 2021 20:14:50 +0100 Subject: [PATCH] Add tests for series nfo --- .../Parsers/BaseNfoParser.cs | 44 +++-- .../Parsers/MovieNfoParserTests.cs | 35 +++- .../Parsers/SeriesNfoParserTests.cs | 91 +++++++++ .../Test Data/American Gods.nfo | 185 ++++++++++++++++++ 4 files changed, 332 insertions(+), 23 deletions(-) create mode 100644 tests/Jellyfin.XbmcMetadata.Tests/Parsers/SeriesNfoParserTests.cs create mode 100644 tests/Jellyfin.XbmcMetadata.Tests/Test Data/American Gods.nfo diff --git a/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs b/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs index a675173a9..3e12c5757 100644 --- a/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs +++ b/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs @@ -63,14 +63,14 @@ namespace MediaBrowser.XbmcMetadata.Parsers /// metadataFile is null or empty. public void Fetch(MetadataResult item, string metadataFile, CancellationToken cancellationToken) { - if (item == null) + if (item.Item == null) { - throw new ArgumentNullException(nameof(item)); + throw new ArgumentException("Item can't be null.", nameof(item)); } if (string.IsNullOrEmpty(metadataFile)) { - throw new ArgumentException("The metadata file was empty or null.", nameof(metadataFile)); + throw new ArgumentException("The metadata filepath was empty.", nameof(metadataFile)); } _validProviderIds = new Dictionary(StringComparer.OrdinalIgnoreCase); @@ -270,17 +270,13 @@ namespace MediaBrowser.XbmcMetadata.Parsers if (!string.IsNullOrWhiteSpace(val)) { - if (DateTime.TryParseExact(val, BaseNfoSaver.DateAddedFormat, CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out var added)) - { - item.DateCreated = added.ToUniversalTime(); - } - else if (DateTime.TryParse(val, CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out added)) + if (DateTime.TryParse(val, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out var added)) { item.DateCreated = added.ToUniversalTime(); } else { - Logger.LogWarning("Invalid Added value found: " + val); + Logger.LogWarning("Invalid Added value found: {Value}", val); } } @@ -384,16 +380,8 @@ namespace MediaBrowser.XbmcMetadata.Parsers } case "tagline": - { - var val = reader.ReadElementContentAsString(); - - if (!string.IsNullOrWhiteSpace(val)) - { - item.Tagline = val; - } - - break; - } + item.Tagline = reader.ReadElementContentAsString(); + break; case "country": { @@ -710,6 +698,24 @@ namespace MediaBrowser.XbmcMetadata.Parsers break; } + case "uniqueid": + { + if (reader.IsEmptyElement) + { + reader.Read(); + break; + } + + var provider = reader.GetAttribute("type"); + var id = reader.ReadElementContentAsString(); + if (!string.IsNullOrWhiteSpace(provider) && !string.IsNullOrWhiteSpace(id)) + { + item.SetProviderId(provider, id); + } + + break; + } + default: string readerName = reader.Name; if (_validProviderIds.TryGetValue(readerName, out string? providerIdValue)) diff --git a/tests/Jellyfin.XbmcMetadata.Tests/Parsers/MovieNfoParserTests.cs b/tests/Jellyfin.XbmcMetadata.Tests/Parsers/MovieNfoParserTests.cs index 7d6b70f93..7651653a1 100644 --- a/tests/Jellyfin.XbmcMetadata.Tests/Parsers/MovieNfoParserTests.cs +++ b/tests/Jellyfin.XbmcMetadata.Tests/Parsers/MovieNfoParserTests.cs @@ -16,8 +16,9 @@ namespace Jellyfin.XbmcMetadata.Parsers.Tests { public class MovieNfoParserTests { - [Fact] - public void Fetch_Valid_Succes() + private readonly MovieNfoParser _parser; + + public MovieNfoParserTests() { var providerManager = new Mock(); providerManager.Setup(x => x.GetExternalIdInfos(It.IsAny())) @@ -25,13 +26,18 @@ namespace Jellyfin.XbmcMetadata.Parsers.Tests var config = new Mock(); config.Setup(x => x.GetConfiguration(It.IsAny())) .Returns(new XbmcMetadataOptions()); - var parser = new MovieNfoParser(new NullLogger(), config.Object, providerManager.Object); + _parser = new MovieNfoParser(new NullLogger(), config.Object, providerManager.Object); + } + [Fact] + public void Fetch_Valid_Succes() + { var result = new MetadataResult