updated eloquera's test setup.

This commit is contained in:
kay.one 2013-02-03 16:10:15 -08:00
parent 23b90ae1c4
commit d13f977bb5
8 changed files with 92 additions and 147 deletions

View File

@ -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<Series>().Should().HaveCount(1);
@ -47,38 +45,6 @@ namespace NzbDrone.Core.Test.Datastore
}
[Test]
public void rollback_should_reset_state()
{
var episode = Builder<Episode>.CreateNew().Build();
Db.Create(episode);
Db.AsQueryable<Episode>().Should().HaveCount(1);
Db.Rollback();
Db.AsQueryable<Episode>().Should().HaveCount(0);
}
[Test]
public void roolback_should_only_roll_back_what_is_not_commited()
{
var episode = Builder<Episode>.CreateNew().Build();
var series = Builder<Series>.CreateNew().Build();
Db.Create(episode);
Db.Commit();
Db.Create(series);
Db.Rollback();
Db.AsQueryable<Episode>().Should().HaveCount(1);
Db.AsQueryable<Series>().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<Episode>().Should().HaveCount(1);
Db.AsQueryable<Episode>().Single().Series.Should().NotBeNull();

View File

@ -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();
}
}
}
}

View File

@ -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;

View File

@ -65,24 +65,17 @@
<Reference Include="AutoMoq">
<HintPath>..\packages\AutoMoq.1.6.1\lib\AutoMoq.dll</HintPath>
</Reference>
<Reference Include="Db4objects.Db4o">
<HintPath>..\packages\db4o-devel.8.1.184.15492\lib\net40\Db4objects.Db4o.dll</HintPath>
</Reference>
<Reference Include="Db4objects.Db4o.Data.Services">
<HintPath>..\packages\db4o-devel.8.1.184.15492\lib\net40\Db4objects.Db4o.Data.Services.dll</HintPath>
</Reference>
<Reference Include="Db4objects.Db4o.Linq">
<HintPath>..\packages\db4o-devel.8.1.184.15492\lib\net40\Db4objects.Db4o.Linq.dll</HintPath>
</Reference>
<Reference Include="DeskMetrics.NET, Version=3.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Libraries\DeskMetrics\DeskMetrics.NET.dll</HintPath>
</Reference>
<Reference Include="Eloquera.Client">
<HintPath>..\packages\EloqueraDB.5.0.0\lib\net40\Eloquera.Client.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Eloquera.Common">
<HintPath>..\packages\EloqueraDB.5.0.0\lib\net40\Eloquera.Common.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Eloquera.Server">
<HintPath>..\packages\EloqueraDB.5.0.0\lib\net40\Eloquera.Server.exe</HintPath>
@ -106,9 +99,6 @@
<Reference Include="Microsoft.Practices.Unity.Configuration">
<HintPath>..\packages\Unity.2.1.505.2\lib\NET35\Microsoft.Practices.Unity.Configuration.dll</HintPath>
</Reference>
<Reference Include="Mono.Reflection">
<HintPath>..\packages\db4o-devel.8.1.184.15492\lib\net40\Mono.Reflection.dll</HintPath>
</Reference>
<Reference Include="Moq, Version=4.0.10827.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.0.10827\lib\NET40\Moq.dll</HintPath>
</Reference>
@ -157,6 +147,7 @@
<ItemGroup>
<Compile Include="Datastore\ObjectDatabaseFixture.cs" />
<Compile Include="Framework\CoreTestTSubject.cs" />
<Compile Include="Framework\ObjectDbTest.cs" />
<Compile Include="HelperTests\XElementHelperTests\ConvertToTFixture.cs" />
<Compile Include="IndexerTests\NzbxFixture.cs" />
<Compile Include="JobTests\RenameSeasonJobFixture.cs" />

View File

@ -3,7 +3,6 @@
<package id="Autofac" version="2.6.3.862" targetFramework="net40" />
<package id="AutoMoq" version="1.6.1" targetFramework="net40" />
<package id="CommonServiceLocator" version="1.0" targetFramework="net40" />
<package id="db4o-devel" version="8.1.184.15492" targetFramework="net40" />
<package id="EloqueraDB" version="5.0.0" targetFramework="net40" />
<package id="FluentAssertions" version="2.0.0.1" targetFramework="net40" />
<package id="Microsoft.SqlServer.Compact" version="4.0.8876.1" targetFramework="net40" />

View File

@ -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<T> Query<T>()
public IEnumerable<T> AsQueryable<T>()
{
return _db.Query<T>();
}
public IEnumerable ExecuteQuery(string query)
public T Create<T>(T obj)
{
return _db.ExecuteQuery(query);
_db.Store(obj);
return obj;
}
public IEnumerable ExecuteQuery(string query, int depth)
public IList<T> CreateMany<T>(IEnumerable<T> objects)
{
return _db.ExecuteQuery(query, depth);
return DoMany(objects, Create);
}
public IEnumerable ExecuteQuery(string query, int depth, Parameters parameters)
public T Update<T>(T obj)
{
return _db.ExecuteQuery(query, depth, parameters);
_db.Store(obj);
return obj;
}
public IEnumerable ExecuteQuery(string query, Parameters parameters)
public IList<T> UpdateMany<T>(IEnumerable<T> objects)
{
return _db.ExecuteQuery(query, parameters);
return DoMany(objects, Update);
}
public object ExecutScalar(string query)
public void Delete<T>(T obj)
{
return _db.ExecuteQuery(query);
_db.Delete(obj);
}
public object ExecuteScalar(string query, int depth)
public void DeleteMany<T>(IEnumerable<T> objects)
{
return _db.ExecuteQuery(query, depth);
foreach (var o in objects)
{
Delete(o);
}
}
public object ExecuteScalar(string query, int depth, Parameters parameters)
private IList<T> DoMany<T>(IEnumerable<T> objects, Func<T, T> function)
{
return _db.ExecuteQuery(query, depth, parameters);
}
public object ExecuteScalar(string query, Parameters parameters)
{
return _db.ExecuteQuery(query, parameters);
return objects.Select(function).ToList();
}
public void Dispose()

View File

@ -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);
}
}
}

View File

@ -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
/// <value><c>true</c> if hidden; otherwise, <c>false</c>.</value>
/// <remarks>This field will be used for shows that are pending delete or
/// new series that haven't been successfully imported</remarks>
[Ignore]
[PetaPoco.Ignore]
public bool Hidden { get; set; }
[ResultColumn]