fixed history->episode relationship.

pull/4/head
kay.one 11 years ago
parent e0b881fe4b
commit a2b91b469e

@ -4,14 +4,14 @@ using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Test.Datastore
{
[TestFixture]
public class DatabaseJoinFixture : DbTest<BasicRepository<Series>, Series>
public class DatabaseRelationshipFixture : DbTest
{
[Test]
[Explicit]
@ -23,7 +23,7 @@ namespace NzbDrone.Core.Test.Datastore
Marr.Data.MapRepository.Instance.EnableTraceLogging = false;
Subject.Insert(series);
Db.Insert(series);
var covers = Builder<MediaCover.MediaCover>.CreateListOfSize(5)
.All()
@ -34,12 +34,12 @@ namespace NzbDrone.Core.Test.Datastore
Db.InsertMany(covers);
var loadedSeries = Subject.SingleOrDefault();
var loadedSeries = Db.Single<Series>();
var sw = Stopwatch.StartNew();
for (int i = 0; i < 10000; i++)
{
loadedSeries = Subject.SingleOrDefault();
loadedSeries = Db.Single<Series>();
var list = loadedSeries.Covers.Value;
}
@ -57,7 +57,7 @@ namespace NzbDrone.Core.Test.Datastore
.With(c => c.Id = 0)
.Build();
Subject.Insert(series);
Db.Insert(series);
var covers = Builder<MediaCover.MediaCover>.CreateListOfSize(5)
.All()
@ -68,14 +68,12 @@ namespace NzbDrone.Core.Test.Datastore
Db.InsertMany(covers);
var loadedSeries = Subject.SingleOrDefault();
loadedSeries = Subject.SingleOrDefault();
var loadedSeries = Db.Single<Series>();
loadedSeries.Covers.Value.Should().HaveSameCount(covers);
}
[Test]
public void embeded_document_as_json()
public void one_to_one()
{
var episode = Builder<Episode>.CreateNew()
.With(c => c.Id = 0)
@ -91,7 +89,28 @@ namespace NzbDrone.Core.Test.Datastore
.Build();
Db.Insert(history);
Db.Single<History.History>().Episode.Value.Should().NotBeNull();
var loadedEpisode = Db.Single<History.History>().Episode.Value;
loadedEpisode.Should().NotBeNull();
loadedEpisode.ShouldHave().AllProperties().EqualTo(episode);
}
[Test]
public void embedded_document_as_json()
{
var quality = new QualityModel { Quality = Quality.Bluray720p, Proper = true };
var history = Builder<History.History>.CreateNew()
.With(c => c.Id = 0)
.With(c => c.Quality = quality)
.Build();
Db.Insert(history);
var loadedQuality = Db.Single<History.History>().Quality;
loadedQuality.Should().Be(quality);
}
}
}

@ -138,7 +138,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Datastore\BasicRepositoryFixture.cs" />
<Compile Include="Datastore\DatabaseJoinFixture.cs" />
<Compile Include="Datastore\DatabaseRelationshipFixture.cs" />
<Compile Include="Datastore\ObjectDatabaseFixture.cs" />
<Compile Include="Framework\CoreTest.cs" />
<Compile Include="Framework\DbTest.cs" />

@ -40,7 +40,7 @@ namespace NzbDrone.Core.Datastore
Mapper.Entity<History.History>().RegisterModel("History")
.Relationships.AutoMapComplexTypeProperties<ILazyLoaded>()
.For(c => c.Episode)
.LazyLoad((db, history) => db.Query<Episode>().Where(ep => ep.Id == history.Id).ToList());
.LazyLoad((db, history) => db.Query<Episode>().Single(ep => ep.Id == history.EpisodeId));
Mapper.Entity<Series>().RegisterModel("Series")
.Relationships.AutoMapComplexTypeProperties<ILazyLoaded>()

Loading…
Cancel
Save