moved cleanup of deleted files to their own service.
detaching of episodes when files are deleted is done through events now.
This commit is contained in:
@@ -13,7 +13,7 @@ using NzbDrone.Core.Tv;
|
||||
namespace NzbDrone.Core.Test.IndexerSearchTests
|
||||
{
|
||||
public abstract class IndexerSearchTestBase<TSearch> : CoreTest<TSearch>
|
||||
where TSearch : SearchBase
|
||||
where TSearch : IndexerSearchBase
|
||||
{
|
||||
protected Series _series;
|
||||
protected Episode _episode;
|
||||
|
||||
@@ -13,7 +13,7 @@ using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.Test.IndexerSearchTests
|
||||
{
|
||||
public class TestSearch : SearchBase
|
||||
public class TestSearch : IndexerSearchBase
|
||||
{
|
||||
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using FizzWare.NBuilder;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
using System.Linq;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFileTests
|
||||
{
|
||||
public class GhostFileCleanupFixture : CoreTest<GhostFileCleanupService>
|
||||
{
|
||||
|
||||
private void GiveEpisodeFiles(IEnumerable<EpisodeFile> episodeFiles)
|
||||
{
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(c => c.GetFilesBySeries(It.IsAny<int>()))
|
||||
.Returns(episodeFiles.ToList());
|
||||
}
|
||||
|
||||
|
||||
private const string DeletedPath = "ANY FILE WITH THIS PATH IS CONSIDERED DELETED!";
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(e => e.FileExists(It.Is<String>(c => c != DeletedPath)))
|
||||
.Returns(true);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_skip_files_that_exist_in_disk()
|
||||
{
|
||||
var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(10)
|
||||
.Build();
|
||||
|
||||
GiveEpisodeFiles(episodeFiles);
|
||||
|
||||
Subject.RemoveNonExistingFiles(0);
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Verify(c => c.UpdateEpisode(It.IsAny<Episode>()), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_delete_none_existing_files()
|
||||
{
|
||||
var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(10)
|
||||
.Random(2)
|
||||
.With(c => c.Path = DeletedPath)
|
||||
.Build();
|
||||
|
||||
GiveEpisodeFiles(episodeFiles);
|
||||
|
||||
Subject.RemoveNonExistingFiles(0);
|
||||
|
||||
Mocker.GetMock<IMediaFileService>().Verify(c => c.Delete(It.Is<EpisodeFile>(e => e.Path == DeletedPath)), Times.Exactly(2));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -151,6 +151,7 @@
|
||||
<Compile Include="JobTests\RenameSeasonJobFixture.cs" />
|
||||
<Compile Include="DecisionEngineTests\LanguageSpecificationFixture.cs" />
|
||||
<Compile Include="MediaCoverTests\MediaCoverServiceFixture.cs" />
|
||||
<Compile Include="MediaFileTests\GhostFileCleanupFixture.cs" />
|
||||
<Compile Include="MediaFileTests\MediaFileRepositoryFixture.cs" />
|
||||
<Compile Include="ProviderTests\DownloadClientTests\NzbgetProviderTests\DownloadNzbFixture.cs" />
|
||||
<Compile Include="ProviderTests\DownloadClientTests\NzbgetProviderTests\QueueFixture.cs" />
|
||||
@@ -172,7 +173,6 @@
|
||||
<Compile Include="Configuration\ConfigCachingFixture.cs" />
|
||||
<Compile Include="DecisionEngineTests\AllowedReleaseGroupSpecificationFixture.cs" />
|
||||
<Compile Include="DecisionEngineTests\CustomStartDateSpecificationFixture.cs" />
|
||||
<Compile Include="ProviderTests\DiskScanProviderTests\CleanUpFixture.cs" />
|
||||
<Compile Include="ProviderTests\DiskScanProviderTests\CleanUpDropFolderFixture.cs" />
|
||||
<Compile Include="ProviderTests\DiskScanProviderTests\GetVideoFilesFixture.cs" />
|
||||
<Compile Include="ProviderTests\DiskScanProviderTests\ScanFixture.cs" />
|
||||
|
||||
@@ -1,117 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers;
|
||||
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
using NzbDrone.Test.Common.AutoMoq;
|
||||
|
||||
namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
|
||||
{
|
||||
// ReSharper disable InconsistentNaming
|
||||
public class CleanUpFixture : CoreTest
|
||||
{
|
||||
[Test]
|
||||
public void should_skip_existing_files()
|
||||
{
|
||||
var episodes = Builder<EpisodeFile>.CreateListOfSize(10).Build();
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(e => e.FileExists(It.IsAny<String>()))
|
||||
.Returns(true);
|
||||
|
||||
|
||||
//Act
|
||||
Mocker.Resolve<DiskScanProvider>().CleanUp(episodes);
|
||||
|
||||
//Assert
|
||||
Mocker.VerifyAllMocks();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_delete_none_existing_files()
|
||||
{
|
||||
var episodes = Builder<EpisodeFile>.CreateListOfSize(10).Build();
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(e => e.FileExists(It.IsAny<String>()))
|
||||
.Returns(false);
|
||||
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
.Setup(e => e.GetEpisodesByFileId(It.IsAny<int>()))
|
||||
.Returns(new List<Episode>());
|
||||
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(e => e.Delete(It.IsAny<int>()));
|
||||
|
||||
|
||||
//Act
|
||||
Mocker.Resolve<DiskScanProvider>().CleanUp(episodes);
|
||||
|
||||
//Assert
|
||||
Mocker.VerifyAllMocks();
|
||||
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
.Verify(e => e.GetEpisodesByFileId(It.IsAny<int>()), Times.Exactly(10));
|
||||
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Verify(e => e.Delete(It.IsAny<int>()), Times.Exactly(10));
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_delete_none_existing_files_remove_links_to_episodes()
|
||||
{
|
||||
var episodes = Builder<EpisodeFile>.CreateListOfSize(10).Build();
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(e => e.FileExists(It.IsAny<String>()))
|
||||
.Returns(false);
|
||||
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
.Setup(e => e.GetEpisodesByFileId(It.IsAny<int>()))
|
||||
.Returns(new List<Episode> { new Episode { EpisodeFile = new EpisodeFile { Id = 10 } }, new Episode { EpisodeFile = new EpisodeFile { Id = 10 } } });
|
||||
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
.Setup(e => e.UpdateEpisode(It.IsAny<Episode>()));
|
||||
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(e => e.Delete(It.IsAny<int>()));
|
||||
|
||||
Mocker.GetMock<IConfigService>()
|
||||
.SetupGet(s => s.AutoIgnorePreviouslyDownloadedEpisodes)
|
||||
.Returns(true);
|
||||
|
||||
//Act
|
||||
Mocker.Resolve<DiskScanProvider>().CleanUp(episodes);
|
||||
|
||||
//Assert
|
||||
Mocker.VerifyAllMocks();
|
||||
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
.Verify(e => e.GetEpisodesByFileId(It.IsAny<int>()), Times.Exactly(10));
|
||||
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
.Verify(e => e.UpdateEpisode(It.Is<Episode>(g => g.EpisodeFileId == 0)), Times.Exactly(20));
|
||||
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Verify(e => e.Delete(It.IsAny<int>()), Times.Exactly(10));
|
||||
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Verify(e => e.Delete(It.IsAny<int>()), Times.Exactly(10));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user