From fd08e9d2c443bc8ec94b70966075bfc6c83a46c1 Mon Sep 17 00:00:00 2001 From: santschi Date: Wed, 8 Mar 2023 22:43:43 +0100 Subject: [PATCH] Fixed: Check for unexpected parent tags to fix GoodReads Series --- .../Resources/WorkResourcesFixture.cs | 62 +++++++++++++++++++ .../Goodreads/Resources/WorkResource.cs | 5 ++ 2 files changed, 67 insertions(+) create mode 100644 src/NzbDrone.Core.Test/MetadataSource/Goodreads/Resources/WorkResourcesFixture.cs diff --git a/src/NzbDrone.Core.Test/MetadataSource/Goodreads/Resources/WorkResourcesFixture.cs b/src/NzbDrone.Core.Test/MetadataSource/Goodreads/Resources/WorkResourcesFixture.cs new file mode 100644 index 000000000..8650674ab --- /dev/null +++ b/src/NzbDrone.Core.Test/MetadataSource/Goodreads/Resources/WorkResourcesFixture.cs @@ -0,0 +1,62 @@ +using System; +using System.Xml.Linq; +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Core.MetadataSource.Goodreads; +using NzbDrone.Core.Test.Framework; +using NzbDrone.Test.Common; + +namespace NzbDrone.Core.Test.MetadataSource.Goodreads.Resources +{ + [TestFixture] + public class WorkResourceFixture : CoreTest + { + [Test] + public void parse_non_work() + { + XElement element = new XElement("Dummy", "entry"); + WorkResource work = new WorkResource(); + + Assert.Throws(() => work.Parse(element)); + + work.OriginalTitle.Should().Be(null); + + ExceptionVerification.IgnoreWarns(); + } + + [Test] + public void parse_minimal_work() + { + XElement element = new XElement("work", + new XElement("original_title", "Book Title"), + new XElement("id", "123456789")); + + WorkResource work = new WorkResource(); + + work.Parse(element); + + work.OriginalTitle.Should().Be("Book Title"); + work.Id.Should().Be(123456789); + + ExceptionVerification.IgnoreWarns(); + } + + [Test] + public void parse_minimal_work_with_surrounding_tags() + { + XElement element = new XElement("series_works", + new XElement("work", + new XElement("original_title", "Book Title"), + new XElement("id", "123456789"))); + + WorkResource work = new WorkResource(); + + work.Parse(element); + + work.OriginalTitle.Should().Be("Book Title"); + work.Id.Should().Be(123456789); + + ExceptionVerification.IgnoreWarns(); + } + } +} diff --git a/src/NzbDrone.Core/MetadataSource/Goodreads/Resources/WorkResource.cs b/src/NzbDrone.Core/MetadataSource/Goodreads/Resources/WorkResource.cs index 15d0a98b3..a521bbb8a 100644 --- a/src/NzbDrone.Core/MetadataSource/Goodreads/Resources/WorkResource.cs +++ b/src/NzbDrone.Core/MetadataSource/Goodreads/Resources/WorkResource.cs @@ -94,6 +94,11 @@ namespace NzbDrone.Core.MetadataSource.Goodreads public override void Parse(XElement element) { + if (element.AncestorsAndSelf().First().Name != "work") + { + element = element.Element("work"); + } + Id = element.ElementAsLong("id"); var bestBookElement = element.Element("best_book");