2018-03-14 20:41:36 +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;
|
2019-12-22 22:08:53 +00:00
|
|
|
using NzbDrone.Core.Movies;
|
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-07-21 20:56:13 +00:00
|
|
|
using NzbDrone.Test.Common;
|
2013-10-22 07:31:36 +00:00
|
|
|
|
2020-03-29 17:48:34 +00:00
|
|
|
namespace NzbDrone.Core.Test.Download.FailedDownloadServiceTests
|
2013-10-22 07:31:36 +00:00
|
|
|
{
|
|
|
|
[TestFixture]
|
2020-03-29 17:48:34 +00:00
|
|
|
public class ProcessFixture : CoreTest<FailedDownloadService>
|
2013-10-22 07:31:36 +00:00
|
|
|
{
|
2014-12-19 00:26:42 +00:00
|
|
|
private TrackedDownload _trackedDownload;
|
2020-03-29 20:05:48 +00:00
|
|
|
private List<MovieHistory> _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
|
|
|
|
2020-03-29 20:05:48 +00:00
|
|
|
_grabHistory = Builder<MovieHistory>.CreateListOfSize(2).BuildList();
|
2014-09-13 23:13:00 +00:00
|
|
|
|
2020-03-29 17:48:34 +00:00
|
|
|
var remoteMovie = new RemoteMovie
|
2014-09-13 23:13:00 +00:00
|
|
|
{
|
2018-03-14 20:41:36 +00:00
|
|
|
Movie = new Movie(),
|
2014-09-13 23:13:00 +00:00
|
|
|
};
|
2013-10-22 07:31:36 +00:00
|
|
|
|
2014-12-19 00:26:42 +00:00
|
|
|
_trackedDownload = Builder<TrackedDownload>.CreateNew()
|
2020-03-29 17:48:34 +00:00
|
|
|
.With(c => c.State = TrackedDownloadState.Downloading)
|
2014-12-19 00:26:42 +00:00
|
|
|
.With(c => c.DownloadItem = completed)
|
2020-03-29 17:48:34 +00:00
|
|
|
.With(c => c.RemoteMovie = remoteMovie)
|
2014-12-19 00:26:42 +00:00
|
|
|
.Build();
|
2014-04-19 15:09:22 +00:00
|
|
|
|
|
|
|
Mocker.GetMock<IHistoryService>()
|
2020-03-29 20:05:48 +00:00
|
|
|
.Setup(s => s.Find(_trackedDownload.DownloadItem.DownloadId, MovieHistoryEventType.Grabbed))
|
2014-12-19 00:26:42 +00:00
|
|
|
.Returns(_grabHistory);
|
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>()
|
2020-03-29 20:05:48 +00:00
|
|
|
.Setup(s => s.Find(_trackedDownload.DownloadItem.DownloadId, MovieHistoryEventType.Grabbed))
|
|
|
|
.Returns(new List<MovieHistory>());
|
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
|
|
|
|
2020-03-29 17:48:34 +00:00
|
|
|
Subject.Check(_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
|
|
|
}
|
|
|
|
|
2015-02-22 12:43:14 +00:00
|
|
|
[Test]
|
|
|
|
public void should_warn_if_matching_history_is_not_found()
|
|
|
|
{
|
|
|
|
_trackedDownload.DownloadItem.Status = DownloadItemStatus.Failed;
|
|
|
|
GivenNoGrabbedHistory();
|
|
|
|
|
2020-03-29 17:48:34 +00:00
|
|
|
Subject.Check(_trackedDownload);
|
2015-02-22 12:43:14 +00:00
|
|
|
|
|
|
|
_trackedDownload.StatusMessages.Should().NotBeEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_not_warn_if_matching_history_is_not_found_and_not_failed()
|
|
|
|
{
|
|
|
|
_trackedDownload.DownloadItem.Status = DownloadItemStatus.Failed;
|
|
|
|
GivenNoGrabbedHistory();
|
|
|
|
|
2020-03-29 17:48:34 +00:00
|
|
|
Subject.Check(_trackedDownload);
|
2015-02-22 12:43:14 +00:00
|
|
|
|
|
|
|
_trackedDownload.StatusMessages.Should().NotBeEmpty();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2020-03-29 17:48:34 +00:00
|
|
|
_trackedDownload.State.Should().NotBe(TrackedDownloadState.Failed);
|
2014-04-01 20:07:41 +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
|
|
|
|
2020-03-29 17:48:34 +00:00
|
|
|
_trackedDownload.State.Should().Be(TrackedDownloadState.Failed);
|
2014-04-01 20:07:41 +00:00
|
|
|
}
|
2013-10-22 07:31:36 +00:00
|
|
|
}
|
|
|
|
}
|