2013-02-04 03:10:15 +03:00
|
|
|
using System;
|
2013-02-17 03:50:04 +03:00
|
|
|
using System.IO;
|
2013-02-04 03:10:15 +03:00
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
2013-02-04 07:18:59 +03:00
|
|
|
using NzbDrone.Common;
|
2013-02-04 03:10:15 +03:00
|
|
|
using NzbDrone.Core.Datastore;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.Framework
|
|
|
|
{
|
2013-02-16 06:50:22 +03: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 03:10:15 +03:00
|
|
|
public abstract class ObjectDbTest : CoreTest
|
|
|
|
{
|
2013-02-16 06:50:22 +03:00
|
|
|
|
2013-02-04 03:10:15 +03:00
|
|
|
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)
|
|
|
|
{
|
2013-02-04 07:18:59 +03:00
|
|
|
_db = new EloqueraDbFactory(new EnvironmentProvider()).CreateMemoryDb();
|
2013-02-04 03:10:15 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-02-17 03:50:04 +03:00
|
|
|
_db = new EloqueraDbFactory(new EnvironmentProvider()).Create(Path.Combine(Environment.CurrentDirectory,Guid.NewGuid().ToString()+ ".elq"));
|
2013-02-04 03:10:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Mocker.SetConstant(Db);
|
2013-02-16 06:50:22 +03:00
|
|
|
Mocker.SetConstant(Db.Db);
|
2013-02-04 03:10:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[TearDown]
|
|
|
|
public void ObjectDbTearDown()
|
|
|
|
{
|
|
|
|
if (_db != null)
|
|
|
|
{
|
|
|
|
_db.Dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|