Fixed: Should ignore indexer provided tvrageid when scene naming exception exists.

This commit is contained in:
Taloth Saldono 2015-08-03 19:19:59 +02:00
parent c56cf8860e
commit a84f39bb48
5 changed files with 67 additions and 34 deletions

View File

@ -108,7 +108,7 @@ namespace NzbDrone.Core.Test.DataAugmentation.Scene
[Test]
public void should_refresh_cache_if_cache_is_empty_when_looking_for_tvdb_id()
{
Subject.FindTvDbId("title");
Subject.FindTvdbId("title");
Mocker.GetMock<ISceneMappingRepository>()
.Verify(v => v.All(), Times.Once());
@ -129,7 +129,7 @@ namespace NzbDrone.Core.Test.DataAugmentation.Scene
Mocker.GetMock<ISceneMappingRepository>()
.Verify(v => v.All(), Times.Once());
Subject.FindTvDbId("title");
Subject.FindTvdbId("title");
Mocker.GetMock<ISceneMappingRepository>()
.Verify(v => v.All(), Times.Once());
@ -195,7 +195,7 @@ namespace NzbDrone.Core.Test.DataAugmentation.Scene
Mocker.GetMock<ISceneMappingRepository>().Setup(c => c.All()).Returns(mappings);
var tvdbId = Subject.FindTvDbId(parseTitle);
var tvdbId = Subject.FindTvdbId(parseTitle);
var seasonNumber = Subject.GetSeasonNumber(parseTitle);
tvdbId.Should().Be(100);
@ -218,7 +218,7 @@ namespace NzbDrone.Core.Test.DataAugmentation.Scene
foreach (var sceneMapping in _fakeMappings)
{
Subject.GetSceneNames(sceneMapping.TvdbId, _fakeMappings.Select(m => m.SeasonNumber)).Should().Contain(sceneMapping.SearchTerm);
Subject.FindTvDbId(sceneMapping.ParseTerm).Should().Be(sceneMapping.TvdbId);
Subject.FindTvdbId(sceneMapping.ParseTerm).Should().Be(sceneMapping.TvdbId);
}
}
}

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.DataAugmentation.Scene;
@ -92,6 +93,23 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests
.Verify(v => v.FindByTvRageId(It.IsAny<Int32>()), Times.Once());
}
[Test]
public void should_not_use_tvrageid_when_scene_naming_exception_exists()
{
GivenMatchByTvRageId();
Mocker.GetMock<ISceneMappingService>()
.Setup(v => v.FindTvdbId(It.IsAny<string>()))
.Returns(10);
var result = Subject.Map(_parsedEpisodeInfo, _series.TvRageId);
Mocker.GetMock<ISeriesService>()
.Verify(v => v.FindByTvRageId(It.IsAny<Int32>()), Times.Never());
result.Series.Should().BeNull();
}
[Test]
public void should_use_search_criteria_series_title()
{
@ -115,7 +133,7 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests
}
[Test]
public void should_FindByTvRageId_when_search_criteria_and_FIndByTitle_matching_fails()
public void should_FindByTvRageId_when_search_criteria_and_FindByTitle_matching_fails()
{
GivenParseResultSeriesDoesntMatchSearchCriteria();
@ -129,7 +147,7 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests
public void should_use_tvdbid_matching_when_alias_is_found()
{
Mocker.GetMock<ISceneMappingService>()
.Setup(s => s.FindTvDbId(It.IsAny<String>()))
.Setup(s => s.FindTvdbId(It.IsAny<String>()))
.Returns(_series.TvdbId);
Subject.Map(_parsedEpisodeInfo, _series.TvRageId, _singleEpisodeSearchCriteria);

View File

@ -15,7 +15,7 @@ namespace NzbDrone.Core.DataAugmentation.Scene
public interface ISceneMappingService
{
List<String> GetSceneNames(int tvdbId, IEnumerable<Int32> seasonNumbers);
Nullable<int> FindTvDbId(string title);
Nullable<int> FindTvdbId(string title);
List<SceneMapping> FindByTvdbId(int tvdbId);
Nullable<Int32> GetSeasonNumber(string title);
}
@ -61,9 +61,9 @@ namespace NzbDrone.Core.DataAugmentation.Scene
.Select(m => m.SearchTerm).Distinct().ToList());
}
public Nullable<Int32> FindTvDbId(string title)
public Nullable<Int32> FindTvdbId(string title)
{
var mapping = FindTvdbId(title);
var mapping = FindMapping(title);
if (mapping == null)
return null;
@ -90,7 +90,7 @@ namespace NzbDrone.Core.DataAugmentation.Scene
public Nullable<Int32> GetSeasonNumber(string title)
{
var mapping = FindTvdbId(title);
var mapping = FindMapping(title);
if (mapping == null)
return null;
@ -147,7 +147,7 @@ namespace NzbDrone.Core.DataAugmentation.Scene
_eventAggregator.PublishEvent(new SceneMappingsUpdatedEvent());
}
private SceneMapping FindTvdbId(string title)
private SceneMapping FindMapping(string title)
{
if (_getTvdbIdCache.Count == 0)
{

View File

@ -116,8 +116,7 @@ namespace NzbDrone.Core.Parser
ParsedEpisodeInfo = parsedEpisodeInfo,
};
var series = searchCriteria == null ? GetSeries(parsedEpisodeInfo, tvRageId) :
GetSeries(parsedEpisodeInfo, tvRageId, searchCriteria);
var series = GetSeries(parsedEpisodeInfo, tvRageId, searchCriteria);
if (series == null)
{
@ -291,7 +290,7 @@ namespace NzbDrone.Core.Parser
{
if (searchCriteria != null)
{
var tvdbId = _sceneMappingService.FindTvDbId(title);
var tvdbId = _sceneMappingService.FindTvdbId(title);
if (tvdbId.HasValue)
{
if (searchCriteria.Series.TvdbId == tvdbId)
@ -354,33 +353,43 @@ namespace NzbDrone.Core.Parser
private Series GetSeries(ParsedEpisodeInfo parsedEpisodeInfo, int tvRageId, SearchCriteriaBase searchCriteria)
{
var tvdbId = _sceneMappingService.FindTvDbId(parsedEpisodeInfo.SeriesTitle);
Series series = null;
var tvdbId = _sceneMappingService.FindTvdbId(parsedEpisodeInfo.SeriesTitle);
if (tvdbId.HasValue)
{
if (searchCriteria.Series.TvdbId == tvdbId)
if (searchCriteria != null && searchCriteria.Series.TvdbId == tvdbId)
{
return searchCriteria.Series;
}
series = _seriesService.FindByTvdbId(tvdbId.Value);
if (series == null)
{
_logger.Debug("No matching series {0}", parsedEpisodeInfo.SeriesTitle);
return null;
}
return series;
}
if (searchCriteria != null)
{
if (searchCriteria.Series.CleanTitle == parsedEpisodeInfo.SeriesTitle.CleanSeriesTitle())
{
return searchCriteria.Series;
}
if (tvRageId > 0 && tvRageId == searchCriteria.Series.TvRageId)
{
//TODO: If series is found by TvRageId, we should report it as a scene naming exception, since it will fail to import
return searchCriteria.Series;
}
}
if (parsedEpisodeInfo.SeriesTitle.CleanSeriesTitle() == searchCriteria.Series.CleanTitle)
{
return searchCriteria.Series;
}
if (tvRageId > 0 && tvRageId == searchCriteria.Series.TvRageId)
{
//TODO: If series is found by TvRageId, we should report it as a scene naming exception, since it will fail to import
return searchCriteria.Series;
}
return GetSeries(parsedEpisodeInfo, tvRageId);
}
private Series GetSeries(ParsedEpisodeInfo parsedEpisodeInfo, int tvRageId)
{
var series = _seriesService.FindByTitle(parsedEpisodeInfo.SeriesTitle);
series = _seriesService.FindByTitle(parsedEpisodeInfo.SeriesTitle);
if (series == null && tvRageId > 0)
{

View File

@ -18,6 +18,7 @@ namespace NzbDrone.Core.Tv
Series GetSeries(int seriesId);
List<Series> GetSeries(IEnumerable<int> seriesIds);
Series AddSeries(Series newSeries);
Series FindByTvdbId(int tvdbId);
Series FindByTvRageId(int tvRageId);
Series FindByTitle(string title);
Series FindByTitle(string title, int year);
@ -87,6 +88,11 @@ namespace NzbDrone.Core.Tv
return newSeries;
}
public Series FindByTvdbId(int tvRageId)
{
return _seriesRepository.FindByTvdbId(tvRageId);
}
public Series FindByTvRageId(int tvRageId)
{
return _seriesRepository.FindByTvRageId(tvRageId);
@ -94,7 +100,7 @@ namespace NzbDrone.Core.Tv
public Series FindByTitle(string title)
{
var tvdbId = _sceneMappingService.FindTvDbId(title);
var tvdbId = _sceneMappingService.FindTvdbId(title);
if (tvdbId.HasValue)
{