2011-06-21 08:44:01 +03:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using AutoMoq;
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
using Moq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
using NzbDrone.Core.Providers.Core;
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
2011-10-21 02:42:17 +03:00
|
|
|
namespace NzbDrone.Core.Test.ProviderTests
|
2011-06-21 08:44:01 +03:00
|
|
|
{
|
|
|
|
// ReSharper disable InconsistentNaming
|
|
|
|
public class DiskScanProviderTest : TestBase
|
|
|
|
{
|
|
|
|
[Test]
|
2011-10-23 02:28:57 +03:00
|
|
|
public void scan_series_should_update_the_last_scan_date()
|
2011-06-21 08:44:01 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer();
|
2011-06-22 08:44:57 +03:00
|
|
|
mocker.GetMock<SeriesProvider>()
|
|
|
|
.Setup(c => c.UpdateSeries(It.Is<Series>(s => s.LastDiskSync != null))).Verifiable();
|
2011-06-21 08:44:01 +03:00
|
|
|
|
|
|
|
mocker.GetMock<EpisodeProvider>()
|
2011-06-22 08:44:57 +03:00
|
|
|
.Setup(c => c.GetEpisodeBySeries(It.IsAny<long>()))
|
|
|
|
.Returns(new List<Episode> { new Episode() });
|
2011-06-21 08:44:01 +03:00
|
|
|
|
2011-10-23 03:13:49 +03:00
|
|
|
mocker.GetMock<DiskProvider>()
|
|
|
|
.Setup(c => c.FolderExists(It.IsAny<string>()))
|
|
|
|
.Returns(true);
|
2011-06-21 08:44:01 +03:00
|
|
|
|
2011-06-22 08:44:57 +03:00
|
|
|
mocker.GetMock<MediaFileProvider>()
|
|
|
|
.Setup(c => c.GetSeriesFiles(It.IsAny<int>()))
|
|
|
|
.Returns(new List<EpisodeFile>());
|
2011-06-21 08:44:01 +03:00
|
|
|
|
2011-06-22 08:44:57 +03:00
|
|
|
mocker.Resolve<DiskScanProvider>().Scan(new Series());
|
2011-06-21 08:44:01 +03:00
|
|
|
|
2011-06-22 08:44:57 +03:00
|
|
|
mocker.VerifyAllMocks();
|
2011-06-21 08:44:01 +03:00
|
|
|
|
2011-06-22 04:12:20 +03:00
|
|
|
}
|
2011-06-21 08:44:01 +03:00
|
|
|
|
2011-06-22 08:44:57 +03:00
|
|
|
[Test]
|
|
|
|
public void cleanup_should_skip_existing_files()
|
2011-06-21 08:44:01 +03:00
|
|
|
{
|
2011-06-22 08:44:57 +03:00
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
|
|
var episodes = Builder<EpisodeFile>.CreateListOfSize(10).Build();
|
2011-06-21 08:44:01 +03:00
|
|
|
|
|
|
|
mocker.GetMock<DiskProvider>()
|
2011-06-22 08:44:57 +03:00
|
|
|
.Setup(e => e.FileExists(It.IsAny<String>()))
|
|
|
|
.Returns(true);
|
2011-06-21 08:44:01 +03:00
|
|
|
|
|
|
|
|
|
|
|
//Act
|
2011-06-22 08:44:57 +03:00
|
|
|
mocker.Resolve<DiskScanProvider>().CleanUp(episodes);
|
2011-06-21 08:44:01 +03:00
|
|
|
|
|
|
|
//Assert
|
2011-06-22 08:44:57 +03:00
|
|
|
mocker.VerifyAllMocks();
|
2011-06-21 08:44:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2011-06-22 08:44:57 +03:00
|
|
|
public void cleanup_should_delete_none_existing_files()
|
2011-06-21 08:44:01 +03:00
|
|
|
{
|
2011-06-22 08:44:57 +03:00
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
|
|
var episodes = Builder<EpisodeFile>.CreateListOfSize(10).Build();
|
2011-06-21 08:44:01 +03:00
|
|
|
|
2011-06-22 08:44:57 +03:00
|
|
|
mocker.GetMock<DiskProvider>()
|
|
|
|
.Setup(e => e.FileExists(It.IsAny<String>()))
|
|
|
|
.Returns(false);
|
2011-06-22 04:12:20 +03:00
|
|
|
|
2011-06-22 08:44:57 +03:00
|
|
|
mocker.GetMock<EpisodeProvider>()
|
|
|
|
.Setup(e => e.GetEpisodesByFileId(It.IsAny<int>()))
|
|
|
|
.Returns(new List<Episode>());
|
2011-06-21 08:44:01 +03:00
|
|
|
|
2011-06-22 04:12:20 +03:00
|
|
|
mocker.GetMock<MediaFileProvider>()
|
2011-06-22 08:44:57 +03:00
|
|
|
.Setup(e => e.Delete(It.IsAny<int>()));
|
2011-06-21 08:44:01 +03:00
|
|
|
|
|
|
|
|
|
|
|
//Act
|
2011-06-22 08:44:57 +03:00
|
|
|
mocker.Resolve<DiskScanProvider>().CleanUp(episodes);
|
2011-06-21 08:44:01 +03:00
|
|
|
|
|
|
|
//Assert
|
2011-06-22 08:44:57 +03:00
|
|
|
mocker.VerifyAllMocks();
|
2011-06-21 08:44:01 +03:00
|
|
|
|
2011-06-22 08:44:57 +03:00
|
|
|
mocker.GetMock<EpisodeProvider>()
|
|
|
|
.Verify(e => e.GetEpisodesByFileId(It.IsAny<int>()), Times.Exactly(10));
|
2011-06-21 08:44:01 +03:00
|
|
|
|
2011-06-22 04:12:20 +03:00
|
|
|
mocker.GetMock<MediaFileProvider>()
|
2011-06-22 08:44:57 +03:00
|
|
|
.Verify(e => e.Delete(It.IsAny<int>()), Times.Exactly(10));
|
2011-06-21 08:44:01 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2011-06-22 08:44:57 +03:00
|
|
|
public void cleanup_should_delete_none_existing_files_remove_links_to_episodes()
|
2011-06-21 08:44:01 +03:00
|
|
|
{
|
2011-06-22 04:12:20 +03:00
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
2011-06-22 08:44:57 +03:00
|
|
|
var episodes = Builder<EpisodeFile>.CreateListOfSize(10).Build();
|
2011-06-21 08:44:01 +03:00
|
|
|
|
2011-06-22 08:44:57 +03:00
|
|
|
mocker.GetMock<DiskProvider>()
|
|
|
|
.Setup(e => e.FileExists(It.IsAny<String>()))
|
|
|
|
.Returns(false);
|
2011-06-21 08:44:01 +03:00
|
|
|
|
2011-06-22 08:44:57 +03:00
|
|
|
mocker.GetMock<EpisodeProvider>()
|
|
|
|
.Setup(e => e.GetEpisodesByFileId(It.IsAny<int>()))
|
|
|
|
.Returns(new List<Episode> { new Episode { EpisodeFileId = 10 }, new Episode { EpisodeFileId = 10 } });
|
2011-06-21 08:44:01 +03:00
|
|
|
|
2011-06-22 08:44:57 +03:00
|
|
|
mocker.GetMock<EpisodeProvider>()
|
|
|
|
.Setup(e => e.UpdateEpisode(It.IsAny<Episode>()));
|
2011-06-21 08:44:01 +03:00
|
|
|
|
2011-06-22 04:12:20 +03:00
|
|
|
mocker.GetMock<MediaFileProvider>()
|
2011-06-22 08:44:57 +03:00
|
|
|
.Setup(e => e.Delete(It.IsAny<int>()));
|
2011-06-22 04:12:20 +03:00
|
|
|
|
2011-06-21 08:44:01 +03:00
|
|
|
|
|
|
|
//Act
|
2011-06-22 08:44:57 +03:00
|
|
|
mocker.Resolve<DiskScanProvider>().CleanUp(episodes);
|
2011-06-21 08:44:01 +03:00
|
|
|
|
|
|
|
//Assert
|
2011-06-22 08:44:57 +03:00
|
|
|
mocker.VerifyAllMocks();
|
2011-06-21 08:44:01 +03:00
|
|
|
|
|
|
|
mocker.GetMock<EpisodeProvider>()
|
2011-06-22 08:44:57 +03:00
|
|
|
.Verify(e => e.GetEpisodesByFileId(It.IsAny<int>()), Times.Exactly(10));
|
2011-06-21 08:44:01 +03:00
|
|
|
|
2011-06-22 08:44:57 +03:00
|
|
|
mocker.GetMock<EpisodeProvider>()
|
|
|
|
.Verify(e => e.UpdateEpisode(It.Is<Episode>(g=>g.EpisodeFileId == 0)), Times.Exactly(20));
|
2011-06-21 09:34:45 +03:00
|
|
|
|
|
|
|
mocker.GetMock<MediaFileProvider>()
|
2011-06-22 08:44:57 +03:00
|
|
|
.Verify(e => e.Delete(It.IsAny<int>()), Times.Exactly(10));
|
2011-06-21 08:44:01 +03:00
|
|
|
|
2011-06-22 08:44:57 +03:00
|
|
|
mocker.GetMock<MediaFileProvider>()
|
|
|
|
.Verify(e => e.Delete(It.IsAny<int>()), Times.Exactly(10));
|
2011-06-21 08:44:01 +03:00
|
|
|
|
|
|
|
}
|
2011-06-22 04:12:20 +03:00
|
|
|
|
2011-10-22 22:03:54 +03:00
|
|
|
[Test]
|
|
|
|
public void scan_series_should_log_warning_if_path_doesnt_exist_on_disk()
|
|
|
|
{
|
|
|
|
//Setup
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
|
|
|
|
|
|
var series = Builder<Series>.CreateNew()
|
|
|
|
.With(s => s.Path = @"C:\Test\TV\SeriesName\")
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
mocker.GetMock<MediaFileProvider>()
|
|
|
|
.Setup(c => c.DeleteOrphaned())
|
|
|
|
.Returns(0);
|
|
|
|
|
|
|
|
mocker.GetMock<MediaFileProvider>()
|
|
|
|
.Setup(c => c.RepairLinks())
|
|
|
|
.Returns(0);
|
2011-06-22 04:12:20 +03:00
|
|
|
|
2011-10-22 22:03:54 +03:00
|
|
|
mocker.GetMock<DiskProvider>()
|
|
|
|
.Setup(c => c.FolderExists(series.Path))
|
|
|
|
.Returns(false);
|
2011-06-22 04:12:20 +03:00
|
|
|
|
2011-10-22 22:03:54 +03:00
|
|
|
//Act
|
|
|
|
mocker.Resolve<DiskScanProvider>().Scan(series, series.Path);
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
mocker.VerifyAllMocks();
|
|
|
|
ExceptionVerification.ExcpectedWarns(1);
|
|
|
|
}
|
2011-06-21 08:44:01 +03:00
|
|
|
}
|
|
|
|
}
|