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