diff --git a/src/NzbDrone.Core.Test/IndexerTests/GazelleTests/GazelleRequestGeneratorFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/GazelleTests/GazelleRequestGeneratorFixture.cs new file mode 100644 index 000000000..947d6aebd --- /dev/null +++ b/src/NzbDrone.Core.Test/IndexerTests/GazelleTests/GazelleRequestGeneratorFixture.cs @@ -0,0 +1,93 @@ +using System.Collections.Generic; +using System.Linq; +using FluentAssertions; +using Moq; +using NLog; +using NUnit.Framework; +using NzbDrone.Common.Cache; +using NzbDrone.Common.Http; +using NzbDrone.Core.Indexers.Gazelle; +using NzbDrone.Core.IndexerSearch.Definitions; +using NzbDrone.Core.Test.Framework; + +namespace NzbDrone.Core.Test.IndexerTests.NewznabTests +{ + public class GazelleRequestGeneratorFixture : CoreTest + { + private AlbumSearchCriteria _singleAlbumSearchCriteria; + private AlbumSearchCriteria _variousArtistSearchCriteria; + + [SetUp] + public void SetUp() + { + Subject.Settings = new GazelleSettings() + { + BaseUrl = "http://127.0.0.1:1234/", + Username = "someuser", + Password = "somepass" + }; + + _singleAlbumSearchCriteria = new AlbumSearchCriteria + { + Artist = new Music.Artist { Name = "Alien Ant Farm" }, + AlbumTitle = "TruANT" + }; + + _variousArtistSearchCriteria = new AlbumSearchCriteria + { + Artist = new Music.Artist { Name = "Various Artists" }, + AlbumTitle = "TruANT" + }; + + Mocker.GetMock() + .Setup(v => v.Execute(It.IsAny())) + .Returns(r => new HttpResponse(r, new HttpHeader(), "{ \"status\": \"success\", \"response\": { \"authkey\": \"key\", \"passkey\": \"key\" } }")); + + Mocker.GetMock>>() + .Setup(v => v.Find(It.IsAny())) + .Returns(r => new Dictionary { { "some", "cookie" } }); + + Subject.AuthCookieCache = Mocker.Resolve>>(); + + Subject.HttpClient = Mocker.Resolve(); + + Subject.Logger = Mocker.Resolve(); + } + + [Test] + public void should_use_all_categories_for_feed() + { + var results = Subject.GetRecentRequests(); + + results.GetAllTiers().Should().HaveCount(1); + + var page = results.GetAllTiers().First().First(); + + page.Url.Query.Should().Be("action=browse&searchstr="); + } + + [Test] + public void should_search_by_artist_and_album_if_supported() + { + var results = Subject.GetSearchRequests(_singleAlbumSearchCriteria); + results.GetTier(0).Should().HaveCount(1); + + var page = results.GetAllTiers().First().First(); + + page.Url.Query.Should().Contain("artistname=Alien+Ant+Farm"); + page.Url.Query.Should().Contain("groupname=TruANT"); + } + + [Test] + public void should_only_search_by_album_if_various_artist() + { + var results = Subject.GetSearchRequests(_variousArtistSearchCriteria); + results.GetTier(0).Should().HaveCount(1); + + var page = results.GetAllTiers().First().First(); + + page.Url.Query.Should().NotContain("artistname="); + page.Url.Query.Should().Contain("groupname=TruANT"); + } + } +} diff --git a/src/NzbDrone.Core/Indexers/Gazelle/GazelleRequestGenerator.cs b/src/NzbDrone.Core/Indexers/Gazelle/GazelleRequestGenerator.cs index a43630fa4..750ed5914 100644 --- a/src/NzbDrone.Core/Indexers/Gazelle/GazelleRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/Gazelle/GazelleRequestGenerator.cs @@ -30,7 +30,16 @@ namespace NzbDrone.Core.Indexers.Gazelle public IndexerPageableRequestChain GetSearchRequests(AlbumSearchCriteria searchCriteria) { var pageableRequests = new IndexerPageableRequestChain(); - pageableRequests.Add(GetRequest(string.Format("&artistname={0}&groupname={1}", searchCriteria.CleanArtistQuery, searchCriteria.CleanAlbumQuery))); + + if (searchCriteria.CleanArtistQuery == "VA") + { + pageableRequests.Add(GetRequest(string.Format("&groupname={0}", searchCriteria.CleanAlbumQuery))); + } + else + { + pageableRequests.Add(GetRequest(string.Format("&artistname={0}&groupname={1}", searchCriteria.CleanArtistQuery, searchCriteria.CleanAlbumQuery))); + } + return pageableRequests; }