mirror of https://github.com/Radarr/Radarr
Rename NzbSearchService to ReleaseSearchService
(cherry picked from commit eb4a9f624e716fa932da7f7e5ff975e2d9f02655)
This commit is contained in:
parent
329d141128
commit
823fe2261e
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,21 +16,21 @@ namespace NzbDrone.Core.IndexerSearch
|
|||
{
|
||||
private readonly IMovieService _movieService;
|
||||
private readonly IMovieCutoffService _movieCutoffService;
|
||||
private readonly ISearchForNzb _nzbSearchService;
|
||||
private readonly ISearchForReleases _releaseSearchService;
|
||||
private readonly IProcessDownloadDecisions _processDownloadDecisions;
|
||||
private readonly IQueueService _queueService;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public MovieSearchService(IMovieService movieService,
|
||||
IMovieCutoffService movieCutoffService,
|
||||
ISearchForNzb nzbSearchService,
|
||||
ISearchForReleases releaseSearchService,
|
||||
IProcessDownloadDecisions processDownloadDecisions,
|
||||
IQueueService queueService,
|
||||
Logger logger)
|
||||
{
|
||||
_movieService = movieService;
|
||||
_movieCutoffService = movieCutoffService;
|
||||
_nzbSearchService = nzbSearchService;
|
||||
_releaseSearchService = releaseSearchService;
|
||||
_processDownloadDecisions = processDownloadDecisions;
|
||||
_queueService = queueService;
|
||||
_logger = logger;
|
||||
|
@ -49,7 +49,7 @@ namespace NzbDrone.Core.IndexerSearch
|
|||
continue;
|
||||
}
|
||||
|
||||
var decisions = _nzbSearchService.MovieSearch(movieId, false, false);
|
||||
var decisions = _releaseSearchService.MovieSearch(movieId, false, false);
|
||||
downloadedCount += _processDownloadDecisions.ProcessDecisions(decisions).Grabbed.Count;
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,7 @@ namespace NzbDrone.Core.IndexerSearch
|
|||
|
||||
try
|
||||
{
|
||||
decisions = _nzbSearchService.MovieSearch(movieId.Key, userInvokedSearch, false);
|
||||
decisions = _releaseSearchService.MovieSearch(movieId.Key, userInvokedSearch, false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
|
@ -16,13 +16,13 @@ using NzbDrone.Core.Profiles;
|
|||
|
||||
namespace NzbDrone.Core.IndexerSearch
|
||||
{
|
||||
public interface ISearchForNzb
|
||||
public interface ISearchForReleases
|
||||
{
|
||||
List<DownloadDecision> MovieSearch(int movieId, 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 IMakeDownloadDecision _makeDownloadDecision;
|
||||
|
@ -31,7 +31,7 @@ namespace NzbDrone.Core.IndexerSearch
|
|||
private readonly IProfileService _profileService;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public NzbSearchService(IIndexerFactory indexerFactory,
|
||||
public ReleaseSearchService(IIndexerFactory indexerFactory,
|
||||
IMakeDownloadDecision makeDownloadDecision,
|
||||
IMovieService movieService,
|
||||
IMovieTranslationService movieTranslationService,
|
|
@ -22,7 +22,7 @@ namespace Radarr.Api.V3.Indexers
|
|||
public class ReleaseController : ReleaseControllerBase
|
||||
{
|
||||
private readonly IFetchAndParseRss _rssFetcherAndParser;
|
||||
private readonly ISearchForNzb _nzbSearchService;
|
||||
private readonly ISearchForReleases _releaseSearchService;
|
||||
private readonly IMakeDownloadDecision _downloadDecisionMaker;
|
||||
private readonly IPrioritizeDownloadDecision _prioritizeDownloadDecision;
|
||||
private readonly IDownloadService _downloadService;
|
||||
|
@ -32,7 +32,7 @@ namespace Radarr.Api.V3.Indexers
|
|||
private readonly ICached<RemoteMovie> _remoteMovieCache;
|
||||
|
||||
public ReleaseController(IFetchAndParseRss rssFetcherAndParser,
|
||||
ISearchForNzb nzbSearchService,
|
||||
ISearchForReleases releaseSearchService,
|
||||
IMakeDownloadDecision downloadDecisionMaker,
|
||||
IPrioritizeDownloadDecision prioritizeDownloadDecision,
|
||||
IDownloadService downloadService,
|
||||
|
@ -43,7 +43,7 @@ namespace Radarr.Api.V3.Indexers
|
|||
: base(qualityProfileService)
|
||||
{
|
||||
_rssFetcherAndParser = rssFetcherAndParser;
|
||||
_nzbSearchService = nzbSearchService;
|
||||
_releaseSearchService = releaseSearchService;
|
||||
_downloadDecisionMaker = downloadDecisionMaker;
|
||||
_prioritizeDownloadDecision = prioritizeDownloadDecision;
|
||||
_downloadService = downloadService;
|
||||
|
@ -110,7 +110,7 @@ namespace Radarr.Api.V3.Indexers
|
|||
{
|
||||
try
|
||||
{
|
||||
var decisions = _nzbSearchService.MovieSearch(movieId, true, true);
|
||||
var decisions = _releaseSearchService.MovieSearch(movieId, true, true);
|
||||
var prioritizedDecisions = _prioritizeDownloadDecision.PrioritizeDecisionsForMovies(decisions);
|
||||
|
||||
return MapDecisions(prioritizedDecisions);
|
||||
|
|
Loading…
Reference in New Issue