From 62de7b63bd6f3eb37baf800839c04e9c7f9d6c51 Mon Sep 17 00:00:00 2001 From: Qstick Date: Sun, 24 May 2020 22:37:05 -0400 Subject: [PATCH] Add Test Fixture for Alt Title Housekeeper --- ...CleanupOrphanedAlternativeTitlesFixture.cs | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/NzbDrone.Core.Test/Housekeeping/Housekeepers/CleanupOrphanedAlternativeTitlesFixture.cs diff --git a/src/NzbDrone.Core.Test/Housekeeping/Housekeepers/CleanupOrphanedAlternativeTitlesFixture.cs b/src/NzbDrone.Core.Test/Housekeeping/Housekeepers/CleanupOrphanedAlternativeTitlesFixture.cs new file mode 100644 index 000000000..d8ec063ab --- /dev/null +++ b/src/NzbDrone.Core.Test/Housekeeping/Housekeepers/CleanupOrphanedAlternativeTitlesFixture.cs @@ -0,0 +1,47 @@ +using FizzWare.NBuilder; +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Core.Housekeeping.Housekeepers; +using NzbDrone.Core.Languages; +using NzbDrone.Core.Movies; +using NzbDrone.Core.Movies.AlternativeTitles; +using NzbDrone.Core.Test.Framework; + +namespace NzbDrone.Core.Test.Housekeeping.Housekeepers +{ + [TestFixture] + public class CleanupOrphanedAlternativeTitleFixture : DbTest + { + [Test] + public void should_delete_orphaned_alternative_title_items() + { + var altTitle = Builder.CreateNew() + .With(h => h.MovieId = default) + .With(h => h.Language = Language.English) + .BuildNew(); + + Db.Insert(altTitle); + Subject.Clean(); + AllStoredModels.Should().BeEmpty(); + } + + [Test] + public void should_not_delete_unorphaned_alternative_title_items() + { + var movie = Builder.CreateNew().BuildNew(); + + Db.Insert(movie); + + var altTitle = Builder.CreateNew() + .With(h => h.MovieId = default) + .With(h => h.Language = Language.English) + .With(b => b.MovieId = movie.Id) + .BuildNew(); + + Db.Insert(altTitle); + + Subject.Clean(); + AllStoredModels.Should().HaveCount(1); + } + } +}