From a2b91b469eacb6e2fb6d74dc612614a39e3a9b2b Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Tue, 26 Mar 2013 00:17:46 -0700 Subject: [PATCH] fixed history->episode relationship. --- ...ture.cs => DatabaseRelationshipFixture.cs} | 41 ++++++++++++++----- NzbDrone.Core.Test/NzbDrone.Core.Test.csproj | 2 +- NzbDrone.Core/Datastore/TableMapping.cs | 2 +- 3 files changed, 32 insertions(+), 13 deletions(-) rename NzbDrone.Core.Test/Datastore/{DatabaseJoinFixture.cs => DatabaseRelationshipFixture.cs} (68%) diff --git a/NzbDrone.Core.Test/Datastore/DatabaseJoinFixture.cs b/NzbDrone.Core.Test/Datastore/DatabaseRelationshipFixture.cs similarity index 68% rename from NzbDrone.Core.Test/Datastore/DatabaseJoinFixture.cs rename to NzbDrone.Core.Test/Datastore/DatabaseRelationshipFixture.cs index 84d93e6a3..7ef89cef3 100644 --- a/NzbDrone.Core.Test/Datastore/DatabaseJoinFixture.cs +++ b/NzbDrone.Core.Test/Datastore/DatabaseRelationshipFixture.cs @@ -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, 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.CreateListOfSize(5) .All() @@ -34,12 +34,12 @@ namespace NzbDrone.Core.Test.Datastore Db.InsertMany(covers); - var loadedSeries = Subject.SingleOrDefault(); + var loadedSeries = Db.Single(); var sw = Stopwatch.StartNew(); for (int i = 0; i < 10000; i++) { - loadedSeries = Subject.SingleOrDefault(); + loadedSeries = Db.Single(); 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.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(); loadedSeries.Covers.Value.Should().HaveSameCount(covers); } [Test] - public void embeded_document_as_json() + public void one_to_one() { var episode = Builder.CreateNew() .With(c => c.Id = 0) @@ -91,7 +89,28 @@ namespace NzbDrone.Core.Test.Datastore .Build(); Db.Insert(history); - Db.Single().Episode.Value.Should().NotBeNull(); + + var loadedEpisode = Db.Single().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.CreateNew() + .With(c => c.Id = 0) + .With(c => c.Quality = quality) + .Build(); + + Db.Insert(history); + + var loadedQuality = Db.Single().Quality; + loadedQuality.Should().Be(quality); } } } diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 42216a516..e7fadaa39 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -138,7 +138,7 @@ - + diff --git a/NzbDrone.Core/Datastore/TableMapping.cs b/NzbDrone.Core/Datastore/TableMapping.cs index c63ada9a8..489a73ba2 100644 --- a/NzbDrone.Core/Datastore/TableMapping.cs +++ b/NzbDrone.Core/Datastore/TableMapping.cs @@ -40,7 +40,7 @@ namespace NzbDrone.Core.Datastore Mapper.Entity().RegisterModel("History") .Relationships.AutoMapComplexTypeProperties() .For(c => c.Episode) - .LazyLoad((db, history) => db.Query().Where(ep => ep.Id == history.Id).ToList()); + .LazyLoad((db, history) => db.Query().Single(ep => ep.Id == history.EpisodeId)); Mapper.Entity().RegisterModel("Series") .Relationships.AutoMapComplexTypeProperties()