Rename NzbSearchService to ReleaseSearchService

(cherry picked from commit eb4a9f624e716fa932da7f7e5ff975e2d9f02655)
This commit is contained in:
Mark McDowall 2021-10-05 12:00:15 -07:00 committed by Robin Dadswell
parent 329d141128
commit 823fe2261e
4 changed files with 173 additions and 12 deletions

View File

@ -0,0 +1,161 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.IndexerSearch;
using NzbDrone.Core.IndexerSearch.Definitions;
using NzbDrone.Core.Movies;
using NzbDrone.Core.Movies.Translations;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.IndexerSearchTests
{
public class ReleaseSearchServiceFixture : CoreTest<ReleaseSearchService>
{
private Mock<IIndexer> _mockIndexer;
private Movie _movie;
[SetUp]
public void SetUp()
{
_mockIndexer = Mocker.GetMock<IIndexer>();
_mockIndexer.SetupGet(s => s.Definition).Returns(new IndexerDefinition { Id = 1 });
_mockIndexer.SetupGet(s => s.SupportsSearch).Returns(true);
Mocker.GetMock<IIndexerFactory>()
.Setup(s => s.AutomaticSearchEnabled(true))
.Returns(new List<IIndexer> { _mockIndexer.Object });
Mocker.GetMock<IMakeDownloadDecision>()
.Setup(s => s.GetSearchDecision(It.IsAny<List<Parser.Model.ReleaseInfo>>(), It.IsAny<SearchCriteriaBase>()))
.Returns(new List<DownloadDecision>());
_movie = Builder<Movie>.CreateNew()
.With(v => v.Monitored = true)
.Build();
Mocker.GetMock<IMovieService>()
.Setup(v => v.GetMovie(_movie.Id))
.Returns(_movie);
Mocker.GetMock<IMovieTranslationService>()
.Setup(s => s.GetAllTranslationsForMovie(It.IsAny<int>()))
.Returns(new List<MovieTranslation>());
}
private List<SearchCriteriaBase> WatchForSearchCriteria()
{
var result = new List<SearchCriteriaBase>();
_mockIndexer.Setup(v => v.Fetch(It.IsAny<MovieSearchCriteria>()))
.Callback<MovieSearchCriteria>(s => result.Add(s))
.Returns(new List<Parser.Model.ReleaseInfo>());
return result;
}
[Test]
public void Tags_IndexerTags_MovieNoTags_IndexerNotIncluded()
{
_mockIndexer.SetupGet(s => s.Definition).Returns(new IndexerDefinition
{
Id = 1,
Tags = new HashSet<int> { 3 }
});
var allCriteria = WatchForSearchCriteria();
Subject.MovieSearch(_movie, true, false);
var criteria = allCriteria.OfType<MovieSearchCriteria>().ToList();
criteria.Count.Should().Be(0);
}
[Test]
public void Tags_IndexerNoTags_MovieTags_IndexerIncluded()
{
_mockIndexer.SetupGet(s => s.Definition).Returns(new IndexerDefinition
{
Id = 1
});
_movie = Builder<Movie>.CreateNew()
.With(v => v.Monitored = true)
.With(v => v.Tags = new HashSet<int> { 3 })
.Build();
Mocker.GetMock<IMovieService>()
.Setup(v => v.GetMovie(_movie.Id))
.Returns(_movie);
var allCriteria = WatchForSearchCriteria();
Subject.MovieSearch(_movie, true, false);
var criteria = allCriteria.OfType<MovieSearchCriteria>().ToList();
criteria.Count.Should().Be(1);
}
[Test]
public void Tags_IndexerAndMovieTagsMatch_IndexerIncluded()
{
_mockIndexer.SetupGet(s => s.Definition).Returns(new IndexerDefinition
{
Id = 1,
Tags = new HashSet<int> { 1, 2, 3 }
});
_movie = Builder<Movie>.CreateNew()
.With(v => v.Monitored = true)
.With(v => v.Tags = new HashSet<int> { 3, 4, 5 })
.Build();
Mocker.GetMock<IMovieService>()
.Setup(v => v.GetMovie(_movie.Id))
.Returns(_movie);
var allCriteria = WatchForSearchCriteria();
Subject.MovieSearch(_movie, true, false);
var criteria = allCriteria.OfType<MovieSearchCriteria>().ToList();
criteria.Count.Should().Be(1);
}
[Test]
public void Tags_IndexerAndMovieTagsMismatch_IndexerNotIncluded()
{
_mockIndexer.SetupGet(s => s.Definition).Returns(new IndexerDefinition
{
Id = 1,
Tags = new HashSet<int> { 1, 2, 3 }
});
_movie = Builder<Movie>.CreateNew()
.With(v => v.Monitored = true)
.With(v => v.Tags = new HashSet<int> { 4, 5, 6 })
.Build();
Mocker.GetMock<IMovieService>()
.Setup(v => v.GetMovie(_movie.Id))
.Returns(_movie);
var allCriteria = WatchForSearchCriteria();
Subject.MovieSearch(_movie, true, false);
var criteria = allCriteria.OfType<MovieSearchCriteria>().ToList();
criteria.Count.Should().Be(0);
}
}
}

View File

@ -16,21 +16,21 @@ namespace NzbDrone.Core.IndexerSearch
{ {
private readonly IMovieService _movieService; private readonly IMovieService _movieService;
private readonly IMovieCutoffService _movieCutoffService; private readonly IMovieCutoffService _movieCutoffService;
private readonly ISearchForNzb _nzbSearchService; private readonly ISearchForReleases _releaseSearchService;
private readonly IProcessDownloadDecisions _processDownloadDecisions; private readonly IProcessDownloadDecisions _processDownloadDecisions;
private readonly IQueueService _queueService; private readonly IQueueService _queueService;
private readonly Logger _logger; private readonly Logger _logger;
public MovieSearchService(IMovieService movieService, public MovieSearchService(IMovieService movieService,
IMovieCutoffService movieCutoffService, IMovieCutoffService movieCutoffService,
ISearchForNzb nzbSearchService, ISearchForReleases releaseSearchService,
IProcessDownloadDecisions processDownloadDecisions, IProcessDownloadDecisions processDownloadDecisions,
IQueueService queueService, IQueueService queueService,
Logger logger) Logger logger)
{ {
_movieService = movieService; _movieService = movieService;
_movieCutoffService = movieCutoffService; _movieCutoffService = movieCutoffService;
_nzbSearchService = nzbSearchService; _releaseSearchService = releaseSearchService;
_processDownloadDecisions = processDownloadDecisions; _processDownloadDecisions = processDownloadDecisions;
_queueService = queueService; _queueService = queueService;
_logger = logger; _logger = logger;
@ -49,7 +49,7 @@ namespace NzbDrone.Core.IndexerSearch
continue; continue;
} }
var decisions = _nzbSearchService.MovieSearch(movieId, false, false); var decisions = _releaseSearchService.MovieSearch(movieId, false, false);
downloadedCount += _processDownloadDecisions.ProcessDecisions(decisions).Grabbed.Count; downloadedCount += _processDownloadDecisions.ProcessDecisions(decisions).Grabbed.Count;
} }
@ -106,7 +106,7 @@ namespace NzbDrone.Core.IndexerSearch
try try
{ {
decisions = _nzbSearchService.MovieSearch(movieId.Key, userInvokedSearch, false); decisions = _releaseSearchService.MovieSearch(movieId.Key, userInvokedSearch, false);
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -16,13 +16,13 @@ using NzbDrone.Core.Profiles;
namespace NzbDrone.Core.IndexerSearch namespace NzbDrone.Core.IndexerSearch
{ {
public interface ISearchForNzb public interface ISearchForReleases
{ {
List<DownloadDecision> MovieSearch(int movieId, bool userInvokedSearch, bool interactiveSearch); List<DownloadDecision> MovieSearch(int movieId, bool userInvokedSearch, bool interactiveSearch);
List<DownloadDecision> MovieSearch(Movie movie, bool userInvokedSearch, bool interactiveSearch); List<DownloadDecision> MovieSearch(Movie movie, bool userInvokedSearch, bool interactiveSearch);
} }
public class NzbSearchService : ISearchForNzb public class ReleaseSearchService : ISearchForReleases
{ {
private readonly IIndexerFactory _indexerFactory; private readonly IIndexerFactory _indexerFactory;
private readonly IMakeDownloadDecision _makeDownloadDecision; private readonly IMakeDownloadDecision _makeDownloadDecision;
@ -31,7 +31,7 @@ namespace NzbDrone.Core.IndexerSearch
private readonly IProfileService _profileService; private readonly IProfileService _profileService;
private readonly Logger _logger; private readonly Logger _logger;
public NzbSearchService(IIndexerFactory indexerFactory, public ReleaseSearchService(IIndexerFactory indexerFactory,
IMakeDownloadDecision makeDownloadDecision, IMakeDownloadDecision makeDownloadDecision,
IMovieService movieService, IMovieService movieService,
IMovieTranslationService movieTranslationService, IMovieTranslationService movieTranslationService,

View File

@ -22,7 +22,7 @@ namespace Radarr.Api.V3.Indexers
public class ReleaseController : ReleaseControllerBase public class ReleaseController : ReleaseControllerBase
{ {
private readonly IFetchAndParseRss _rssFetcherAndParser; private readonly IFetchAndParseRss _rssFetcherAndParser;
private readonly ISearchForNzb _nzbSearchService; private readonly ISearchForReleases _releaseSearchService;
private readonly IMakeDownloadDecision _downloadDecisionMaker; private readonly IMakeDownloadDecision _downloadDecisionMaker;
private readonly IPrioritizeDownloadDecision _prioritizeDownloadDecision; private readonly IPrioritizeDownloadDecision _prioritizeDownloadDecision;
private readonly IDownloadService _downloadService; private readonly IDownloadService _downloadService;
@ -32,7 +32,7 @@ namespace Radarr.Api.V3.Indexers
private readonly ICached<RemoteMovie> _remoteMovieCache; private readonly ICached<RemoteMovie> _remoteMovieCache;
public ReleaseController(IFetchAndParseRss rssFetcherAndParser, public ReleaseController(IFetchAndParseRss rssFetcherAndParser,
ISearchForNzb nzbSearchService, ISearchForReleases releaseSearchService,
IMakeDownloadDecision downloadDecisionMaker, IMakeDownloadDecision downloadDecisionMaker,
IPrioritizeDownloadDecision prioritizeDownloadDecision, IPrioritizeDownloadDecision prioritizeDownloadDecision,
IDownloadService downloadService, IDownloadService downloadService,
@ -43,7 +43,7 @@ namespace Radarr.Api.V3.Indexers
: base(qualityProfileService) : base(qualityProfileService)
{ {
_rssFetcherAndParser = rssFetcherAndParser; _rssFetcherAndParser = rssFetcherAndParser;
_nzbSearchService = nzbSearchService; _releaseSearchService = releaseSearchService;
_downloadDecisionMaker = downloadDecisionMaker; _downloadDecisionMaker = downloadDecisionMaker;
_prioritizeDownloadDecision = prioritizeDownloadDecision; _prioritizeDownloadDecision = prioritizeDownloadDecision;
_downloadService = downloadService; _downloadService = downloadService;
@ -110,7 +110,7 @@ namespace Radarr.Api.V3.Indexers
{ {
try try
{ {
var decisions = _nzbSearchService.MovieSearch(movieId, true, true); var decisions = _releaseSearchService.MovieSearch(movieId, true, true);
var prioritizedDecisions = _prioritizeDownloadDecision.PrioritizeDecisionsForMovies(decisions); var prioritizedDecisions = _prioritizeDownloadDecision.PrioritizeDecisionsForMovies(decisions);
return MapDecisions(prioritizedDecisions); return MapDecisions(prioritizedDecisions);