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

107 lines
3.6 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 ProcessFixture : CoreTest<FailedDownloadService>
2013-10-22 07:31:36 +00:00
{
private TrackedDownload _trackedDownload;
private List<MovieHistory> _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<MovieHistory>.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.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);
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, MovieHistoryEventType.Grabbed))
.Returns(new List<MovieHistory>());
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.Check(_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.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);
}
2013-10-22 07:31:36 +00:00
}
}