2012-08-29 15:34:51 +00:00
|
|
|
|
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;
|
2013-02-24 06:48:52 +00:00
|
|
|
|
using NzbDrone.Core.Configuration;
|
2013-02-19 06:01:03 +00:00
|
|
|
|
using NzbDrone.Core.Tv;
|
2012-08-29 15:34:51 +00:00
|
|
|
|
using NzbDrone.Core.Model;
|
|
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
|
using NzbDrone.Core.Providers.Core;
|
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
using NzbDrone.Test.Common;
|
|
|
|
|
using NzbDrone.Test.Common.AutoMoq;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
|
|
|
|
|
{
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
2013-02-17 05:44:06 +00:00
|
|
|
|
public class CleanUpFixture : CoreTest
|
2012-08-29 15:34:51 +00:00
|
|
|
|
{
|
|
|
|
|
[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);
|
|
|
|
|
|
2013-02-22 00:47:09 +00:00
|
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2012-08-29 15:34:51 +00:00
|
|
|
|
.Setup(e => e.GetEpisodesByFileId(It.IsAny<int>()))
|
|
|
|
|
.Returns(new List<Episode>());
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<MediaFileProvider>()
|
|
|
|
|
.Setup(e => e.Delete(It.IsAny<int>()));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
Mocker.Resolve<DiskScanProvider>().CleanUp(episodes);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
Mocker.VerifyAllMocks();
|
|
|
|
|
|
2013-02-22 00:47:09 +00:00
|
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2012-08-29 15:34:51 +00:00
|
|
|
|
.Verify(e => e.GetEpisodesByFileId(It.IsAny<int>()), Times.Exactly(10));
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<MediaFileProvider>()
|
|
|
|
|
.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);
|
|
|
|
|
|
2013-02-22 00:47:09 +00:00
|
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2012-08-29 15:34:51 +00:00
|
|
|
|
.Setup(e => e.GetEpisodesByFileId(It.IsAny<int>()))
|
2013-02-20 02:05:15 +00:00
|
|
|
|
.Returns(new List<Episode> { new Episode { EpisodeFile = new EpisodeFile { EpisodeFileId = 10 } }, new Episode { EpisodeFile = new EpisodeFile { EpisodeFileId = 10 } } });
|
2012-08-29 15:34:51 +00:00
|
|
|
|
|
2013-02-22 00:47:09 +00:00
|
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2012-08-29 15:34:51 +00:00
|
|
|
|
.Setup(e => e.UpdateEpisode(It.IsAny<Episode>()));
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<MediaFileProvider>()
|
|
|
|
|
.Setup(e => e.Delete(It.IsAny<int>()));
|
|
|
|
|
|
2013-02-24 19:39:31 +00:00
|
|
|
|
Mocker.GetMock<IConfigService>()
|
2012-08-29 15:34:51 +00:00
|
|
|
|
.SetupGet(s => s.AutoIgnorePreviouslyDownloadedEpisodes)
|
|
|
|
|
.Returns(true);
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
Mocker.Resolve<DiskScanProvider>().CleanUp(episodes);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
Mocker.VerifyAllMocks();
|
|
|
|
|
|
2013-02-22 00:47:09 +00:00
|
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2012-08-29 15:34:51 +00:00
|
|
|
|
.Verify(e => e.GetEpisodesByFileId(It.IsAny<int>()), Times.Exactly(10));
|
|
|
|
|
|
2013-02-22 00:47:09 +00:00
|
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2013-02-20 02:05:15 +00:00
|
|
|
|
.Verify(e => e.UpdateEpisode(It.Is<Episode>(g => g.EpisodeFileId == 0)), Times.Exactly(20));
|
2012-08-29 15:34:51 +00:00
|
|
|
|
|
|
|
|
|
Mocker.GetMock<MediaFileProvider>()
|
|
|
|
|
.Verify(e => e.Delete(It.IsAny<int>()), Times.Exactly(10));
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<MediaFileProvider>()
|
|
|
|
|
.Verify(e => e.Delete(It.IsAny<int>()), Times.Exactly(10));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|