mirror of https://github.com/Sonarr/Sonarr
Fixed: Removing pending releases
This commit is contained in:
parent
fa0401fa89
commit
fd3dda2b16
|
@ -1,31 +1,47 @@
|
||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using FizzWare.NBuilder;
|
||||||
using Moq;
|
using Moq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Common.Crypto;
|
||||||
using NzbDrone.Core.Download.Pending;
|
using NzbDrone.Core.Download.Pending;
|
||||||
|
using NzbDrone.Core.Parser;
|
||||||
using NzbDrone.Core.Parser.Model;
|
using NzbDrone.Core.Parser.Model;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
using NzbDrone.Core.Tv;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.Download.Pending.PendingReleaseServiceTests
|
namespace NzbDrone.Core.Test.Download.Pending.PendingReleaseServiceTests
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class RemovePendingFixture : CoreTest<PendingReleaseService>
|
public class RemovePendingFixture : CoreTest<PendingReleaseService>
|
||||||
{
|
{
|
||||||
|
|
||||||
private List<PendingRelease> _pending;
|
private List<PendingRelease> _pending;
|
||||||
|
private Episode _episode;
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void Setup()
|
public void Setup()
|
||||||
{
|
{
|
||||||
_pending = new List<PendingRelease>();
|
_pending = new List<PendingRelease>();
|
||||||
|
|
||||||
|
_episode = Builder<Episode>.CreateNew()
|
||||||
|
.Build();
|
||||||
|
|
||||||
Mocker.GetMock<IPendingReleaseRepository>()
|
Mocker.GetMock<IPendingReleaseRepository>()
|
||||||
.Setup(s => s.AllBySeriesId(It.IsAny<int>()))
|
.Setup(s => s.AllBySeriesId(It.IsAny<int>()))
|
||||||
.Returns(_pending);
|
.Returns(_pending);
|
||||||
|
|
||||||
Mocker.GetMock<IPendingReleaseRepository>()
|
Mocker.GetMock<IPendingReleaseRepository>()
|
||||||
.Setup(s => s.Get(It.IsAny<int>()))
|
.Setup(s => s.All())
|
||||||
.Returns<int>(r => _pending.Single(c => c.Id == r));
|
.Returns( _pending);
|
||||||
|
|
||||||
|
Mocker.GetMock<ISeriesService>()
|
||||||
|
.Setup(s => s.GetSeries(It.IsAny<int>()))
|
||||||
|
.Returns(new Series());
|
||||||
|
|
||||||
|
Mocker.GetMock<IParsingService>()
|
||||||
|
.Setup(s => s.GetEpisodes(It.IsAny<ParsedEpisodeInfo>(), It.IsAny<Series>(), It.IsAny<bool>(), null))
|
||||||
|
.Returns(new List<Episode>{ _episode });
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddPending(int id, int seasonNumber, int[] episodes)
|
private void AddPending(int id, int seasonNumber, int[] episodes)
|
||||||
|
@ -42,12 +58,13 @@ namespace NzbDrone.Core.Test.Download.Pending.PendingReleaseServiceTests
|
||||||
{
|
{
|
||||||
AddPending(id: 1, seasonNumber: 2, episodes: new[] { 3 });
|
AddPending(id: 1, seasonNumber: 2, episodes: new[] { 3 });
|
||||||
|
|
||||||
Subject.RemovePendingQueueItems(1);
|
var queueId = HashConverter.GetHashInt31(String.Format("pending-{0}-ep{1}", 1, _episode.Id));
|
||||||
|
|
||||||
|
Subject.RemovePendingQueueItems(queueId);
|
||||||
|
|
||||||
AssertRemoved(1);
|
AssertRemoved(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void should_remove_multiple_releases_release()
|
public void should_remove_multiple_releases_release()
|
||||||
{
|
{
|
||||||
|
@ -56,7 +73,9 @@ namespace NzbDrone.Core.Test.Download.Pending.PendingReleaseServiceTests
|
||||||
AddPending(id: 3, seasonNumber: 2, episodes: new[] { 3 });
|
AddPending(id: 3, seasonNumber: 2, episodes: new[] { 3 });
|
||||||
AddPending(id: 4, seasonNumber: 2, episodes: new[] { 3 });
|
AddPending(id: 4, seasonNumber: 2, episodes: new[] { 3 });
|
||||||
|
|
||||||
Subject.RemovePendingQueueItems(3);
|
var queueId = HashConverter.GetHashInt31(String.Format("pending-{0}-ep{1}", 3, _episode.Id));
|
||||||
|
|
||||||
|
Subject.RemovePendingQueueItems(queueId);
|
||||||
|
|
||||||
AssertRemoved(3, 4);
|
AssertRemoved(3, 4);
|
||||||
}
|
}
|
||||||
|
@ -69,7 +88,9 @@ namespace NzbDrone.Core.Test.Download.Pending.PendingReleaseServiceTests
|
||||||
AddPending(id: 3, seasonNumber: 3, episodes: new[] { 1 });
|
AddPending(id: 3, seasonNumber: 3, episodes: new[] { 1 });
|
||||||
AddPending(id: 4, seasonNumber: 3, episodes: new[] { 1 });
|
AddPending(id: 4, seasonNumber: 3, episodes: new[] { 1 });
|
||||||
|
|
||||||
Subject.RemovePendingQueueItems(1);
|
var queueId = HashConverter.GetHashInt31(String.Format("pending-{0}-ep{1}", 1, _episode.Id));
|
||||||
|
|
||||||
|
Subject.RemovePendingQueueItems(queueId);
|
||||||
|
|
||||||
AssertRemoved(1, 2);
|
AssertRemoved(1, 2);
|
||||||
}
|
}
|
||||||
|
@ -82,7 +103,9 @@ namespace NzbDrone.Core.Test.Download.Pending.PendingReleaseServiceTests
|
||||||
AddPending(id: 3, seasonNumber: 2, episodes: new[] { 2 });
|
AddPending(id: 3, seasonNumber: 2, episodes: new[] { 2 });
|
||||||
AddPending(id: 4, seasonNumber: 2, episodes: new[] { 3 });
|
AddPending(id: 4, seasonNumber: 2, episodes: new[] { 3 });
|
||||||
|
|
||||||
Subject.RemovePendingQueueItems(1);
|
var queueId = HashConverter.GetHashInt31(String.Format("pending-{0}-ep{1}", 1, _episode.Id));
|
||||||
|
|
||||||
|
Subject.RemovePendingQueueItems(queueId);
|
||||||
|
|
||||||
AssertRemoved(1, 2);
|
AssertRemoved(1, 2);
|
||||||
}
|
}
|
||||||
|
@ -93,7 +116,9 @@ namespace NzbDrone.Core.Test.Download.Pending.PendingReleaseServiceTests
|
||||||
AddPending(id: 1, seasonNumber: 2, episodes: new[] { 1 });
|
AddPending(id: 1, seasonNumber: 2, episodes: new[] { 1 });
|
||||||
AddPending(id: 2, seasonNumber: 2, episodes: new[] { 1, 2 });
|
AddPending(id: 2, seasonNumber: 2, episodes: new[] { 1, 2 });
|
||||||
|
|
||||||
Subject.RemovePendingQueueItems(1);
|
var queueId = HashConverter.GetHashInt31(String.Format("pending-{0}-ep{1}", 1, _episode.Id));
|
||||||
|
|
||||||
|
Subject.RemovePendingQueueItems(queueId);
|
||||||
|
|
||||||
AssertRemoved(1);
|
AssertRemoved(1);
|
||||||
}
|
}
|
||||||
|
@ -104,12 +129,13 @@ namespace NzbDrone.Core.Test.Download.Pending.PendingReleaseServiceTests
|
||||||
AddPending(id: 1, seasonNumber: 2, episodes: new[] { 1 });
|
AddPending(id: 1, seasonNumber: 2, episodes: new[] { 1 });
|
||||||
AddPending(id: 2, seasonNumber: 2, episodes: new[] { 1, 2 });
|
AddPending(id: 2, seasonNumber: 2, episodes: new[] { 1, 2 });
|
||||||
|
|
||||||
Subject.RemovePendingQueueItems(2);
|
var queueId = HashConverter.GetHashInt31(String.Format("pending-{0}-ep{1}", 2, _episode.Id));
|
||||||
|
|
||||||
|
Subject.RemovePendingQueueItems(queueId);
|
||||||
|
|
||||||
AssertRemoved(2);
|
AssertRemoved(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void AssertRemoved(params int[] ids)
|
private void AssertRemoved(params int[] ids)
|
||||||
{
|
{
|
||||||
Mocker.GetMock<IPendingReleaseRepository>().Verify(c => c.DeleteMany(It.Is<IEnumerable<int>>(s => s.SequenceEqual(ids))));
|
Mocker.GetMock<IPendingReleaseRepository>().Verify(c => c.DeleteMany(It.Is<IEnumerable<int>>(s => s.SequenceEqual(ids))));
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace NzbDrone.Core.Download.Pending
|
||||||
List<RemoteEpisode> GetPendingRemoteEpisodes(int seriesId);
|
List<RemoteEpisode> GetPendingRemoteEpisodes(int seriesId);
|
||||||
List<Queue.Queue> GetPendingQueue();
|
List<Queue.Queue> GetPendingQueue();
|
||||||
Queue.Queue FindPendingQueueItem(int queueId);
|
Queue.Queue FindPendingQueueItem(int queueId);
|
||||||
void RemovePendingQueueItems(int episodeId);
|
void RemovePendingQueueItems(int queueId);
|
||||||
RemoteEpisode OldestPendingRelease(int seriesId, IEnumerable<int> episodeIds);
|
RemoteEpisode OldestPendingRelease(int seriesId, IEnumerable<int> episodeIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,10 +154,9 @@ namespace NzbDrone.Core.Download.Pending
|
||||||
|
|
||||||
public void RemovePendingQueueItems(int queueId)
|
public void RemovePendingQueueItems(int queueId)
|
||||||
{
|
{
|
||||||
var targetItem = _repository.Get(queueId);
|
var targetItem = FindPendingRelease(queueId);
|
||||||
var seriesReleases = _repository.AllBySeriesId(targetItem.SeriesId);
|
var seriesReleases = _repository.AllBySeriesId(targetItem.SeriesId);
|
||||||
|
|
||||||
|
|
||||||
var releasesToRemove = seriesReleases.Where(
|
var releasesToRemove = seriesReleases.Where(
|
||||||
c => c.ParsedEpisodeInfo.SeasonNumber == targetItem.ParsedEpisodeInfo.SeasonNumber &&
|
c => c.ParsedEpisodeInfo.SeasonNumber == targetItem.ParsedEpisodeInfo.SeasonNumber &&
|
||||||
c.ParsedEpisodeInfo.EpisodeNumbers.SequenceEqual(targetItem.ParsedEpisodeInfo.EpisodeNumbers));
|
c.ParsedEpisodeInfo.EpisodeNumbers.SequenceEqual(targetItem.ParsedEpisodeInfo.EpisodeNumbers));
|
||||||
|
@ -167,10 +166,9 @@ namespace NzbDrone.Core.Download.Pending
|
||||||
|
|
||||||
public RemoteEpisode OldestPendingRelease(int seriesId, IEnumerable<int> episodeIds)
|
public RemoteEpisode OldestPendingRelease(int seriesId, IEnumerable<int> episodeIds)
|
||||||
{
|
{
|
||||||
return GetPendingRemoteEpisodes(seriesId)
|
return GetPendingRemoteEpisodes(seriesId).Where(r => r.Episodes.Select(e => e.Id).Intersect(episodeIds).Any())
|
||||||
.Where(r => r.Episodes.Select(e => e.Id).Intersect(episodeIds).Any())
|
.OrderByDescending(p => p.Release.AgeHours)
|
||||||
.OrderByDescending(p => p.Release.AgeHours)
|
.FirstOrDefault();
|
||||||
.FirstOrDefault();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<PendingRelease> GetPendingReleases()
|
private List<PendingRelease> GetPendingReleases()
|
||||||
|
@ -294,9 +292,9 @@ namespace NzbDrone.Core.Download.Pending
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int FindPendingReleaseId(int queueId)
|
private PendingRelease FindPendingRelease(int queueId)
|
||||||
{
|
{
|
||||||
return GetPendingReleases().First(p => p.RemoteEpisode.Episodes.Any(e => queueId == GetQueueId(p, e))).Id;
|
return GetPendingReleases().First(p => p.RemoteEpisode.Episodes.Any(e => queueId == GetQueueId(p, e)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private int GetQueueId(PendingRelease pendingRelease, Episode episode)
|
private int GetQueueId(PendingRelease pendingRelease, Episode episode)
|
||||||
|
|
Loading…
Reference in New Issue