diff --git a/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs b/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs index 93abe509f..abbf8a106 100644 --- a/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs +++ b/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs @@ -4,7 +4,6 @@ using FluentAssertions; using NUnit.Framework; using NzbDrone.Core.Repository; using NzbDrone.Core.Test.Framework; -using Db4objects.Db4o.Linq; namespace NzbDrone.Core.Test.Datastore { @@ -14,7 +13,7 @@ namespace NzbDrone.Core.Test.Datastore [SetUp] public void SetUp() { - WithObjectDb(false); + WithObjectDb(); } [Test] @@ -25,7 +24,6 @@ namespace NzbDrone.Core.Test.Datastore Db.Create(series); - Db.Ext().Purge(); Db.AsQueryable().Should().HaveCount(1); @@ -47,38 +45,6 @@ namespace NzbDrone.Core.Test.Datastore } - [Test] - public void rollback_should_reset_state() - { - var episode = Builder.CreateNew().Build(); - - Db.Create(episode); - - Db.AsQueryable().Should().HaveCount(1); - - Db.Rollback(); - - Db.AsQueryable().Should().HaveCount(0); - } - - [Test] - public void roolback_should_only_roll_back_what_is_not_commited() - { - var episode = Builder.CreateNew().Build(); - var series = Builder.CreateNew().Build(); - - Db.Create(episode); - - Db.Commit(); - - Db.Create(series); - - Db.Rollback(); - - Db.AsQueryable().Should().HaveCount(1); - Db.AsQueryable().Should().HaveCount(0); - } - [Test] public void should_store_nested_objects() @@ -102,7 +68,7 @@ namespace NzbDrone.Core.Test.Datastore episode.Series.Title = "UpdatedTitle"; - Db.Update(episode, 2); + Db.Update(episode); Db.AsQueryable().Should().HaveCount(1); Db.AsQueryable().Single().Series.Should().NotBeNull(); diff --git a/NzbDrone.Core.Test/Framework/ObjectDbTest.cs b/NzbDrone.Core.Test/Framework/ObjectDbTest.cs new file mode 100644 index 000000000..897810a91 --- /dev/null +++ b/NzbDrone.Core.Test/Framework/ObjectDbTest.cs @@ -0,0 +1,45 @@ +using System; +using System.Linq; +using NUnit.Framework; +using NzbDrone.Core.Datastore; + +namespace NzbDrone.Core.Test.Framework +{ + public abstract class ObjectDbTest : CoreTest + { + private EloqueraDb _db; + protected EloqueraDb Db + { + get + { + if (_db == null) + throw new InvalidOperationException("Test object database doesn't exists. Make sure you call WithRealDb() if you intend to use an actual database."); + + return _db; + } + } + + protected void WithObjectDb(bool memory = true) + { + if (memory) + { + _db = new EloqueraDbFactory().CreateMemoryDb(); + } + else + { + _db = new EloqueraDbFactory().Create(Guid.NewGuid().ToString()); + } + + Mocker.SetConstant(Db); + } + + [TearDown] + public void ObjectDbTearDown() + { + if (_db != null) + { + _db.Dispose(); + } + } + } +} \ No newline at end of file diff --git a/NzbDrone.Core.Test/Framework/SqlCeTest.cs b/NzbDrone.Core.Test/Framework/SqlCeTest.cs index 61e037214..c47dd737c 100644 --- a/NzbDrone.Core.Test/Framework/SqlCeTest.cs +++ b/NzbDrone.Core.Test/Framework/SqlCeTest.cs @@ -1,6 +1,5 @@ using System; using System.IO; -using Db4objects.Db4o.IO; using NUnit.Framework; using NzbDrone.Core.Datastore; using NzbDrone.Core.Model.Notification; @@ -30,46 +29,6 @@ namespace NzbDrone.Core.Test.Framework } - public abstract class ObjectDbTest : CoreTest - { - private EloqueraDb _db; - protected EloqueraDb Db - { - get - { - if (_db == null) - throw new InvalidOperationException("Test object database doesn't exists. Make sure you call WithRealDb() if you intend to use an actual database."); - - return _db; - } - } - - protected void WithObjectDb(bool memory = true) - { - if (memory) - { - //Todo: Actually use memory: http://www.eloquera.com/sites/default/files/filepicker/1/Help/Documentation/HTML/In-memory%20database.htm - _db = new EloqueraDbFactory().Create(); - } - else - { - _db = new EloqueraDbFactory().Create(dbFilename: Guid.NewGuid().ToString()); - } - - Mocker.SetConstant(Db); - } - - [TearDown] - public void ObjectDbTearDown() - { - if (_db != null) - { - _db.Dispose(); - } - } - } - - public abstract class SqlCeTest : CoreTest { private string _dbTemplateName; diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 8166e73a6..8862d93d8 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -65,24 +65,17 @@ ..\packages\AutoMoq.1.6.1\lib\AutoMoq.dll - - ..\packages\db4o-devel.8.1.184.15492\lib\net40\Db4objects.Db4o.dll - - - ..\packages\db4o-devel.8.1.184.15492\lib\net40\Db4objects.Db4o.Data.Services.dll - - - ..\packages\db4o-devel.8.1.184.15492\lib\net40\Db4objects.Db4o.Linq.dll - False ..\Libraries\DeskMetrics\DeskMetrics.NET.dll ..\packages\EloqueraDB.5.0.0\lib\net40\Eloquera.Client.dll + True ..\packages\EloqueraDB.5.0.0\lib\net40\Eloquera.Common.dll + True ..\packages\EloqueraDB.5.0.0\lib\net40\Eloquera.Server.exe @@ -106,9 +99,6 @@ ..\packages\Unity.2.1.505.2\lib\NET35\Microsoft.Practices.Unity.Configuration.dll - - ..\packages\db4o-devel.8.1.184.15492\lib\net40\Mono.Reflection.dll - ..\packages\Moq.4.0.10827\lib\NET40\Moq.dll @@ -157,6 +147,7 @@ + diff --git a/NzbDrone.Core.Test/packages.config b/NzbDrone.Core.Test/packages.config index 8d13db8e9..bce8f8a52 100644 --- a/NzbDrone.Core.Test/packages.config +++ b/NzbDrone.Core.Test/packages.config @@ -3,7 +3,6 @@ - diff --git a/NzbDrone.Core/Datastore/EloqueraDb.cs b/NzbDrone.Core/Datastore/EloqueraDb.cs index a6dc1b0a0..7a55c5097 100644 --- a/NzbDrone.Core/Datastore/EloqueraDb.cs +++ b/NzbDrone.Core/Datastore/EloqueraDb.cs @@ -1,84 +1,64 @@ using System; -using System.Collections; using System.Collections.Generic; using System.Linq; -using System.Text; using Eloquera.Client; namespace NzbDrone.Core.Datastore { public class EloqueraDb : IDisposable { - private DB _db; + private readonly DB _db; public EloqueraDb(DB db) { _db = db; } - public int Create(object obj) - { - return Convert.ToInt32(_db.Store(obj)); - } - - public void Update(object obj) - { - _db.Store(obj); - } - - public void Delete(object obj) - { - _db.Delete(obj); - } - - public void DeleteAll(object obj) - { - _db.DeleteAll(obj); - } - - public IEnumerable Query() + public IEnumerable AsQueryable() { return _db.Query(); } - public IEnumerable ExecuteQuery(string query) - { - return _db.ExecuteQuery(query); - } - public IEnumerable ExecuteQuery(string query, int depth) + public T Create(T obj) { - return _db.ExecuteQuery(query, depth); + _db.Store(obj); + return obj; } - public IEnumerable ExecuteQuery(string query, int depth, Parameters parameters) + public IList CreateMany(IEnumerable objects) { - return _db.ExecuteQuery(query, depth, parameters); + return DoMany(objects, Create); } - public IEnumerable ExecuteQuery(string query, Parameters parameters) + public T Update(T obj) { - return _db.ExecuteQuery(query, parameters); + _db.Store(obj); + return obj; } - public object ExecutScalar(string query) + public IList UpdateMany(IEnumerable objects) { - return _db.ExecuteQuery(query); + return DoMany(objects, Update); } - public object ExecuteScalar(string query, int depth) + + public void Delete(T obj) { - return _db.ExecuteQuery(query, depth); + _db.Delete(obj); } - public object ExecuteScalar(string query, int depth, Parameters parameters) + public void DeleteMany(IEnumerable objects) { - return _db.ExecuteQuery(query, depth, parameters); + foreach (var o in objects) + { + Delete(o); + } } - public object ExecuteScalar(string query, Parameters parameters) + private IList DoMany(IEnumerable objects, Func function) { - return _db.ExecuteQuery(query, parameters); + return objects.Select(function).ToList(); } public void Dispose() diff --git a/NzbDrone.Core/Datastore/EloqueraDbFactory.cs b/NzbDrone.Core/Datastore/EloqueraDbFactory.cs index 77e3e5544..29dd92ed6 100644 --- a/NzbDrone.Core/Datastore/EloqueraDbFactory.cs +++ b/NzbDrone.Core/Datastore/EloqueraDbFactory.cs @@ -1,31 +1,31 @@ using System; -using System.Collections.Generic; using System.IO; using System.Linq; -using System.Text; using Eloquera.Client; -using NzbDrone.Common; namespace NzbDrone.Core.Datastore { public class EloqueraDbFactory { - private readonly EnvironmentProvider _environmentProvider; - - public EloqueraDbFactory() + public EloqueraDb CreateMemoryDb() { - _environmentProvider = new EnvironmentProvider(); + return InternalCreate("server=(local);password=;options=inmemory;",Guid.NewGuid().ToString()); } - public EloqueraDb Create(string dbName = "NzbDrone", string dbFilename = "nzbdrone.eloq") + public EloqueraDb Create(string dbPath) { - DB db = new DB(); - DB.Configuration.ServerSettings.DatabasePath = Path.Combine(_environmentProvider.GetAppDataPath(), dbName); - db.CreateDatabase(dbName); - db.OpenDatabase(dbName); - db.RefreshMode = ObjectRefreshMode.AlwaysReturnUpdatedValues; + var file = new FileInfo(dbPath).Name; + return InternalCreate(string.Format("server=(local);database={0};usedatapath={1};password=;", file, dbPath),file); + } + private EloqueraDb InternalCreate(string connectionString, string databaseName) + { + var db = new DB(connectionString); + db.CreateDatabase(databaseName); + db.OpenDatabase(databaseName); return new EloqueraDb(db); } + + } } diff --git a/NzbDrone.Core/Repository/Series.cs b/NzbDrone.Core/Repository/Series.cs index 1b10976e1..764ce5f5b 100644 --- a/NzbDrone.Core/Repository/Series.cs +++ b/NzbDrone.Core/Repository/Series.cs @@ -1,5 +1,6 @@ using System; using System.ComponentModel; +using Eloquera.Client; using NzbDrone.Core.Model; using NzbDrone.Core.Repository.Quality; using PetaPoco; @@ -9,6 +10,10 @@ namespace NzbDrone.Core.Repository [PrimaryKey("SeriesId", autoIncrement = false)] public class Series { + + [ID] + public int Id; + public virtual int SeriesId { get; set; } public string Title { get; set; } @@ -66,7 +71,7 @@ namespace NzbDrone.Core.Repository /// true if hidden; otherwise, false. /// This field will be used for shows that are pending delete or /// new series that haven't been successfully imported - [Ignore] + [PetaPoco.Ignore] public bool Hidden { get; set; } [ResultColumn]