You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
3.3 KiB
101 lines
3.3 KiB
7 years ago
|
using System.Collections.Generic;
|
||
11 years ago
|
using FizzWare.NBuilder;
|
||
10 years ago
|
using FluentAssertions;
|
||
11 years ago
|
using Moq;
|
||
|
using NUnit.Framework;
|
||
10 years ago
|
using NzbDrone.Common.Disk;
|
||
11 years ago
|
using NzbDrone.Core.Download;
|
||
10 years ago
|
using NzbDrone.Core.Download.TrackedDownloads;
|
||
11 years ago
|
using NzbDrone.Core.History;
|
||
|
using NzbDrone.Core.Messaging.Events;
|
||
5 years ago
|
using NzbDrone.Core.Movies;
|
||
10 years ago
|
using NzbDrone.Core.Parser.Model;
|
||
11 years ago
|
using NzbDrone.Core.Test.Framework;
|
||
10 years ago
|
using NzbDrone.Test.Common;
|
||
11 years ago
|
|
||
5 years ago
|
namespace NzbDrone.Core.Test.Download.FailedDownloadServiceTests
|
||
11 years ago
|
{
|
||
|
[TestFixture]
|
||
5 years ago
|
public class ProcessFailedFixture : CoreTest<FailedDownloadService>
|
||
11 years ago
|
{
|
||
10 years ago
|
private TrackedDownload _trackedDownload;
|
||
|
private List<History.History> _grabHistory;
|
||
11 years ago
|
|
||
|
[SetUp]
|
||
|
public void Setup()
|
||
|
{
|
||
10 years ago
|
var completed = Builder<DownloadClientItem>.CreateNew()
|
||
10 years ago
|
.With(h => h.Status = DownloadItemStatus.Completed)
|
||
10 years ago
|
.With(h => h.OutputPath = new OsPath(@"C:\DropFolder\MyDownload".AsOsAgnostic()))
|
||
10 years ago
|
.With(h => h.Title = "Drone.S01E01.HDTV")
|
||
10 years ago
|
.Build();
|
||
11 years ago
|
|
||
10 years ago
|
_grabHistory = Builder<History.History>.CreateListOfSize(2).BuildList();
|
||
10 years ago
|
|
||
5 years ago
|
var remoteMovie = new RemoteMovie
|
||
10 years ago
|
{
|
||
5 years ago
|
Movie = new Movie()
|
||
10 years ago
|
};
|
||
11 years ago
|
|
||
10 years ago
|
_trackedDownload = Builder<TrackedDownload>.CreateNew()
|
||
5 years ago
|
.With(c => c.State = TrackedDownloadState.FailedPending)
|
||
10 years ago
|
.With(c => c.DownloadItem = completed)
|
||
5 years ago
|
.With(c => c.RemoteMovie = remoteMovie)
|
||
10 years ago
|
.Build();
|
||
11 years ago
|
|
||
|
Mocker.GetMock<IHistoryService>()
|
||
10 years ago
|
.Setup(s => s.Find(_trackedDownload.DownloadItem.DownloadId, HistoryEventType.Grabbed))
|
||
|
.Returns(_grabHistory);
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
[Test]
|
||
10 years ago
|
public void should_mark_failed_if_encrypted()
|
||
11 years ago
|
{
|
||
10 years ago
|
_trackedDownload.DownloadItem.IsEncrypted = true;
|
||
11 years ago
|
|
||
5 years ago
|
Subject.ProcessFailed(_trackedDownload);
|
||
11 years ago
|
|
||
10 years ago
|
AssertDownloadFailed();
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
[Test]
|
||
10 years ago
|
public void should_mark_failed_if_download_item_is_failed()
|
||
11 years ago
|
{
|
||
10 years ago
|
_trackedDownload.DownloadItem.Status = DownloadItemStatus.Failed;
|
||
11 years ago
|
|
||
5 years ago
|
Subject.ProcessFailed(_trackedDownload);
|
||
11 years ago
|
|
||
10 years ago
|
AssertDownloadFailed();
|
||
11 years ago
|
}
|
||
|
|
||
10 years ago
|
[Test]
|
||
|
public void should_include_tracked_download_in_message()
|
||
|
{
|
||
|
_trackedDownload.DownloadItem.Status = DownloadItemStatus.Failed;
|
||
|
|
||
5 years ago
|
Subject.ProcessFailed(_trackedDownload);
|
||
10 years ago
|
|
||
|
Mocker.GetMock<IEventAggregator>()
|
||
|
.Verify(v => v.PublishEvent(It.Is<DownloadFailedEvent>(c => c.TrackedDownload != null)), Times.Once());
|
||
|
|
||
|
AssertDownloadFailed();
|
||
|
}
|
||
11 years ago
|
|
||
10 years ago
|
private void AssertDownloadNotFailed()
|
||
11 years ago
|
{
|
||
10 years ago
|
Mocker.GetMock<IEventAggregator>()
|
||
|
.Verify(v => v.PublishEvent(It.IsAny<DownloadFailedEvent>()), Times.Never());
|
||
11 years ago
|
|
||
5 years ago
|
_trackedDownload.State.Should().NotBe(TrackedDownloadState.Failed);
|
||
11 years ago
|
}
|
||
|
|
||
10 years ago
|
private void AssertDownloadFailed()
|
||
10 years ago
|
{
|
||
10 years ago
|
Mocker.GetMock<IEventAggregator>()
|
||
|
.Verify(v => v.PublishEvent(It.IsAny<DownloadFailedEvent>()), Times.Once());
|
||
10 years ago
|
|
||
5 years ago
|
_trackedDownload.State.Should().Be(TrackedDownloadState.Failed);
|
||
11 years ago
|
}
|
||
11 years ago
|
}
|
||
|
}
|