1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-14 06:52:36 +01:00
Radarr/NzbDrone.Core.Test/DiskScanProviderTest.cs

142 lines
4.3 KiB
C#
Raw Normal View History

2011-06-21 07:44:01 +02:00
using System;
using System.Collections.Generic;
using AutoMoq;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
2011-06-22 03:12:20 +02:00
using NzbDrone.Core.Model;
2011-06-21 07:44:01 +02:00
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Quality;
using NzbDrone.Core.Test.Framework;
using PetaPoco;
namespace NzbDrone.Core.Test
{
// ReSharper disable InconsistentNaming
public class DiskScanProviderTest : TestBase
{
2011-06-21 07:44:01 +02:00
[Test]
public void scan_series_should_update_last_scan_date()
2011-06-21 07:44:01 +02:00
{
var mocker = new AutoMoqer();
mocker.GetMock<SeriesProvider>()
.Setup(c => c.UpdateSeries(It.Is<Series>(s => s.LastDiskSync != null))).Verifiable();
2011-06-21 07:44:01 +02:00
mocker.GetMock<EpisodeProvider>()
.Setup(c => c.GetEpisodeBySeries(It.IsAny<long>()))
.Returns(new List<Episode> { new Episode() });
2011-06-21 07:44:01 +02:00
mocker.GetMock<MediaFileProvider>()
.Setup(c => c.GetSeriesFiles(It.IsAny<int>()))
.Returns(new List<EpisodeFile>());
2011-06-21 07:44:01 +02:00
mocker.Resolve<DiskScanProvider>().Scan(new Series());
2011-06-21 07:44:01 +02:00
mocker.VerifyAllMocks();
2011-06-21 07:44:01 +02:00
2011-06-22 03:12:20 +02:00
}
2011-06-21 07:44:01 +02:00
[Test]
public void cleanup_should_skip_existing_files()
2011-06-21 07:44:01 +02:00
{
var mocker = new AutoMoqer(MockBehavior.Strict);
var episodes = Builder<EpisodeFile>.CreateListOfSize(10).Build();
2011-06-21 07:44:01 +02:00
mocker.GetMock<DiskProvider>()
.Setup(e => e.FileExists(It.IsAny<String>()))
.Returns(true);
2011-06-21 07:44:01 +02:00
//Act
mocker.Resolve<DiskScanProvider>().CleanUp(episodes);
2011-06-21 07:44:01 +02:00
//Assert
mocker.VerifyAllMocks();
2011-06-21 07:44:01 +02:00
}
[Test]
public void cleanup_should_delete_none_existing_files()
2011-06-21 07:44:01 +02:00
{
var mocker = new AutoMoqer(MockBehavior.Strict);
var episodes = Builder<EpisodeFile>.CreateListOfSize(10).Build();
2011-06-21 07:44:01 +02:00
mocker.GetMock<DiskProvider>()
.Setup(e => e.FileExists(It.IsAny<String>()))
.Returns(false);
2011-06-22 03:12:20 +02:00
mocker.GetMock<EpisodeProvider>()
.Setup(e => e.GetEpisodesByFileId(It.IsAny<int>()))
.Returns(new List<Episode>());
2011-06-21 07:44:01 +02:00
2011-06-22 03:12:20 +02:00
mocker.GetMock<MediaFileProvider>()
.Setup(e => e.Delete(It.IsAny<int>()));
2011-06-21 07:44:01 +02:00
//Act
mocker.Resolve<DiskScanProvider>().CleanUp(episodes);
2011-06-21 07:44:01 +02:00
//Assert
mocker.VerifyAllMocks();
2011-06-21 07:44:01 +02:00
mocker.GetMock<EpisodeProvider>()
.Verify(e => e.GetEpisodesByFileId(It.IsAny<int>()), Times.Exactly(10));
2011-06-21 07:44:01 +02:00
2011-06-22 03:12:20 +02:00
mocker.GetMock<MediaFileProvider>()
.Verify(e => e.Delete(It.IsAny<int>()), Times.Exactly(10));
2011-06-21 07:44:01 +02:00
}
2011-06-21 07:44:01 +02:00
[Test]
public void cleanup_should_delete_none_existing_files_remove_links_to_episodes()
2011-06-21 07:44:01 +02:00
{
2011-06-22 03:12:20 +02:00
var mocker = new AutoMoqer(MockBehavior.Strict);
var episodes = Builder<EpisodeFile>.CreateListOfSize(10).Build();
2011-06-21 07:44:01 +02:00
mocker.GetMock<DiskProvider>()
.Setup(e => e.FileExists(It.IsAny<String>()))
.Returns(false);
2011-06-21 07:44:01 +02: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 07:44:01 +02:00
mocker.GetMock<EpisodeProvider>()
.Setup(e => e.UpdateEpisode(It.IsAny<Episode>()));
2011-06-21 07:44:01 +02:00
2011-06-22 03:12:20 +02:00
mocker.GetMock<MediaFileProvider>()
.Setup(e => e.Delete(It.IsAny<int>()));
2011-06-22 03:12:20 +02:00
2011-06-21 07:44:01 +02:00
//Act
mocker.Resolve<DiskScanProvider>().CleanUp(episodes);
2011-06-21 07:44:01 +02:00
//Assert
mocker.VerifyAllMocks();
2011-06-21 07:44:01 +02:00
mocker.GetMock<EpisodeProvider>()
.Verify(e => e.GetEpisodesByFileId(It.IsAny<int>()), Times.Exactly(10));
2011-06-21 07:44:01 +02:00
mocker.GetMock<EpisodeProvider>()
.Verify(e => e.UpdateEpisode(It.Is<Episode>(g=>g.EpisodeFileId == 0)), Times.Exactly(20));
mocker.GetMock<MediaFileProvider>()
.Verify(e => e.Delete(It.IsAny<int>()), Times.Exactly(10));
2011-06-21 07:44:01 +02:00
mocker.GetMock<MediaFileProvider>()
.Verify(e => e.Delete(It.IsAny<int>()), Times.Exactly(10));
2011-06-21 07:44:01 +02:00
}
2011-06-22 03:12:20 +02:00
2011-06-21 07:44:01 +02:00
}
}