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

102 lines
3.4 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;
using NzbDrone.Core.Music;
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<EntityHistory> _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<EntityHistory>.CreateListOfSize(2).BuildList();
2017-09-23 04:19:55 +00:00
var remoteAlbum = new RemoteAlbum
{
2017-09-23 04:19:55 +00:00
Artist = new Artist(),
Albums = new List<Album> { new Album { Id = 1 } }
};
2013-10-22 07:31:36 +00:00
_trackedDownload = Builder<TrackedDownload>.CreateNew()
.With(c => c.State = TrackedDownloadState.DownloadFailedPending)
.With(c => c.DownloadItem = completed)
2017-09-23 04:19:55 +00:00
.With(c => c.RemoteAlbum = remoteAlbum)
.Build();
Mocker.GetMock<IHistoryService>()
.Setup(s => s.Find(_trackedDownload.DownloadItem.DownloadId, EntityHistoryEventType.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.DownloadFailed);
}
private void AssertDownloadFailed()
{
Mocker.GetMock<IEventAggregator>()
.Verify(v => v.PublishEvent(It.IsAny<DownloadFailedEvent>()), Times.Once());
_trackedDownload.State.Should().Be(TrackedDownloadState.DownloadFailed);
}
2013-10-22 07:31:36 +00:00
}
}