1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00
Sonarr/NzbDrone.Core.Test/TvTests/EpisodeRepositoryTests/CleanupOrphanedEpisodesFixture.cs

45 lines
1.4 KiB
C#
Raw Normal View History

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);
}
}
}