From b27217bcf4a5fc47071f3b87eb9022abbb59018f Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Wed, 10 Apr 2013 21:38:45 -0700 Subject: [PATCH] added test for lazy loaded objects. --- .../Datastore/ObjectDatabaseFixture.cs | 20 +++++++++++++++++++ NzbDrone.Core.Test/Framework/DbTest.cs | 6 +++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs b/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs index ad84f1078..b305d21cd 100644 --- a/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs +++ b/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs @@ -8,6 +8,7 @@ using NUnit.Framework; using NzbDrone.Core.Datastore; using NzbDrone.Core.Jobs; using NzbDrone.Core.Test.Framework; +using NzbDrone.Core.Tv; namespace NzbDrone.Core.Test.Datastore { @@ -123,6 +124,25 @@ namespace NzbDrone.Core.Test.Datastore Db.All().Single().Name.Should().Be("B"); Db.All().Single().Interval.Should().Be(12); } + + [Test] + public void should_load_lazy_objects() + { + + var rootFolder = Db.Insert(new RootFolders.RootFolder() { Path = "C:\test" }); + + var series = Builder.CreateNew() + .With(c=>c.RootFolderId = rootFolder.Id) + .BuildNew(); + + Db.Insert(series); + + + Db.Single().RootFolder.Should().NotBeNull(); + Db.Single().RootFolder.Value.Should().NotBeNull(); + Db.Single().RootFolder.Value.Path.Should().Be(rootFolder.Path); + + } } } diff --git a/NzbDrone.Core.Test/Framework/DbTest.cs b/NzbDrone.Core.Test/Framework/DbTest.cs index 5186e25d1..e92011dd5 100644 --- a/NzbDrone.Core.Test/Framework/DbTest.cs +++ b/NzbDrone.Core.Test/Framework/DbTest.cs @@ -130,7 +130,7 @@ namespace NzbDrone.Core.Test.Framework public interface ITestDatabase { void InsertMany(IEnumerable items) where T : ModelBase, new(); - void Insert(T item) where T : ModelBase, new(); + T Insert(T item) where T : ModelBase, new(); List All() where T : ModelBase, new(); T Single() where T : ModelBase, new(); void Update(T childModel) where T : ModelBase, new(); @@ -151,9 +151,9 @@ namespace NzbDrone.Core.Test.Framework new BasicRepository(_dbConnection).InsertMany(items.ToList()); } - public void Insert(T item) where T : ModelBase, new() + public T Insert(T item) where T : ModelBase, new() { - new BasicRepository(_dbConnection).Insert(item); + return new BasicRepository(_dbConnection).Insert(item); } public List All() where T : ModelBase, new()