|
|
@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
using NzbDrone.Core.Housekeeping.Housekeepers;
|
|
|
|
|
|
|
|
using NzbDrone.Core.MediaFiles;
|
|
|
|
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
|
|
|
using NzbDrone.Core.Tv;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
[TestFixture]
|
|
|
|
|
|
|
|
public class CleanupOrphanedEpisodeFilesFixture : DbTest<CleanupOrphanedEpisodeFiles, EpisodeFile>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
|
|
public void should_delete_orphaned_episode_files()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var episodeFile = Builder<EpisodeFile>.CreateNew()
|
|
|
|
|
|
|
|
.BuildNew();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Db.Insert(episodeFile);
|
|
|
|
|
|
|
|
Subject.Clean();
|
|
|
|
|
|
|
|
AllStoredModels.Should().BeEmpty();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
|
|
public void should_not_delete_unorphaned_episode_files()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(2)
|
|
|
|
|
|
|
|
.BuildListOfNew();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Db.InsertMany(episodeFiles);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var episode = Builder<Episode>.CreateNew()
|
|
|
|
|
|
|
|
.With(e => e.EpisodeFileId = episodeFiles.First().Id)
|
|
|
|
|
|
|
|
.BuildNew();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Db.Insert(episode);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Subject.Clean();
|
|
|
|
|
|
|
|
AllStoredModels.Should().HaveCount(1);
|
|
|
|
|
|
|
|
Db.All<Episode>().Should().Contain(e => e.EpisodeFileId == AllStoredModels.First().Id);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|