2014-12-19 00:26:42 +00:00
|
|
|
|
using System.Collections.Generic;
|
2013-10-22 07:31:36 +00:00
|
|
|
|
using FizzWare.NBuilder;
|
2014-12-19 00:26:42 +00:00
|
|
|
|
using FluentAssertions;
|
2013-10-22 07:31:36 +00:00
|
|
|
|
using Moq;
|
|
|
|
|
using NUnit.Framework;
|
2014-12-19 00:26:42 +00:00
|
|
|
|
using NzbDrone.Common.Disk;
|
2013-10-22 07:31:36 +00:00
|
|
|
|
using NzbDrone.Core.Download;
|
2014-12-19 00:26:42 +00:00
|
|
|
|
using NzbDrone.Core.Download.TrackedDownloads;
|
2013-10-22 07:31:36 +00:00
|
|
|
|
using NzbDrone.Core.History;
|
|
|
|
|
using NzbDrone.Core.Messaging.Events;
|
2014-09-13 23:13:00 +00:00
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
2013-10-22 07:31:36 +00:00
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
2014-09-13 23:13:00 +00:00
|
|
|
|
using NzbDrone.Core.Tv;
|
2014-07-21 20:56:13 +00:00
|
|
|
|
using NzbDrone.Test.Common;
|
2013-10-22 07:31:36 +00:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.Download
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2014-12-19 00:26:42 +00:00
|
|
|
|
public class FailedDownloadServiceFixture : CoreTest<FailedDownloadService>
|
2013-10-22 07:31:36 +00:00
|
|
|
|
{
|
2014-12-19 00:26:42 +00:00
|
|
|
|
private TrackedDownload _trackedDownload;
|
|
|
|
|
private List<History.History> _grabHistory;
|
2013-10-22 07:31:36 +00:00
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
2014-12-19 00:26:42 +00:00
|
|
|
|
var completed = Builder<DownloadClientItem>.CreateNew()
|
2014-09-13 23:13:00 +00:00
|
|
|
|
.With(h => h.Status = DownloadItemStatus.Completed)
|
2014-12-19 00:26:42 +00:00
|
|
|
|
.With(h => h.OutputPath = new OsPath(@"C:\DropFolder\MyDownload".AsOsAgnostic()))
|
2014-09-13 23:13:00 +00:00
|
|
|
|
.With(h => h.Title = "Drone.S01E01.HDTV")
|
2014-12-19 00:26:42 +00:00
|
|
|
|
.Build();
|
2013-10-22 07:31:36 +00:00
|
|
|
|
|
2014-12-19 00:26:42 +00:00
|
|
|
|
_grabHistory = Builder<History.History>.CreateListOfSize(2).BuildList();
|
2014-09-13 23:13:00 +00:00
|
|
|
|
|
|
|
|
|
var remoteEpisode = new RemoteEpisode
|
|
|
|
|
{
|
|
|
|
|
Series = new Series(),
|
|
|
|
|
Episodes = new List<Episode> { new Episode { Id = 1 } }
|
|
|
|
|
};
|
2013-10-22 07:31:36 +00:00
|
|
|
|
|
2014-12-19 00:26:42 +00:00
|
|
|
|
_trackedDownload = Builder<TrackedDownload>.CreateNew()
|
|
|
|
|
.With(c => c.State = TrackedDownloadStage.Downloading)
|
|
|
|
|
.With(c => c.DownloadItem = completed)
|
|
|
|
|
.With(c => c.RemoteEpisode = remoteEpisode)
|
|
|
|
|
.Build();
|
2014-04-19 15:09:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IHistoryService>()
|
2014-12-19 00:26:42 +00:00
|
|
|
|
.Setup(s => s.Find(_trackedDownload.DownloadItem.DownloadId, HistoryEventType.Grabbed))
|
|
|
|
|
.Returns(_grabHistory);
|
2014-09-13 23:13:00 +00:00
|
|
|
|
|
2013-10-22 07:31:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-24 05:24:26 +00:00
|
|
|
|
private void GivenNoGrabbedHistory()
|
2013-10-22 07:31:36 +00:00
|
|
|
|
{
|
|
|
|
|
Mocker.GetMock<IHistoryService>()
|
2014-12-19 00:26:42 +00:00
|
|
|
|
.Setup(s => s.Find(_trackedDownload.DownloadItem.DownloadId, HistoryEventType.Grabbed))
|
|
|
|
|
.Returns(new List<History.History>());
|
2013-10-22 07:31:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2014-12-19 00:26:42 +00:00
|
|
|
|
public void should_not_fail_if_matching_history_is_not_found()
|
2013-10-22 07:31:36 +00:00
|
|
|
|
{
|
2014-04-19 15:09:22 +00:00
|
|
|
|
GivenNoGrabbedHistory();
|
2013-10-22 07:31:36 +00:00
|
|
|
|
|
2014-12-19 00:26:42 +00:00
|
|
|
|
Subject.Process(_trackedDownload);
|
2013-10-22 07:31:36 +00:00
|
|
|
|
|
2014-12-19 00:26:42 +00:00
|
|
|
|
AssertDownloadNotFailed();
|
2013-10-22 07:31:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-24 20:50:00 +00:00
|
|
|
|
[Test]
|
2014-12-19 00:26:42 +00:00
|
|
|
|
public void should_mark_failed_if_encrypted()
|
2014-02-24 20:50:00 +00:00
|
|
|
|
{
|
2014-12-19 00:26:42 +00:00
|
|
|
|
_trackedDownload.DownloadItem.IsEncrypted = true;
|
2014-02-24 20:50:00 +00:00
|
|
|
|
|
2014-12-19 00:26:42 +00:00
|
|
|
|
Subject.Process(_trackedDownload);
|
2014-02-24 20:50:00 +00:00
|
|
|
|
|
2014-12-19 00:26:42 +00:00
|
|
|
|
AssertDownloadFailed();
|
2014-02-24 20:50:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-22 07:31:36 +00:00
|
|
|
|
[Test]
|
2014-12-19 00:26:42 +00:00
|
|
|
|
public void should_mark_failed_if_download_item_is_failed()
|
2013-10-22 07:31:36 +00:00
|
|
|
|
{
|
2014-12-19 00:26:42 +00:00
|
|
|
|
_trackedDownload.DownloadItem.Status = DownloadItemStatus.Failed;
|
2013-10-22 07:31:36 +00:00
|
|
|
|
|
2014-12-19 00:26:42 +00:00
|
|
|
|
Subject.Process(_trackedDownload);
|
2013-10-22 07:31:36 +00:00
|
|
|
|
|
2014-12-19 00:26:42 +00:00
|
|
|
|
AssertDownloadFailed();
|
2013-10-22 07:31:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-01-21 15:57:54 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void should_include_tracked_download_in_message()
|
|
|
|
|
{
|
|
|
|
|
_trackedDownload.DownloadItem.Status = DownloadItemStatus.Failed;
|
|
|
|
|
|
|
|
|
|
Subject.Process(_trackedDownload);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IEventAggregator>()
|
|
|
|
|
.Verify(v => v.PublishEvent(It.Is<DownloadFailedEvent>(c => c.TrackedDownload != null)), Times.Once());
|
|
|
|
|
|
|
|
|
|
AssertDownloadFailed();
|
|
|
|
|
}
|
2013-10-22 07:31:36 +00:00
|
|
|
|
|
2014-12-19 00:26:42 +00:00
|
|
|
|
private void AssertDownloadNotFailed()
|
2014-04-01 20:07:41 +00:00
|
|
|
|
{
|
2014-12-19 00:26:42 +00:00
|
|
|
|
Mocker.GetMock<IEventAggregator>()
|
|
|
|
|
.Verify(v => v.PublishEvent(It.IsAny<DownloadFailedEvent>()), Times.Never());
|
2014-04-01 20:07:41 +00:00
|
|
|
|
|
2014-12-19 00:26:42 +00:00
|
|
|
|
_trackedDownload.State.Should().NotBe(TrackedDownloadStage.DownloadFailed);
|
2014-04-01 20:07:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-21 20:56:13 +00:00
|
|
|
|
|
2014-12-19 00:26:42 +00:00
|
|
|
|
private void AssertDownloadFailed()
|
2014-07-21 20:56:13 +00:00
|
|
|
|
{
|
2014-12-19 00:26:42 +00:00
|
|
|
|
Mocker.GetMock<IEventAggregator>()
|
|
|
|
|
.Verify(v => v.PublishEvent(It.IsAny<DownloadFailedEvent>()), Times.Once());
|
2014-07-21 20:56:13 +00:00
|
|
|
|
|
2014-12-19 00:26:42 +00:00
|
|
|
|
_trackedDownload.State.Should().Be(TrackedDownloadStage.DownloadFailed);
|
2014-04-01 20:07:41 +00:00
|
|
|
|
}
|
2013-10-22 07:31:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|