updated eloquera's test setup.
This commit is contained in:
parent
23b90ae1c4
commit
d13f977bb5
|
@ -4,7 +4,6 @@ using FluentAssertions;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using NzbDrone.Core.Repository;
|
using NzbDrone.Core.Repository;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
using Db4objects.Db4o.Linq;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.Datastore
|
namespace NzbDrone.Core.Test.Datastore
|
||||||
{
|
{
|
||||||
|
@ -14,7 +13,7 @@ namespace NzbDrone.Core.Test.Datastore
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void SetUp()
|
public void SetUp()
|
||||||
{
|
{
|
||||||
WithObjectDb(false);
|
WithObjectDb();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -25,7 +24,6 @@ namespace NzbDrone.Core.Test.Datastore
|
||||||
|
|
||||||
Db.Create(series);
|
Db.Create(series);
|
||||||
|
|
||||||
Db.Ext().Purge();
|
|
||||||
|
|
||||||
Db.AsQueryable<Series>().Should().HaveCount(1);
|
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]
|
[Test]
|
||||||
public void should_store_nested_objects()
|
public void should_store_nested_objects()
|
||||||
|
@ -102,7 +68,7 @@ namespace NzbDrone.Core.Test.Datastore
|
||||||
|
|
||||||
episode.Series.Title = "UpdatedTitle";
|
episode.Series.Title = "UpdatedTitle";
|
||||||
|
|
||||||
Db.Update(episode, 2);
|
Db.Update(episode);
|
||||||
|
|
||||||
Db.AsQueryable<Episode>().Should().HaveCount(1);
|
Db.AsQueryable<Episode>().Should().HaveCount(1);
|
||||||
Db.AsQueryable<Episode>().Single().Series.Should().NotBeNull();
|
Db.AsQueryable<Episode>().Single().Series.Should().NotBeNull();
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Db4objects.Db4o.IO;
|
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using NzbDrone.Core.Datastore;
|
using NzbDrone.Core.Datastore;
|
||||||
using NzbDrone.Core.Model.Notification;
|
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
|
public abstract class SqlCeTest : CoreTest
|
||||||
{
|
{
|
||||||
private string _dbTemplateName;
|
private string _dbTemplateName;
|
||||||
|
|
|
@ -65,24 +65,17 @@
|
||||||
<Reference Include="AutoMoq">
|
<Reference Include="AutoMoq">
|
||||||
<HintPath>..\packages\AutoMoq.1.6.1\lib\AutoMoq.dll</HintPath>
|
<HintPath>..\packages\AutoMoq.1.6.1\lib\AutoMoq.dll</HintPath>
|
||||||
</Reference>
|
</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">
|
<Reference Include="DeskMetrics.NET, Version=3.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
<HintPath>..\Libraries\DeskMetrics\DeskMetrics.NET.dll</HintPath>
|
<HintPath>..\Libraries\DeskMetrics\DeskMetrics.NET.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Eloquera.Client">
|
<Reference Include="Eloquera.Client">
|
||||||
<HintPath>..\packages\EloqueraDB.5.0.0\lib\net40\Eloquera.Client.dll</HintPath>
|
<HintPath>..\packages\EloqueraDB.5.0.0\lib\net40\Eloquera.Client.dll</HintPath>
|
||||||
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Eloquera.Common">
|
<Reference Include="Eloquera.Common">
|
||||||
<HintPath>..\packages\EloqueraDB.5.0.0\lib\net40\Eloquera.Common.dll</HintPath>
|
<HintPath>..\packages\EloqueraDB.5.0.0\lib\net40\Eloquera.Common.dll</HintPath>
|
||||||
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Eloquera.Server">
|
<Reference Include="Eloquera.Server">
|
||||||
<HintPath>..\packages\EloqueraDB.5.0.0\lib\net40\Eloquera.Server.exe</HintPath>
|
<HintPath>..\packages\EloqueraDB.5.0.0\lib\net40\Eloquera.Server.exe</HintPath>
|
||||||
|
@ -106,9 +99,6 @@
|
||||||
<Reference Include="Microsoft.Practices.Unity.Configuration">
|
<Reference Include="Microsoft.Practices.Unity.Configuration">
|
||||||
<HintPath>..\packages\Unity.2.1.505.2\lib\NET35\Microsoft.Practices.Unity.Configuration.dll</HintPath>
|
<HintPath>..\packages\Unity.2.1.505.2\lib\NET35\Microsoft.Practices.Unity.Configuration.dll</HintPath>
|
||||||
</Reference>
|
</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">
|
<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>
|
<HintPath>..\packages\Moq.4.0.10827\lib\NET40\Moq.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
@ -157,6 +147,7 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Datastore\ObjectDatabaseFixture.cs" />
|
<Compile Include="Datastore\ObjectDatabaseFixture.cs" />
|
||||||
<Compile Include="Framework\CoreTestTSubject.cs" />
|
<Compile Include="Framework\CoreTestTSubject.cs" />
|
||||||
|
<Compile Include="Framework\ObjectDbTest.cs" />
|
||||||
<Compile Include="HelperTests\XElementHelperTests\ConvertToTFixture.cs" />
|
<Compile Include="HelperTests\XElementHelperTests\ConvertToTFixture.cs" />
|
||||||
<Compile Include="IndexerTests\NzbxFixture.cs" />
|
<Compile Include="IndexerTests\NzbxFixture.cs" />
|
||||||
<Compile Include="JobTests\RenameSeasonJobFixture.cs" />
|
<Compile Include="JobTests\RenameSeasonJobFixture.cs" />
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
<package id="Autofac" version="2.6.3.862" targetFramework="net40" />
|
<package id="Autofac" version="2.6.3.862" targetFramework="net40" />
|
||||||
<package id="AutoMoq" version="1.6.1" targetFramework="net40" />
|
<package id="AutoMoq" version="1.6.1" targetFramework="net40" />
|
||||||
<package id="CommonServiceLocator" version="1.0" 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="EloqueraDB" version="5.0.0" targetFramework="net40" />
|
||||||
<package id="FluentAssertions" version="2.0.0.1" targetFramework="net40" />
|
<package id="FluentAssertions" version="2.0.0.1" targetFramework="net40" />
|
||||||
<package id="Microsoft.SqlServer.Compact" version="4.0.8876.1" targetFramework="net40" />
|
<package id="Microsoft.SqlServer.Compact" version="4.0.8876.1" targetFramework="net40" />
|
||||||
|
|
|
@ -1,84 +1,64 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using Eloquera.Client;
|
using Eloquera.Client;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Datastore
|
namespace NzbDrone.Core.Datastore
|
||||||
{
|
{
|
||||||
public class EloqueraDb : IDisposable
|
public class EloqueraDb : IDisposable
|
||||||
{
|
{
|
||||||
private DB _db;
|
private readonly DB _db;
|
||||||
|
|
||||||
public EloqueraDb(DB db)
|
public EloqueraDb(DB db)
|
||||||
{
|
{
|
||||||
_db = db;
|
_db = db;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Create(object obj)
|
public IEnumerable<T> AsQueryable<T>()
|
||||||
{
|
|
||||||
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>()
|
|
||||||
{
|
{
|
||||||
return _db.Query<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);
|
return objects.Select(function).ToList();
|
||||||
}
|
|
||||||
|
|
||||||
public object ExecuteScalar(string query, Parameters parameters)
|
|
||||||
{
|
|
||||||
return _db.ExecuteQuery(query, parameters);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
|
|
@ -1,31 +1,31 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using Eloquera.Client;
|
using Eloquera.Client;
|
||||||
using NzbDrone.Common;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Datastore
|
namespace NzbDrone.Core.Datastore
|
||||||
{
|
{
|
||||||
public class EloqueraDbFactory
|
public class EloqueraDbFactory
|
||||||
{
|
{
|
||||||
private readonly EnvironmentProvider _environmentProvider;
|
public EloqueraDb CreateMemoryDb()
|
||||||
|
|
||||||
public EloqueraDbFactory()
|
|
||||||
{
|
{
|
||||||
_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();
|
var file = new FileInfo(dbPath).Name;
|
||||||
DB.Configuration.ServerSettings.DatabasePath = Path.Combine(_environmentProvider.GetAppDataPath(), dbName);
|
return InternalCreate(string.Format("server=(local);database={0};usedatapath={1};password=;", file, dbPath),file);
|
||||||
db.CreateDatabase(dbName);
|
}
|
||||||
db.OpenDatabase(dbName);
|
|
||||||
db.RefreshMode = ObjectRefreshMode.AlwaysReturnUpdatedValues;
|
|
||||||
|
|
||||||
|
private EloqueraDb InternalCreate(string connectionString, string databaseName)
|
||||||
|
{
|
||||||
|
var db = new DB(connectionString);
|
||||||
|
db.CreateDatabase(databaseName);
|
||||||
|
db.OpenDatabase(databaseName);
|
||||||
return new EloqueraDb(db);
|
return new EloqueraDb(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
using Eloquera.Client;
|
||||||
using NzbDrone.Core.Model;
|
using NzbDrone.Core.Model;
|
||||||
using NzbDrone.Core.Repository.Quality;
|
using NzbDrone.Core.Repository.Quality;
|
||||||
using PetaPoco;
|
using PetaPoco;
|
||||||
|
@ -9,6 +10,10 @@ namespace NzbDrone.Core.Repository
|
||||||
[PrimaryKey("SeriesId", autoIncrement = false)]
|
[PrimaryKey("SeriesId", autoIncrement = false)]
|
||||||
public class Series
|
public class Series
|
||||||
{
|
{
|
||||||
|
|
||||||
|
[ID]
|
||||||
|
public int Id;
|
||||||
|
|
||||||
public virtual int SeriesId { get; set; }
|
public virtual int SeriesId { get; set; }
|
||||||
|
|
||||||
public string Title { 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>
|
/// <value><c>true</c> if hidden; otherwise, <c>false</c>.</value>
|
||||||
/// <remarks>This field will be used for shows that are pending delete or
|
/// <remarks>This field will be used for shows that are pending delete or
|
||||||
/// new series that haven't been successfully imported</remarks>
|
/// new series that haven't been successfully imported</remarks>
|
||||||
[Ignore]
|
[PetaPoco.Ignore]
|
||||||
public bool Hidden { get; set; }
|
public bool Hidden { get; set; }
|
||||||
|
|
||||||
[ResultColumn]
|
[ResultColumn]
|
||||||
|
|
Loading…
Reference in New Issue