Fixed: Refreshing series that have duplicate season information

pull/6/head
Mark McDowall 9 years ago
parent 54fda3d648
commit 319b4f13b7

@ -135,5 +135,50 @@ namespace NzbDrone.Core.Test.TvTests
ExceptionVerification.ExpectedWarns(1); ExceptionVerification.ExpectedWarns(1);
} }
[Test]
public void should_not_throw_if_duplicate_season_is_in_existing_info()
{
var newSeriesInfo = _series.JsonClone();
newSeriesInfo.Seasons.Add(Builder<Season>.CreateNew()
.With(s => s.SeasonNumber = 2)
.Build());
_series.Seasons.Add(Builder<Season>.CreateNew()
.With(s => s.SeasonNumber = 2)
.Build());
_series.Seasons.Add(Builder<Season>.CreateNew()
.With(s => s.SeasonNumber = 2)
.Build());
GivenNewSeriesInfo(newSeriesInfo);
Subject.Execute(new RefreshSeriesCommand(_series.Id));
Mocker.GetMock<ISeriesService>()
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.Seasons.Count == 2)));
}
[Test]
public void should_filter_duplicate_seasons()
{
var newSeriesInfo = _series.JsonClone();
newSeriesInfo.Seasons.Add(Builder<Season>.CreateNew()
.With(s => s.SeasonNumber = 2)
.Build());
newSeriesInfo.Seasons.Add(Builder<Season>.CreateNew()
.With(s => s.SeasonNumber = 2)
.Build());
GivenNewSeriesInfo(newSeriesInfo);
Subject.Execute(new RefreshSeriesCommand(_series.Id));
Mocker.GetMock<ISeriesService>()
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.Seasons.Count == 2)));
}
} }
} }

@ -116,9 +116,11 @@ namespace NzbDrone.Core.Tv
private List<Season> UpdateSeasons(Series series, Series seriesInfo) private List<Season> UpdateSeasons(Series series, Series seriesInfo)
{ {
foreach (var season in seriesInfo.Seasons) var seasons = seriesInfo.Seasons.DistinctBy(s => s.SeasonNumber).ToList();
foreach (var season in seasons)
{ {
var existingSeason = series.Seasons.SingleOrDefault(s => s.SeasonNumber == season.SeasonNumber); var existingSeason = series.Seasons.FirstOrDefault(s => s.SeasonNumber == season.SeasonNumber);
//Todo: Should this should use the previous season's monitored state? //Todo: Should this should use the previous season's monitored state?
if (existingSeason == null) if (existingSeason == null)
@ -139,7 +141,7 @@ namespace NzbDrone.Core.Tv
} }
} }
return seriesInfo.Seasons; return seasons;
} }
public void Execute(RefreshSeriesCommand message) public void Execute(RefreshSeriesCommand message)

Loading…
Cancel
Save