1
0
mirror of https://github.com/Radarr/Radarr.git synced 2026-04-18 21:35:51 -04:00

Added housekeeping to cleanup orphaned episodes and history items

This commit is contained in:
Mark McDowall
2013-09-17 22:28:05 -07:00
parent 174689f533
commit 07b68b17ee
14 changed files with 286 additions and 2 deletions
@@ -4,6 +4,7 @@ using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.History;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Test.HistoryTests
{
@@ -41,5 +42,71 @@ namespace NzbDrone.Core.Test.HistoryTests
StoredModel.Data.Should().HaveCount(2);
}
[Test]
public void should_delete_orphaned_items_by_series()
{
var history = Builder<History.History>.CreateNew().BuildNew();
Subject.Insert(history);
Subject.CleanupOrphanedBySeries();
Subject.All().Should().BeEmpty();
}
[Test]
public void should_delete_orphaned_items_by_episode()
{
var history = Builder<History.History>.CreateNew().BuildNew();
Subject.Insert(history);
Subject.CleanupOrphanedByEpisode();
Subject.All().Should().BeEmpty();
}
[Test]
public void should_not_delete_unorphaned_data_by_series()
{
var series = Builder<Series>.CreateNew()
.BuildNew();
Db.Insert(series);
var history = Builder<History.History>.CreateListOfSize(2)
.All()
.With(h => h.Id = 0)
.TheFirst(1)
.With(h => h.SeriesId = series.Id)
.Build();
Subject.InsertMany(history);
Subject.CleanupOrphanedBySeries();
Subject.All().Should().HaveCount(1);
Subject.All().Should().Contain(h => h.SeriesId == series.Id);
}
[Test]
public void should_not_delete_unorphaned_data_by_episode()
{
var episode = Builder<Episode>.CreateNew()
.BuildNew();
Db.Insert(episode);
var history = Builder<History.History>.CreateListOfSize(2)
.All()
.With(h => h.Id = 0)
.TheFirst(1)
.With(h => h.EpisodeId = episode.Id)
.Build();
Subject.InsertMany(history);
Subject.CleanupOrphanedByEpisode();
Subject.All().Should().HaveCount(1);
Subject.All().Should().Contain(h => h.EpisodeId == episode.Id);
}
}
}
@@ -179,6 +179,7 @@
<Compile Include="ProviderTests\RecycleBinProviderTests\DeleteFileFixture.cs" />
<Compile Include="ProviderTests\RecycleBinProviderTests\DeleteDirectoryFixture.cs" />
<Compile Include="NotificationTests\PlexProviderTest.cs" />
<Compile Include="TvTests\EpisodeRepositoryTests\CleanupOrphanedEpisodesFixture.cs" />
<Compile Include="TvTests\RefreshEpisodeServiceFixture.cs" />
<Compile Include="TvTests\EpisodeProviderTests\HandleEpisodeFileDeletedFixture.cs" />
<Compile Include="TvTests\EpisodeRepositoryTests\FindEpisodeFixture.cs" />
@@ -0,0 +1,44 @@
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Test.TvTests.EpisodeRepositoryTests
{
[TestFixture]
public class CleanupOrphanedEpisodesFixture : DbTest<EpisodeRepository, Episode>
{
[Test]
public void should_delete_orphaned_episodes()
{
var episode = Builder<Episode>.CreateNew()
.BuildNew();
Subject.Insert(episode);
Subject.CleanupOrphanedEpisodes();
Subject.All().Should().BeEmpty();
}
[Test]
public void should_not_delete_unorphaned_episodes()
{
var series = Builder<Series>.CreateNew()
.BuildNew();
Db.Insert(series);
var episodes = Builder<Episode>.CreateListOfSize(2)
.All()
.With(e => e.Id = 0)
.TheFirst(1)
.With(e => e.SeriesId = series.Id)
.Build();
Subject.InsertMany(episodes);
Subject.CleanupOrphanedEpisodes();
Subject.All().Should().HaveCount(1);
Subject.All().Should().Contain(e => e.SeriesId == series.Id);
}
}
}