2013-02-04 00:10:15 +00:00
|
|
|
|
using System;
|
2013-02-17 00:50:04 +00:00
|
|
|
|
using System.IO;
|
2013-02-04 00:10:15 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using NUnit.Framework;
|
2013-02-04 04:18:59 +00:00
|
|
|
|
using NzbDrone.Common;
|
2013-02-04 00:10:15 +00:00
|
|
|
|
using NzbDrone.Core.Datastore;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.Framework
|
|
|
|
|
{
|
2013-02-16 03:50:22 +00:00
|
|
|
|
|
2013-02-18 07:59:43 +00:00
|
|
|
|
|
|
|
|
|
public abstract class RepositoryTest<TRepository, TModel> : ObjectDbTest<TRepository>
|
|
|
|
|
where TRepository : class, IBasicRepository<TModel>
|
|
|
|
|
where TModel : ModelBase, new()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
protected BasicRepository<TModel> Storage { get; private set; }
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void RepositoryTestSetup()
|
|
|
|
|
{
|
|
|
|
|
WithObjectDb();
|
|
|
|
|
Storage = Mocker.Resolve<BasicRepository<TModel>>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-16 03:50:22 +00:00
|
|
|
|
public abstract class ObjectDbTest<TSubject> : ObjectDbTest where TSubject : class
|
|
|
|
|
{
|
|
|
|
|
private TSubject _subject;
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void CoreTestSetup()
|
|
|
|
|
{
|
|
|
|
|
_subject = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected TSubject Subject
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (_subject == null)
|
|
|
|
|
{
|
|
|
|
|
_subject = Mocker.Resolve<TSubject>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _subject;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-04 00:10:15 +00:00
|
|
|
|
public abstract class ObjectDbTest : CoreTest
|
|
|
|
|
{
|
2013-02-16 03:50:22 +00:00
|
|
|
|
|
2013-02-17 01:52:40 +00:00
|
|
|
|
private IObjectDatabase _db;
|
|
|
|
|
protected IObjectDatabase Db
|
2013-02-04 00:10:15 +00:00
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
2013-02-17 05:09:35 +00:00
|
|
|
|
//if (memory)
|
|
|
|
|
//{
|
|
|
|
|
// _db = new SiaqoDbFactory(new DiskProvider(),new EnvironmentProvider()).CreateMemoryDb();
|
|
|
|
|
//}
|
|
|
|
|
//else
|
|
|
|
|
//{
|
2013-02-18 07:59:43 +00:00
|
|
|
|
_db = new SiaqoDbFactory(new DiskProvider(), new EnvironmentProvider()).Create(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Guid.NewGuid().ToString()));
|
2013-02-17 05:09:35 +00:00
|
|
|
|
//}
|
2013-02-04 00:10:15 +00:00
|
|
|
|
|
|
|
|
|
Mocker.SetConstant(Db);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TearDown]
|
|
|
|
|
public void ObjectDbTearDown()
|
|
|
|
|
{
|
|
|
|
|
if (_db != null)
|
|
|
|
|
{
|
|
|
|
|
_db.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|