Radarr/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/ScanWatchFolderFixture.cs

100 lines
3.2 KiB
C#
Raw Normal View History

using System;
2019-07-10 03:14:53 +00:00
using System.Collections.Generic;
using System.IO;
using System.Linq;
2019-07-10 03:14:53 +00:00
using System.Threading;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common.Disk;
using NzbDrone.Core.Download;
using NzbDrone.Core.Download.Clients.Blackhole;
2019-07-10 03:14:53 +00:00
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
{
[TestFixture]
public class ScanWatchFolderFixture : CoreTest<ScanWatchFolder>
{
Fixed all tests and even added some new ones :) (#835) * First fixing of tests. * Updated more tests. * Fix some tests * Fix all prioritization tests. And add new for preferred words. * Updated CompletedDownloadservice tests * Fixed a lot of tests * Fixed all indexer requests. We should add more for the indexers we added. To lazy for that though ¯\_(ツ)_/¯ * Fixed organizer tests. Should probably be also updated to incorporate our newly added tags. * Fix notification tests. * Fixed update test for osx * Fixed a few more tests. * Fixed some more tests. * Update appveyor.yml * Update appveyor.yml * Update appveyor.yml * Update appveyor.yml * Update appveyor.yml * Update appveyor.yml * Update appveyor.yml * Update appveyor.yml * Update appveyor.yml * Update appveyor.yml * Update appveyor.yml * Update appveyor.yml * Update appveyor.yml * Update appveyor.yml * Update activity.less * Update appveyor.yml * Update appveyor.yml * Update CommonVersionInfo.cs * Update build-appveyor.cake Let's hope this works. * Update CommonVersionInfo.cs Just to kickstart appveyor * Fixed a few tests * Just ignore those tests. * Fixed more tests. * First steps in fixing Core.Test.Download.DownloadApprovedFixture * Fix most DownloadApprovedFixture tests * Fixed something. * Fixed a few more tests. * Fixed pending release tests. * All Core tests are now fixed. * Fixed the last tests :) * Fixed Download Station Tests. * Fixed Vuze and Transmission default settings which caused the tests to fail. * Fix most tests. * Fix RootFolder tests. * Fixed last tests
2017-03-06 21:23:25 +00:00
protected readonly string _title = "Droned.1998.1080p.WEB-DL-DRONE";
protected string _completedDownloadFolder = @"c:\blackhole\completed".AsOsAgnostic();
2019-07-10 03:14:53 +00:00
protected void GivenCompletedItem()
{
var targetDir = Path.Combine(_completedDownloadFolder, _title);
Mocker.GetMock<IDiskProvider>()
.Setup(c => c.GetDirectories(_completedDownloadFolder))
.Returns(new[] { targetDir });
Mocker.GetMock<IDiskProvider>()
.Setup(c => c.GetFiles(targetDir, SearchOption.AllDirectories))
.Returns(new[] { Path.Combine(targetDir, "somefile.mkv") });
Mocker.GetMock<IDiskProvider>()
.Setup(c => c.GetFileSize(It.IsAny<string>()))
.Returns(1000000);
2019-07-10 03:14:53 +00:00
Mocker.GetMock<IDiskScanService>().Setup(c => c.FilterPaths(It.IsAny<string>(), It.IsAny<IEnumerable<string>>(), It.IsAny<bool>()))
.Returns<string, IEnumerable<string>, bool>((b, s, e) => s.ToList());
}
protected void GivenChangedItem()
{
var currentSize = Mocker.GetMock<IDiskProvider>().Object.GetFileSize("abc");
Mocker.GetMock<IDiskProvider>()
.Setup(c => c.GetFileSize(It.IsAny<string>()))
.Returns(currentSize + 1);
}
2019-07-10 03:14:53 +00:00
private void VerifySingleItem(DownloadItemStatus status)
{
var items = Subject.GetItems(_completedDownloadFolder, TimeSpan.FromMilliseconds(50)).ToList();
items.Count.Should().Be(1);
items.First().Status.Should().Be(status);
}
[Test]
public void GetItems_should_considered_locked_files_queued()
{
GivenCompletedItem();
Mocker.GetMock<IDiskProvider>()
.Setup(c => c.IsFileLocked(It.IsAny<string>()))
.Returns(true);
Thread.Sleep(60);
VerifySingleItem(DownloadItemStatus.Downloading);
}
[Test]
public void GetItems_should_considered_changing_files_queued()
{
GivenCompletedItem();
VerifySingleItem(DownloadItemStatus.Downloading);
// If we keep changing the file every 20ms we should stay Downloading.
for (var i = 0; i < 10; i++)
{
TestLogger.Info("Iteration {0}", i);
GivenChangedItem();
VerifySingleItem(DownloadItemStatus.Downloading);
Thread.Sleep(10);
}
// Until it remains unchanged for >=50ms.
Thread.Sleep(60);
VerifySingleItem(DownloadItemStatus.Completed);
}
}
}