From 8c99cca2079080c431fdf777c12c992dd999fe67 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Wed, 6 Feb 2013 00:40:57 -0800 Subject: [PATCH] Broke some Eloquera tests to prove a point --- .../Datastore/ObjectDatabaseFixture.cs | 37 +++++++++++++++---- NzbDrone.Core/Datastore/BasicRepository.cs | 13 +++---- NzbDrone.Core/Repository/Series.cs | 2 +- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs b/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs index 25dac579e..c057a85d1 100644 --- a/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs +++ b/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs @@ -14,14 +14,19 @@ public class ObjectDatabaseFixture : ObjectDbTest private Series testSeries; private Episode testEpisode; - [SetUp] public void SetUp() { WithObjectDb(); - testSeries = Builder.CreateNew().Build(); - testEpisode = Builder.CreateNew().Build(); + testSeries = Builder + .CreateNew() + .With(s => s.Id = 0) + .Build(); + + testEpisode = Builder + .CreateNew() + .Build(); } @@ -47,8 +52,6 @@ public void should_not_store_dirty_data_in_cache() Db.AsQueryable().Single().Series.Should().BeNull(); } - - [Test] public void should_store_nested_objects() { @@ -76,7 +79,6 @@ public void should_update_nested_objects() Db.AsQueryable().Single().Series.Title.Should().Be("UpdatedTitle"); } - [Test] public void new_objects_should_get_id() { @@ -85,7 +87,28 @@ public void new_objects_should_get_id() } [Test] - public void should_be_able_to_read_unknow_type() + public void should_have_id_when_returned_from_database() + { + Db.Insert(testSeries); + var item = Db.AsQueryable(); + + item.Should().HaveCount(1); + item.First().Id.Should().NotBe(0); + item.First().Id.Should().Be(testSeries.Id); + } + + [Test] + public void should_be_able_to_find_object_by_id() + { + Db.Insert(testSeries); + var item = Db.AsQueryable().Single(c => c.Id == testSeries.Id); + + item.Id.Should().NotBe(0); + item.Id.Should().Be(testSeries.Id); + } + + [Test] + public void should_be_able_to_read_unknown_type() { Db.AsQueryable().ToList().Should().BeEmpty(); } diff --git a/NzbDrone.Core/Datastore/BasicRepository.cs b/NzbDrone.Core/Datastore/BasicRepository.cs index e280dffb6..752dc4c46 100644 --- a/NzbDrone.Core/Datastore/BasicRepository.cs +++ b/NzbDrone.Core/Datastore/BasicRepository.cs @@ -22,25 +22,24 @@ public BasicRepository(EloqueraDb eloqueraDb) protected EloqueraDb EloqueraDb { get; private set; } - public List All() { return EloqueraDb.AsQueryable().ToList(); } - public TModel Get(int rootFolderId) + public TModel Get(int id) { - return EloqueraDb.AsQueryable().Single(c => c.Id == rootFolderId); + return EloqueraDb.AsQueryable().Single(c => c.Id == id); } - public TModel Add(TModel rootFolder) + public TModel Add(TModel model) { - return EloqueraDb.Insert(rootFolder); + return EloqueraDb.Insert(model); } - public void Delete(int rootFolderId) + public void Delete(int id) { - var itemToDelete = Get(rootFolderId); + var itemToDelete = Get(id); EloqueraDb.Delete(itemToDelete); } } diff --git a/NzbDrone.Core/Repository/Series.cs b/NzbDrone.Core/Repository/Series.cs index 764ce5f5b..984f6acdd 100644 --- a/NzbDrone.Core/Repository/Series.cs +++ b/NzbDrone.Core/Repository/Series.cs @@ -12,7 +12,7 @@ public class Series { [ID] - public int Id; + public long Id; public virtual int SeriesId { get; set; }