Radarr/src/NzbDrone.Core.Test/Download/FailedDownloadServiceTests/ProcessFailedFixture.cs

101 lines
3.3 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.FailedDownloadServiceTests
2013-10-22 07:31:36 +00:00
{
[TestFixture]
public class ProcessFailedFixture : 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 remoteMovie = new RemoteMovie
{
Movie = new Movie()
};
2013-10-22 07:31:36 +00:00
_trackedDownload = Builder<TrackedDownload>.CreateNew()
.With(c => c.State = TrackedDownloadState.FailedPending)
.With(c => c.DownloadItem = completed)
.With(c => c.RemoteMovie = remoteMovie)
.Build();
Mocker.GetMock<IHistoryService>()
.Setup(s => s.Find(_trackedDownload.DownloadItem.DownloadId, HistoryEventType.Grabbed))
.Returns(_grabHistory);
2013-10-22 07:31:36 +00:00
}
[Test]
public void should_mark_failed_if_encrypted()
{
_trackedDownload.DownloadItem.IsEncrypted = true;
Subject.ProcessFailed(_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.ProcessFailed(_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.ProcessFailed(_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(TrackedDownloadState.Failed);
}
private void AssertDownloadFailed()
{
Mocker.GetMock<IEventAggregator>()
.Verify(v => v.PublishEvent(It.IsAny<DownloadFailedEvent>()), Times.Once());
_trackedDownload.State.Should().Be(TrackedDownloadState.Failed);
}
2013-10-22 07:31:36 +00:00
}
}