2013-09-18 08:28:05 +03:00
|
|
|
using FizzWare.NBuilder;
|
|
|
|
using FluentAssertions;
|
|
|
|
using NUnit.Framework;
|
2013-09-19 03:28:25 +03:00
|
|
|
using NzbDrone.Core.Housekeeping.Housekeepers;
|
2013-09-18 08:28:05 +03:00
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
using NzbDrone.Core.Tv;
|
|
|
|
|
2013-09-19 03:28:25 +03:00
|
|
|
namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
|
2013-09-18 08:28:05 +03:00
|
|
|
{
|
|
|
|
[TestFixture]
|
2013-09-19 03:28:25 +03:00
|
|
|
public class CleanupOrphanedEpisodesFixture : DbTest<CleanupOrphanedEpisodes, Episode>
|
2013-09-18 08:28:05 +03:00
|
|
|
{
|
|
|
|
[Test]
|
|
|
|
public void should_delete_orphaned_episodes()
|
|
|
|
{
|
|
|
|
var episode = Builder<Episode>.CreateNew()
|
|
|
|
.BuildNew();
|
|
|
|
|
2013-09-19 03:28:25 +03:00
|
|
|
Db.Insert(episode);
|
|
|
|
Subject.Clean();
|
|
|
|
AllStoredModels.Should().BeEmpty();
|
2013-09-18 08:28:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_not_delete_unorphaned_episodes()
|
|
|
|
{
|
|
|
|
var series = Builder<Series>.CreateNew()
|
|
|
|
.BuildNew();
|
|
|
|
|
|
|
|
Db.Insert(series);
|
|
|
|
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(2)
|
|
|
|
.TheFirst(1)
|
|
|
|
.With(e => e.SeriesId = series.Id)
|
2013-09-19 03:28:25 +03:00
|
|
|
.BuildListOfNew();
|
2013-09-18 08:28:05 +03:00
|
|
|
|
2013-09-19 03:28:25 +03:00
|
|
|
Db.InsertMany(episodes);
|
|
|
|
Subject.Clean();
|
|
|
|
AllStoredModels.Should().HaveCount(1);
|
|
|
|
AllStoredModels.Should().Contain(e => e.SeriesId == series.Id);
|
2013-09-18 08:28:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|