added test for lazy loaded objects.

pull/6/head
kay.one 12 years ago
parent 684a72792a
commit b27217bcf4

@ -8,6 +8,7 @@ using NUnit.Framework;
using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore;
using NzbDrone.Core.Jobs; using NzbDrone.Core.Jobs;
using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Test.Datastore namespace NzbDrone.Core.Test.Datastore
{ {
@ -123,6 +124,25 @@ namespace NzbDrone.Core.Test.Datastore
Db.All<JobDefinition>().Single().Name.Should().Be("B"); Db.All<JobDefinition>().Single().Name.Should().Be("B");
Db.All<JobDefinition>().Single().Interval.Should().Be(12); Db.All<JobDefinition>().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<Series>.CreateNew()
.With(c=>c.RootFolderId = rootFolder.Id)
.BuildNew();
Db.Insert(series);
Db.Single<Series>().RootFolder.Should().NotBeNull();
Db.Single<Series>().RootFolder.Value.Should().NotBeNull();
Db.Single<Series>().RootFolder.Value.Path.Should().Be(rootFolder.Path);
}
} }
} }

@ -130,7 +130,7 @@ namespace NzbDrone.Core.Test.Framework
public interface ITestDatabase public interface ITestDatabase
{ {
void InsertMany<T>(IEnumerable<T> items) where T : ModelBase, new(); void InsertMany<T>(IEnumerable<T> items) where T : ModelBase, new();
void Insert<T>(T item) where T : ModelBase, new(); T Insert<T>(T item) where T : ModelBase, new();
List<T> All<T>() where T : ModelBase, new(); List<T> All<T>() where T : ModelBase, new();
T Single<T>() where T : ModelBase, new(); T Single<T>() where T : ModelBase, new();
void Update<T>(T childModel) where T : ModelBase, new(); void Update<T>(T childModel) where T : ModelBase, new();
@ -151,9 +151,9 @@ namespace NzbDrone.Core.Test.Framework
new BasicRepository<T>(_dbConnection).InsertMany(items.ToList()); new BasicRepository<T>(_dbConnection).InsertMany(items.ToList());
} }
public void Insert<T>(T item) where T : ModelBase, new() public T Insert<T>(T item) where T : ModelBase, new()
{ {
new BasicRepository<T>(_dbConnection).Insert(item); return new BasicRepository<T>(_dbConnection).Insert(item);
} }
public List<T> All<T>() where T : ModelBase, new() public List<T> All<T>() where T : ModelBase, new()

Loading…
Cancel
Save