mirror of https://github.com/Sonarr/Sonarr
Added tests to verify Marr.data changes. Fixed nested LazyLoading.
This commit is contained in:
parent
8f87f06ac6
commit
45f748cf03
|
@ -556,8 +556,14 @@ namespace Marr.Data.QGen
|
||||||
_isJoin = true;
|
_isJoin = true;
|
||||||
MemberInfo rightMember = (rightEntity.Body as MemberExpression).Member;
|
MemberInfo rightMember = (rightEntity.Body as MemberExpression).Member;
|
||||||
|
|
||||||
var relationship = EntGraph.Relationships.Single(v => v.Member == rightMember);
|
foreach (var item in EntGraph)
|
||||||
EntGraph.AddLazyRelationship(relationship);
|
{
|
||||||
|
if (item.EntityType == typeof(TLeft))
|
||||||
|
{
|
||||||
|
var relationship = item.Relationships.Single(v => v.Member == rightMember);
|
||||||
|
item.AddLazyRelationship(relationship);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return Join(joinType, rightMember, filterExpression);
|
return Join(joinType, rightMember, filterExpression);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,105 @@
|
||||||
|
using FizzWare.NBuilder;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Core.Datastore;
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
var qualityProfile = new NzbDrone.Core.Qualities.QualityProfile
|
||||||
|
{
|
||||||
|
Name = "Test",
|
||||||
|
Cutoff = Quality.WEBDL720p,
|
||||||
|
Items = NzbDrone.Core.Test.Qualities.QualityFixture.GetDefaultQualities()
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
qualityProfile = Db.Insert(qualityProfile);
|
||||||
|
|
||||||
|
var series = Builder<Series>.CreateListOfSize(1)
|
||||||
|
.All()
|
||||||
|
.With(v => v.QualityProfileId = qualityProfile.Id)
|
||||||
|
.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]
|
||||||
|
public void should_lazy_load_qualityprofile_if_not_joined()
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
Assert.IsFalse(episode.Series.QualityProfile.IsLoaded);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[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]
|
||||||
|
public void should_explicit_load_qualityprofile_if_joined()
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
.Join<Series, QualityProfile>(Marr.Data.QGen.JoinType.Inner, v => v.QualityProfile, (l, r) => l.QualityProfileId == r.Id)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
foreach (var episode in episodes)
|
||||||
|
{
|
||||||
|
Assert.IsNotNull(episode.Series);
|
||||||
|
Assert.IsTrue(episode.Series.QualityProfile.IsLoaded);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -104,6 +104,7 @@
|
||||||
<Compile Include="Blacklisting\BlacklistRepositoryFixture.cs" />
|
<Compile Include="Blacklisting\BlacklistRepositoryFixture.cs" />
|
||||||
<Compile Include="DataAugmentationFixture\Scene\SceneMappingProxyFixture.cs" />
|
<Compile Include="DataAugmentationFixture\Scene\SceneMappingProxyFixture.cs" />
|
||||||
<Compile Include="DataAugmentationFixture\Scene\SceneMappingServiceFixture.cs" />
|
<Compile Include="DataAugmentationFixture\Scene\SceneMappingServiceFixture.cs" />
|
||||||
|
<Compile Include="Datastore\MarrDataLazyLoadingFixture.cs" />
|
||||||
<Compile Include="Datastore\BasicRepositoryFixture.cs" />
|
<Compile Include="Datastore\BasicRepositoryFixture.cs" />
|
||||||
<Compile Include="Datastore\Converters\ProviderSettingConverterFixture.cs" />
|
<Compile Include="Datastore\Converters\ProviderSettingConverterFixture.cs" />
|
||||||
<Compile Include="Datastore\DatabaseRelationshipFixture.cs" />
|
<Compile Include="Datastore\DatabaseRelationshipFixture.cs" />
|
||||||
|
|
Loading…
Reference in New Issue