2014-02-14 23:15:45 +00:00
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using NzbDrone.Core.Datastore;
|
2014-06-08 08:22:55 +00:00
|
|
|
|
using NzbDrone.Core.Profiles;
|
2014-02-14 23:15:45 +00:00
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
using NzbDrone.Core.Tv;
|
|
|
|
|
using NzbDrone.Core.Qualities;
|
|
|
|
|
using NzbDrone.Core.MediaFiles;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.Datastore
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public class MarrDataLazyLoadingFixture : DbTest
|
|
|
|
|
{
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
2014-06-08 08:22:55 +00:00
|
|
|
|
var profile = new Profile
|
2014-02-14 23:15:45 +00:00
|
|
|
|
{
|
|
|
|
|
Name = "Test",
|
|
|
|
|
Cutoff = Quality.WEBDL720p,
|
2014-06-08 08:22:55 +00:00
|
|
|
|
Items = Qualities.QualityFixture.GetDefaultQualities()
|
2014-02-14 23:15:45 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2014-06-08 08:22:55 +00:00
|
|
|
|
profile = Db.Insert(profile);
|
2014-02-14 23:15:45 +00:00
|
|
|
|
|
|
|
|
|
var series = Builder<Series>.CreateListOfSize(1)
|
|
|
|
|
.All()
|
2014-06-08 08:22:55 +00:00
|
|
|
|
.With(v => v.ProfileId = profile.Id)
|
2014-02-14 23:15:45 +00:00
|
|
|
|
.BuildListOfNew();
|
|
|
|
|
|
|
|
|
|
Db.InsertMany(series);
|
|
|
|
|
|
|
|
|
|
var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(1)
|
|
|
|
|
.All()
|
|
|
|
|
.With(v => v.SeriesId = series[0].Id)
|
|
|
|
|
.BuildListOfNew();
|
|
|
|
|
|
|
|
|
|
Db.InsertMany(episodeFiles);
|
|
|
|
|
|
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(10)
|
|
|
|
|
.All()
|
|
|
|
|
.With(v => v.Monitored = true)
|
|
|
|
|
.With(v => v.EpisodeFileId = episodeFiles[0].Id)
|
|
|
|
|
.With(v => v.SeriesId = series[0].Id)
|
|
|
|
|
.BuildListOfNew();
|
|
|
|
|
|
|
|
|
|
Db.InsertMany(episodes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2014-06-08 08:22:55 +00:00
|
|
|
|
public void should_lazy_load_profile_if_not_joined()
|
2014-02-14 23:15:45 +00:00
|
|
|
|
{
|
|
|
|
|
var db = Mocker.Resolve<IDatabase>();
|
|
|
|
|
var DataMapper = db.GetDataMapper();
|
|
|
|
|
|
|
|
|
|
var episodes = DataMapper.Query<Episode>()
|
|
|
|
|
.Join<Episode, Series>(Marr.Data.QGen.JoinType.Inner, v => v.Series, (l, r) => l.SeriesId == r.Id)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
foreach (var episode in episodes)
|
|
|
|
|
{
|
|
|
|
|
Assert.IsNotNull(episode.Series);
|
2014-06-08 08:22:55 +00:00
|
|
|
|
Assert.IsFalse(episode.Series.Profile.IsLoaded);
|
2014-02-14 23:15:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_explicit_load_episodefile_if_joined()
|
|
|
|
|
{
|
|
|
|
|
var db = Mocker.Resolve<IDatabase>();
|
|
|
|
|
var DataMapper = db.GetDataMapper();
|
|
|
|
|
|
|
|
|
|
var episodes = DataMapper.Query<Episode>()
|
|
|
|
|
.Join<Episode, EpisodeFile>(Marr.Data.QGen.JoinType.Inner, v => v.EpisodeFile, (l, r) => l.EpisodeFileId == r.Id)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
foreach (var episode in episodes)
|
|
|
|
|
{
|
|
|
|
|
Assert.IsNull(episode.Series);
|
|
|
|
|
Assert.IsTrue(episode.EpisodeFile.IsLoaded);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2014-06-08 08:22:55 +00:00
|
|
|
|
public void should_explicit_load_profile_if_joined()
|
2014-02-14 23:15:45 +00:00
|
|
|
|
{
|
|
|
|
|
var db = Mocker.Resolve<IDatabase>();
|
|
|
|
|
var DataMapper = db.GetDataMapper();
|
|
|
|
|
|
|
|
|
|
var episodes = DataMapper.Query<Episode>()
|
|
|
|
|
.Join<Episode, Series>(Marr.Data.QGen.JoinType.Inner, v => v.Series, (l, r) => l.SeriesId == r.Id)
|
2014-06-08 08:22:55 +00:00
|
|
|
|
.Join<Series, Profile>(Marr.Data.QGen.JoinType.Inner, v => v.Profile, (l, r) => l.ProfileId == r.Id)
|
2014-02-14 23:15:45 +00:00
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
foreach (var episode in episodes)
|
|
|
|
|
{
|
|
|
|
|
Assert.IsNotNull(episode.Series);
|
2014-06-08 08:22:55 +00:00
|
|
|
|
Assert.IsTrue(episode.Series.Profile.IsLoaded);
|
2014-02-14 23:15:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|