From 68b8ccc826612c6353e65b8060cb21b58c145cc6 Mon Sep 17 00:00:00 2001 From: Tom Andrews Date: Sun, 10 Mar 2019 22:20:24 +0000 Subject: [PATCH] Fixed: NullReferenceException in GetAlbums --- .../NzbDrone.Core.Test.csproj | 3 +- .../ParsingServiceTests/GetAlbumsFixture.cs | 38 +++++++++++++++++++ src/NzbDrone.Core/Parser/ParsingService.cs | 2 +- 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 src/NzbDrone.Core.Test/ParserTests/ParsingServiceTests/GetAlbumsFixture.cs diff --git a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 4a40c277f..b93803de2 100644 --- a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -362,6 +362,7 @@ + @@ -613,4 +614,4 @@ - \ No newline at end of file + diff --git a/src/NzbDrone.Core.Test/ParserTests/ParsingServiceTests/GetAlbumsFixture.cs b/src/NzbDrone.Core.Test/ParserTests/ParsingServiceTests/GetAlbumsFixture.cs new file mode 100644 index 000000000..4a696478a --- /dev/null +++ b/src/NzbDrone.Core.Test/ParserTests/ParsingServiceTests/GetAlbumsFixture.cs @@ -0,0 +1,38 @@ +using Moq; +using NUnit.Framework; +using NzbDrone.Core.Parser; +using NzbDrone.Core.Test.Framework; +using NzbDrone.Core.Music; +using FizzWare.NBuilder; +using NzbDrone.Core.IndexerSearch.Definitions; +using NzbDrone.Core.Parser.Model; +using FluentAssertions; +using System.Linq; +using System.Collections.Generic; + +namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests +{ + [TestFixture] + public class GetAlbumsFixture : CoreTest + { + [Test] + public void should_not_fail_if_search_criteria_contains_multiple_albums_with_the_same_name() + { + var artist = Builder.CreateNew().Build(); + var albums = Builder.CreateListOfSize(2).All().With(x => x.Title = "IdenticalTitle").Build().ToList(); + var criteria = new AlbumSearchCriteria { + Artist = artist, + Albums = albums + }; + + var parsed = new ParsedAlbumInfo { + AlbumTitle = "IdenticalTitle" + }; + + Subject.GetAlbums(parsed, artist, criteria).Should().BeEquivalentTo(new List()); + + Mocker.GetMock() + .Verify(s => s.FindByTitle(artist.ArtistMetadataId, "IdenticalTitle"), Times.Once()); + } + } +} diff --git a/src/NzbDrone.Core/Parser/ParsingService.cs b/src/NzbDrone.Core/Parser/ParsingService.cs index 340bbd7a0..f8c658bbf 100644 --- a/src/NzbDrone.Core/Parser/ParsingService.cs +++ b/src/NzbDrone.Core/Parser/ParsingService.cs @@ -149,7 +149,7 @@ namespace NzbDrone.Core.Parser if (searchCriteria != null) { - albumInfo = searchCriteria.Albums.SingleOrDefault(e => e.Title == albumTitle); + albumInfo = searchCriteria.Albums.ExclusiveOrDefault(e => e.Title == albumTitle); } if (albumInfo == null)