Radarr/src/NzbDrone.Core.Test/Download/FailedDownloadServiceFixtur...

140 lines
4.5 KiB
C#
Raw Normal View History

using System.Collections.Generic;
2013-10-22 07:31:36 +00:00
using FizzWare.NBuilder;
using FluentAssertions;
2013-10-22 07:31:36 +00:00
using Moq;
using NUnit.Framework;
using NzbDrone.Common.Disk;
2013-10-22 07:31:36 +00:00
using NzbDrone.Core.Download;
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;
using NzbDrone.Core.Parser.Model;
2013-10-22 07:31:36 +00:00
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
2013-10-22 07:31:36 +00:00
namespace NzbDrone.Core.Test.Download
{
[TestFixture]
public class FailedDownloadServiceFixture : CoreTest<FailedDownloadService>
2013-10-22 07:31:36 +00:00
{
private TrackedDownload _trackedDownload;
private List<History.History> _grabHistory;
2013-10-22 07:31:36 +00:00
[SetUp]
public void Setup()
{
var completed = Builder<DownloadClientItem>.CreateNew()
.With(h => h.Status = DownloadItemStatus.Completed)
.With(h => h.OutputPath = new OsPath(@"C:\DropFolder\MyDownload".AsOsAgnostic()))
.With(h => h.Title = "Drone.S01E01.HDTV")
.Build();
2013-10-22 07:31:36 +00:00
_grabHistory = Builder<History.History>.CreateListOfSize(2).BuildList();
var remoteEpisode = new RemoteMovie
{
Movie = new Movie(),
};
2013-10-22 07:31:36 +00:00
_trackedDownload = Builder<TrackedDownload>.CreateNew()
.With(c => c.State = TrackedDownloadStage.Downloading)
.With(c => c.DownloadItem = completed)
.With(c => c.RemoteMovie = remoteEpisode)
.Build();
Mocker.GetMock<IHistoryService>()
.Setup(s => s.Find(_trackedDownload.DownloadItem.DownloadId, HistoryEventType.Grabbed))
.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>()
.Setup(s => s.Find(_trackedDownload.DownloadItem.DownloadId, HistoryEventType.Grabbed))
.Returns(new List<History.History>());
2013-10-22 07:31:36 +00:00
}
[Test]
public void should_not_fail_if_matching_history_is_not_found()
2013-10-22 07:31:36 +00:00
{
GivenNoGrabbedHistory();
2013-10-22 07:31:36 +00:00
Subject.Process(_trackedDownload);
2013-10-22 07:31:36 +00:00
AssertDownloadNotFailed();
2013-10-22 07:31:36 +00:00
}
[Test]
public void should_warn_if_matching_history_is_not_found()
{
_trackedDownload.DownloadItem.Status = DownloadItemStatus.Failed;
GivenNoGrabbedHistory();
Subject.Process(_trackedDownload);
_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();
Subject.Process(_trackedDownload);
_trackedDownload.StatusMessages.Should().NotBeEmpty();
}
[Test]
public void should_mark_failed_if_encrypted()
{
_trackedDownload.DownloadItem.IsEncrypted = true;
Subject.Process(_trackedDownload);
AssertDownloadFailed();
}
2013-10-22 07:31:36 +00:00
[Test]
public void should_mark_failed_if_download_item_is_failed()
2013-10-22 07:31:36 +00:00
{
_trackedDownload.DownloadItem.Status = DownloadItemStatus.Failed;
2013-10-22 07:31:36 +00:00
Subject.Process(_trackedDownload);
2013-10-22 07:31:36 +00:00
AssertDownloadFailed();
2013-10-22 07:31:36 +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
private void AssertDownloadNotFailed()
{
Mocker.GetMock<IEventAggregator>()
.Verify(v => v.PublishEvent(It.IsAny<DownloadFailedEvent>()), Times.Never());
_trackedDownload.State.Should().NotBe(TrackedDownloadStage.DownloadFailed);
}
private void AssertDownloadFailed()
{
Mocker.GetMock<IEventAggregator>()
.Verify(v => v.PublishEvent(It.IsAny<DownloadFailedEvent>()), Times.Once());
_trackedDownload.State.Should().Be(TrackedDownloadStage.DownloadFailed);
}
2013-10-22 07:31:36 +00:00
}
}