mirror of
https://github.com/Radarr/Radarr.git
synced 2026-04-18 21:35:51 -04:00
Housekeepers talk to the DB directly now
This commit is contained in:
@@ -60,8 +60,6 @@ namespace NzbDrone.Core.Test.Framework
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Category("DbTest")]
|
||||
public abstract class DbTest : CoreTest
|
||||
{
|
||||
|
||||
@@ -42,71 +42,5 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
-12
@@ -1,13 +1,14 @@
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Housekeeping.Housekeepers;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.Test.TvTests.EpisodeRepositoryTests
|
||||
namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
|
||||
{
|
||||
[TestFixture]
|
||||
public class CleanupOrphanedEpisodesFixture : DbTest<EpisodeRepository, Episode>
|
||||
public class CleanupOrphanedEpisodesFixture : DbTest<CleanupOrphanedEpisodes, Episode>
|
||||
{
|
||||
[Test]
|
||||
public void should_delete_orphaned_episodes()
|
||||
@@ -15,9 +16,9 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeRepositoryTests
|
||||
var episode = Builder<Episode>.CreateNew()
|
||||
.BuildNew();
|
||||
|
||||
Subject.Insert(episode);
|
||||
Subject.CleanupOrphanedEpisodes();
|
||||
Subject.All().Should().BeEmpty();
|
||||
Db.Insert(episode);
|
||||
Subject.Clean();
|
||||
AllStoredModels.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -29,16 +30,14 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeRepositoryTests
|
||||
Db.Insert(series);
|
||||
|
||||
var episodes = Builder<Episode>.CreateListOfSize(2)
|
||||
.All()
|
||||
.With(e => e.Id = 0)
|
||||
.TheFirst(1)
|
||||
.With(e => e.SeriesId = series.Id)
|
||||
.Build();
|
||||
.BuildListOfNew();
|
||||
|
||||
Subject.InsertMany(episodes);
|
||||
Subject.CleanupOrphanedEpisodes();
|
||||
Subject.All().Should().HaveCount(1);
|
||||
Subject.All().Should().Contain(e => e.SeriesId == series.Id);
|
||||
Db.InsertMany(episodes);
|
||||
Subject.Clean();
|
||||
AllStoredModels.Should().HaveCount(1);
|
||||
AllStoredModels.Should().Contain(e => e.SeriesId == series.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
using System;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Housekeeping.Housekeepers;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
|
||||
{
|
||||
[TestFixture]
|
||||
public class CleanupOrphanedHistoryItemsFixture : DbTest<CleanupOrphanedHistoryItems, History.History>
|
||||
{
|
||||
private Series _series;
|
||||
private Episode _episode;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_series = Builder<Series>.CreateNew()
|
||||
.BuildNew();
|
||||
|
||||
_episode = Builder<Episode>.CreateNew()
|
||||
.BuildNew();
|
||||
}
|
||||
|
||||
private void GivenSeries()
|
||||
{
|
||||
Db.Insert(_series);
|
||||
}
|
||||
|
||||
private void GivenEpisode()
|
||||
{
|
||||
Db.Insert(_episode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_delete_orphaned_items_by_series()
|
||||
{
|
||||
GivenEpisode();
|
||||
|
||||
var history = Builder<History.History>.CreateNew()
|
||||
.With(h => h.EpisodeId = _episode.Id)
|
||||
.BuildNew();
|
||||
Db.Insert(history);
|
||||
|
||||
Subject.Clean();
|
||||
AllStoredModels.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_delete_orphaned_items_by_episode()
|
||||
{
|
||||
GivenSeries();
|
||||
|
||||
var history = Builder<History.History>.CreateNew()
|
||||
.With(h => h.SeriesId = _series.Id)
|
||||
.BuildNew();
|
||||
Db.Insert(history);
|
||||
|
||||
Subject.Clean();
|
||||
AllStoredModels.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_delete_unorphaned_data_by_series()
|
||||
{
|
||||
GivenSeries();
|
||||
GivenEpisode();
|
||||
|
||||
var history = Builder<History.History>.CreateListOfSize(2)
|
||||
.All()
|
||||
.With(h => h.EpisodeId = _episode.Id)
|
||||
.TheFirst(1)
|
||||
.With(h => h.SeriesId = _series.Id)
|
||||
.BuildListOfNew();
|
||||
|
||||
Db.InsertMany(history);
|
||||
|
||||
Subject.Clean();
|
||||
AllStoredModels.Should().HaveCount(1);
|
||||
AllStoredModels.Should().Contain(h => h.SeriesId == _series.Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_delete_unorphaned_data_by_episode()
|
||||
{
|
||||
GivenSeries();
|
||||
GivenEpisode();
|
||||
|
||||
var history = Builder<History.History>.CreateListOfSize(2)
|
||||
.All()
|
||||
.With(h => h.SeriesId = _series.Id)
|
||||
.TheFirst(1)
|
||||
.With(h => h.EpisodeId = _episode.Id)
|
||||
.BuildListOfNew();
|
||||
|
||||
Db.InsertMany(history);
|
||||
|
||||
Subject.Clean();
|
||||
AllStoredModels.Should().HaveCount(1);
|
||||
AllStoredModels.Should().Contain(h => h.EpisodeId == _episode.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -125,6 +125,7 @@
|
||||
<Compile Include="Framework\CoreTest.cs" />
|
||||
<Compile Include="Framework\DbTest.cs" />
|
||||
<Compile Include="Framework\NBuilderExtensions.cs" />
|
||||
<Compile Include="Housekeeping\Housekeepers\CleanupOrphanedHistoryItemsFixture.cs" />
|
||||
<Compile Include="IndexerSearchTests\SearchDefinitionFixture.cs" />
|
||||
<Compile Include="IndexerTests\BasicRssParserFixture.cs" />
|
||||
<Compile Include="IndexerTests\IndexerServiceFixture.cs" />
|
||||
@@ -179,7 +180,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="Housekeeping\Housekeepers\CleanupOrphanedEpisodesFixture.cs" />
|
||||
<Compile Include="TvTests\RefreshEpisodeServiceFixture.cs" />
|
||||
<Compile Include="TvTests\EpisodeProviderTests\HandleEpisodeFileDeletedFixture.cs" />
|
||||
<Compile Include="TvTests\EpisodeRepositoryTests\FindEpisodeFixture.cs" />
|
||||
|
||||
Reference in New Issue
Block a user