1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2025-07-11 01:10:36 +02:00
Files
Sonarr/NzbDrone.Core.Test/Framework/ObjectDbTest.cs

93 lines
2.1 KiB
C#
Raw Normal View History

2013-02-03 16:10:15 -08:00
using System;
2013-02-23 11:38:25 -08:00
using System.Collections.Generic;
2013-02-16 16:50:04 -08:00
using System.IO;
2013-02-03 16:10:15 -08:00
using System.Linq;
using NUnit.Framework;
2013-02-03 20:18:59 -08:00
using NzbDrone.Common;
2013-02-03 16:10:15 -08:00
using NzbDrone.Core.Datastore;
namespace NzbDrone.Core.Test.Framework
{
2013-02-23 11:38:25 -08:00
public abstract class ObjectDbTest<TSubject, TModel> : ObjectDbTest
where TSubject : class
where TModel : ModelBase, new()
{
2013-02-23 11:38:25 -08:00
private TSubject _subject;
protected BasicRepository<TModel> Storage { get; private set; }
2013-02-23 11:38:25 -08:00
protected IList<TModel> AllStoredModels
{
2013-02-23 11:38:25 -08:00
get
{
return Storage.All().ToList();
}
}
2013-02-23 11:38:25 -08:00
protected TModel StoredModel
{
get
{
return Storage.All().Single();
}
}
[SetUp]
public void CoreTestSetup()
{
_subject = null;
2013-02-23 11:38:25 -08:00
Storage = Mocker.Resolve<BasicRepository<TModel>>();
}
protected TSubject Subject
{
get
{
if (_subject == null)
{
_subject = Mocker.Resolve<TSubject>();
}
return _subject;
}
}
}
2013-02-03 16:10:15 -08:00
public abstract class ObjectDbTest : CoreTest
{
2013-02-16 17:52:40 -08:00
private IObjectDatabase _db;
protected IObjectDatabase Db
2013-02-03 16:10:15 -08: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;
}
}
2013-02-23 11:38:25 -08:00
private void WithObjectDb(bool memory = true)
2013-02-03 16:10:15 -08:00
{
_db = new SiaqoDbFactory(new DiskProvider(), new EnvironmentProvider()).Create(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Guid.NewGuid().ToString()));
2013-02-03 16:10:15 -08:00
Mocker.SetConstant(Db);
}
2013-02-23 11:38:25 -08:00
[SetUp]
public void SetupReadDb()
{
WithObjectDb();
}
2013-02-03 16:10:15 -08:00
[TearDown]
public void ObjectDbTearDown()
{
if (_db != null)
{
_db.Dispose();
}
}
}
}