mirror of https://github.com/Radarr/Radarr
107 lines
3.6 KiB
C#
107 lines
3.6 KiB
C#
using System.Collections.Generic;
|
|
using FizzWare.NBuilder;
|
|
using FluentAssertions;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
using NzbDrone.Common.Disk;
|
|
using NzbDrone.Core.Download;
|
|
using NzbDrone.Core.Download.TrackedDownloads;
|
|
using NzbDrone.Core.History;
|
|
using NzbDrone.Core.Messaging.Events;
|
|
using NzbDrone.Core.Movies;
|
|
using NzbDrone.Core.Parser.Model;
|
|
using NzbDrone.Core.Test.Framework;
|
|
using NzbDrone.Test.Common;
|
|
|
|
namespace NzbDrone.Core.Test.Download.FailedDownloadServiceTests
|
|
{
|
|
[TestFixture]
|
|
public class ProcessFixture : CoreTest<FailedDownloadService>
|
|
{
|
|
private TrackedDownload _trackedDownload;
|
|
private List<MovieHistory> _grabHistory;
|
|
|
|
[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();
|
|
|
|
_grabHistory = Builder<MovieHistory>.CreateListOfSize(2).BuildList();
|
|
|
|
var remoteMovie = new RemoteMovie
|
|
{
|
|
Movie = new Movie(),
|
|
};
|
|
|
|
_trackedDownload = Builder<TrackedDownload>.CreateNew()
|
|
.With(c => c.State = TrackedDownloadState.Downloading)
|
|
.With(c => c.DownloadItem = completed)
|
|
.With(c => c.RemoteMovie = remoteMovie)
|
|
.Build();
|
|
|
|
Mocker.GetMock<IHistoryService>()
|
|
.Setup(s => s.Find(_trackedDownload.DownloadItem.DownloadId, MovieHistoryEventType.Grabbed))
|
|
.Returns(_grabHistory);
|
|
}
|
|
|
|
private void GivenNoGrabbedHistory()
|
|
{
|
|
Mocker.GetMock<IHistoryService>()
|
|
.Setup(s => s.Find(_trackedDownload.DownloadItem.DownloadId, MovieHistoryEventType.Grabbed))
|
|
.Returns(new List<MovieHistory>());
|
|
}
|
|
|
|
[Test]
|
|
public void should_not_fail_if_matching_history_is_not_found()
|
|
{
|
|
GivenNoGrabbedHistory();
|
|
|
|
Subject.Check(_trackedDownload);
|
|
|
|
AssertDownloadNotFailed();
|
|
}
|
|
|
|
[Test]
|
|
public void should_warn_if_matching_history_is_not_found()
|
|
{
|
|
_trackedDownload.DownloadItem.Status = DownloadItemStatus.Failed;
|
|
GivenNoGrabbedHistory();
|
|
|
|
Subject.Check(_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.Check(_trackedDownload);
|
|
|
|
_trackedDownload.StatusMessages.Should().NotBeEmpty();
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|