using System.Collections.Generic; using FizzWare.NBuilder; using FluentAssertions; using NUnit.Framework; using NzbDrone.Core.History; using NzbDrone.Core.Housekeeping.Housekeepers; using NzbDrone.Core.Languages; using NzbDrone.Core.Movies; using NzbDrone.Core.Qualities; using NzbDrone.Core.Test.Framework; namespace NzbDrone.Core.Test.Housekeeping.Housekeepers { [TestFixture] public class CleanupOrphanedHistoryItemsFixture : DbTest { private Movie _movie; [SetUp] public void Setup() { _movie = Builder.CreateNew() .BuildNew(); } private void GivenSeries() { Db.Insert(_movie); } [Test] public void should_delete_orphaned_items() { var history = Builder.CreateNew() .With(h => h.Quality = new QualityModel()) .With(h => h.Languages = new List()) .BuildNew(); Db.Insert(history); Subject.Clean(); AllStoredModels.Should().BeEmpty(); } [Test] public void should_not_delete_unorphaned() { GivenSeries(); var history = Builder.CreateNew() .With(h => h.Quality = new QualityModel()) .With(h => h.Languages = new List()) .With(h => h.MovieId = _movie.Id) .BuildNew(); Db.Insert(history); Subject.Clean(); AllStoredModels.Should().HaveCount(1); } } }