2021-12-25 01:55:32 +00:00
|
|
|
using FizzWare.NBuilder;
|
2013-09-19 00:28:25 +00:00
|
|
|
using FluentAssertions;
|
|
|
|
using NUnit.Framework;
|
2021-12-25 01:55:32 +00:00
|
|
|
using NzbDrone.Core.History;
|
2013-09-19 00:28:25 +00:00
|
|
|
using NzbDrone.Core.Housekeeping.Housekeepers;
|
2020-01-03 12:49:24 +00:00
|
|
|
using NzbDrone.Core.Music;
|
2014-07-28 11:16:40 +00:00
|
|
|
using NzbDrone.Core.Qualities;
|
2013-09-19 00:28:25 +00:00
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
|
|
|
|
{
|
|
|
|
[TestFixture]
|
2021-12-25 01:55:32 +00:00
|
|
|
public class CleanupOrphanedHistoryItemsFixture : DbTest<CleanupOrphanedHistoryItems, EntityHistory>
|
2013-09-19 00:28:25 +00:00
|
|
|
{
|
2017-08-14 02:58:42 +00:00
|
|
|
private Artist _artist;
|
|
|
|
private Album _album;
|
2013-09-19 00:28:25 +00:00
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void Setup()
|
|
|
|
{
|
2017-08-14 02:58:42 +00:00
|
|
|
_artist = Builder<Artist>.CreateNew()
|
2013-09-19 00:28:25 +00:00
|
|
|
.BuildNew();
|
|
|
|
|
2017-08-14 02:58:42 +00:00
|
|
|
_album = Builder<Album>.CreateNew()
|
2018-12-15 00:02:43 +00:00
|
|
|
.BuildNew();
|
2013-09-19 00:28:25 +00:00
|
|
|
}
|
|
|
|
|
2017-08-14 02:58:42 +00:00
|
|
|
private void GivenArtist()
|
2013-09-19 00:28:25 +00:00
|
|
|
{
|
2017-08-14 02:58:42 +00:00
|
|
|
Db.Insert(_artist);
|
2013-09-19 00:28:25 +00:00
|
|
|
}
|
|
|
|
|
2017-08-14 02:58:42 +00:00
|
|
|
private void GivenAlbum()
|
2013-09-19 00:28:25 +00:00
|
|
|
{
|
2017-08-14 02:58:42 +00:00
|
|
|
Db.Insert(_album);
|
2013-09-19 00:28:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2017-08-14 02:58:42 +00:00
|
|
|
public void should_delete_orphaned_items_by_artist()
|
2013-09-19 00:28:25 +00:00
|
|
|
{
|
2017-08-14 02:58:42 +00:00
|
|
|
GivenAlbum();
|
2013-09-19 00:28:25 +00:00
|
|
|
|
2021-12-25 01:55:32 +00:00
|
|
|
var history = Builder<EntityHistory>.CreateNew()
|
2014-07-28 11:16:40 +00:00
|
|
|
.With(h => h.Quality = new QualityModel())
|
2017-08-14 02:58:42 +00:00
|
|
|
.With(h => h.AlbumId = _album.Id)
|
2013-09-19 00:28:25 +00:00
|
|
|
.BuildNew();
|
|
|
|
Db.Insert(history);
|
|
|
|
|
|
|
|
Subject.Clean();
|
|
|
|
AllStoredModels.Should().BeEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2017-08-14 02:58:42 +00:00
|
|
|
public void should_delete_orphaned_items_by_album()
|
2013-09-19 00:28:25 +00:00
|
|
|
{
|
2017-08-14 02:58:42 +00:00
|
|
|
GivenArtist();
|
2013-09-19 00:28:25 +00:00
|
|
|
|
2021-12-25 01:55:32 +00:00
|
|
|
var history = Builder<EntityHistory>.CreateNew()
|
2014-07-28 11:16:40 +00:00
|
|
|
.With(h => h.Quality = new QualityModel())
|
2017-08-14 02:58:42 +00:00
|
|
|
.With(h => h.ArtistId = _artist.Id)
|
2013-09-19 00:28:25 +00:00
|
|
|
.BuildNew();
|
|
|
|
Db.Insert(history);
|
|
|
|
|
|
|
|
Subject.Clean();
|
|
|
|
AllStoredModels.Should().BeEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2017-08-14 02:58:42 +00:00
|
|
|
public void should_not_delete_unorphaned_data_by_artist()
|
2013-09-19 00:28:25 +00:00
|
|
|
{
|
2017-08-14 02:58:42 +00:00
|
|
|
GivenArtist();
|
|
|
|
GivenAlbum();
|
2013-09-19 00:28:25 +00:00
|
|
|
|
2021-12-25 01:55:32 +00:00
|
|
|
var history = Builder<EntityHistory>.CreateListOfSize(2)
|
2013-09-19 00:28:25 +00:00
|
|
|
.All()
|
2014-07-28 11:16:40 +00:00
|
|
|
.With(h => h.Quality = new QualityModel())
|
2017-08-14 02:58:42 +00:00
|
|
|
.With(h => h.AlbumId = _album.Id)
|
2013-09-19 00:28:25 +00:00
|
|
|
.TheFirst(1)
|
2017-08-14 02:58:42 +00:00
|
|
|
.With(h => h.ArtistId = _artist.Id)
|
2013-09-19 00:28:25 +00:00
|
|
|
.BuildListOfNew();
|
|
|
|
|
|
|
|
Db.InsertMany(history);
|
|
|
|
|
|
|
|
Subject.Clean();
|
|
|
|
AllStoredModels.Should().HaveCount(1);
|
2017-08-14 02:58:42 +00:00
|
|
|
AllStoredModels.Should().Contain(h => h.ArtistId == _artist.Id);
|
2013-09-19 00:28:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2017-08-14 02:58:42 +00:00
|
|
|
public void should_not_delete_unorphaned_data_by_album()
|
2013-09-19 00:28:25 +00:00
|
|
|
{
|
2017-08-14 02:58:42 +00:00
|
|
|
GivenArtist();
|
|
|
|
GivenAlbum();
|
2013-09-19 00:28:25 +00:00
|
|
|
|
2021-12-25 01:55:32 +00:00
|
|
|
var history = Builder<EntityHistory>.CreateListOfSize(2)
|
2013-09-19 00:28:25 +00:00
|
|
|
.All()
|
2014-07-28 11:16:40 +00:00
|
|
|
.With(h => h.Quality = new QualityModel())
|
2017-08-14 02:58:42 +00:00
|
|
|
.With(h => h.ArtistId = _artist.Id)
|
2013-09-19 00:28:25 +00:00
|
|
|
.TheFirst(1)
|
2017-08-14 02:58:42 +00:00
|
|
|
.With(h => h.AlbumId = _album.Id)
|
2013-09-19 00:28:25 +00:00
|
|
|
.BuildListOfNew();
|
|
|
|
|
|
|
|
Db.InsertMany(history);
|
|
|
|
|
|
|
|
Subject.Clean();
|
|
|
|
AllStoredModels.Should().HaveCount(1);
|
2017-08-14 02:58:42 +00:00
|
|
|
AllStoredModels.Should().Contain(h => h.AlbumId == _album.Id);
|
2013-09-19 00:28:25 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-15 00:02:43 +00:00
|
|
|
}
|