mirror of https://github.com/Sonarr/Sonarr
added open generic registration for simple repository, services can now use simple repository independently.
This commit is contained in:
parent
63cf7a3b85
commit
e7deda4d5d
|
@ -50,14 +50,14 @@ namespace NzbDrone.Core.Test.Framework
|
|||
|
||||
protected void WithObjectDb(bool memory = true)
|
||||
{
|
||||
if (memory)
|
||||
{
|
||||
_db = new SiaqoDbFactory(new DiskProvider(),new EnvironmentProvider()).CreateMemoryDb();
|
||||
}
|
||||
else
|
||||
{
|
||||
//if (memory)
|
||||
//{
|
||||
// _db = new SiaqoDbFactory(new DiskProvider(),new EnvironmentProvider()).CreateMemoryDb();
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
_db = new SiaqoDbFactory(new DiskProvider(),new EnvironmentProvider()).Create(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Guid.NewGuid().ToString()));
|
||||
}
|
||||
//}
|
||||
|
||||
Mocker.SetConstant(Db);
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ using FluentAssertions;
|
|||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.RootFolders;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
|
@ -21,7 +22,7 @@ namespace NzbDrone.Core.Test.RootFolderTests
|
|||
[Test]
|
||||
public void should_return_one_drive_when_only_one_root_dir_exists()
|
||||
{
|
||||
Mocker.GetMock<IRootFolderRepository>()
|
||||
Mocker.GetMock<IBasicRepository<RootFolder>>()
|
||||
.Setup(s => s.All())
|
||||
.Returns(new List<RootFolder> { new RootFolder { OID = 1, Path = @"C:\Test\TV" } });
|
||||
|
||||
|
@ -41,7 +42,7 @@ namespace NzbDrone.Core.Test.RootFolderTests
|
|||
[Test]
|
||||
public void should_return_one_drive_when_two_rootDirs_on_the_same_drive_exist()
|
||||
{
|
||||
Mocker.GetMock<IRootFolderRepository>()
|
||||
Mocker.GetMock<IBasicRepository<RootFolder>>()
|
||||
.Setup(s => s.All())
|
||||
.Returns(new List<RootFolder> { new RootFolder { OID = 1, Path = @"C:\Test\TV" },
|
||||
new RootFolder { OID = 2, Path = @"C:\Test\TV2" }});
|
||||
|
@ -62,7 +63,7 @@ namespace NzbDrone.Core.Test.RootFolderTests
|
|||
[Test]
|
||||
public void should_return_two_drives_when_two_rootDirs_on_the_different_drive_exist()
|
||||
{
|
||||
Mocker.GetMock<IRootFolderRepository>()
|
||||
Mocker.GetMock<IBasicRepository<RootFolder>>()
|
||||
.Setup(s => s.All())
|
||||
.Returns(new List<RootFolder> { new RootFolder { OID = 1, Path = @"C:\Test\TV" },
|
||||
new RootFolder { OID = 2, Path = @"D:\Test\TV" }});
|
||||
|
@ -87,7 +88,7 @@ namespace NzbDrone.Core.Test.RootFolderTests
|
|||
[Test]
|
||||
public void should_skip_rootDir_if_not_found_on_disk()
|
||||
{
|
||||
Mocker.GetMock<IRootFolderRepository>()
|
||||
Mocker.GetMock<IBasicRepository<RootFolder>>()
|
||||
.Setup(s => s.All())
|
||||
.Returns(new List<RootFolder> { new RootFolder { OID = 1, Path = @"C:\Test\TV" } });
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ using FluentAssertions;
|
|||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.RootFolders;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
|
@ -24,7 +25,7 @@ namespace NzbDrone.Core.Test.RootFolderTests
|
|||
.Setup(m => m.FolderExists(It.IsAny<string>()))
|
||||
.Returns(true);
|
||||
|
||||
Mocker.GetMock<IRootFolderRepository>()
|
||||
Mocker.GetMock<IBasicRepository<RootFolder>>()
|
||||
.Setup(s => s.All())
|
||||
.Returns(new List<RootFolder>());
|
||||
}
|
||||
|
@ -44,7 +45,7 @@ namespace NzbDrone.Core.Test.RootFolderTests
|
|||
|
||||
Subject.Add(root);
|
||||
|
||||
Mocker.GetMock<IRootFolderRepository>().Verify(c => c.Add(root), Times.Once());
|
||||
Mocker.GetMock<IBasicRepository<RootFolder>>().Verify(c => c.Add(root), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -59,14 +60,14 @@ namespace NzbDrone.Core.Test.RootFolderTests
|
|||
public void should_be_able_to_remove_root_dir()
|
||||
{
|
||||
Subject.Remove(1);
|
||||
Mocker.GetMock<IRootFolderRepository>().Verify(c => c.Delete(1), Times.Once());
|
||||
Mocker.GetMock<IBasicRepository<RootFolder>>().Verify(c => c.Delete(1), Times.Once());
|
||||
}
|
||||
|
||||
public void None_existing_folder_returns_empty_list()
|
||||
{
|
||||
WithNoneExistingFolder();
|
||||
|
||||
Mocker.GetMock<IRootFolderRepository>().Setup(c => c.All()).Returns(new List<RootFolder>());
|
||||
Mocker.GetMock<IBasicRepository<RootFolder>>().Setup(c => c.All()).Returns(new List<RootFolder>());
|
||||
|
||||
const string path = "d:\\bad folder";
|
||||
|
||||
|
@ -96,7 +97,7 @@ namespace NzbDrone.Core.Test.RootFolderTests
|
|||
[Test]
|
||||
public void adding_duplicated_root_folder_should_throw()
|
||||
{
|
||||
Mocker.GetMock<IRootFolderRepository>().Setup(c => c.All()).Returns(new List<RootFolder> { new RootFolder { Path = "C:\\TV" } });
|
||||
Mocker.GetMock<IBasicRepository<RootFolder>>().Setup(c => c.All()).Returns(new List<RootFolder> { new RootFolder { Path = "C:\\TV" } });
|
||||
|
||||
Assert.Throws<InvalidOperationException>(() => Subject.Add(new RootFolder { Path = @"C:\TV" }));
|
||||
}
|
||||
|
|
|
@ -85,6 +85,8 @@ namespace NzbDrone.Core
|
|||
return c.Resolve<IObjectDbFactory>().Create();
|
||||
}).As<IObjectDatabase>().SingleInstance();
|
||||
|
||||
container.RegisterGeneric(typeof(BasicRepository<>)).As(typeof(IBasicRepository<>));
|
||||
|
||||
container.RegisterType<DatabaseTarget>().WithParameter(ResolvedParameter.ForNamed<IDatabase>("DatabaseTarget"));
|
||||
container.RegisterType<LogProvider>().WithParameter(ResolvedParameter.ForNamed<IDatabase>("LogProvider"));
|
||||
}
|
||||
|
|
|
@ -20,14 +20,16 @@ namespace NzbDrone.Core.Datastore
|
|||
|
||||
protected IObjectDatabase ObjectDatabase { get; private set; }
|
||||
|
||||
protected IEnumerable<TModel> Queryable { get { return ObjectDatabase.AsQueryable<TModel>(); } }
|
||||
|
||||
public List<TModel> All()
|
||||
{
|
||||
return ObjectDatabase.AsQueryable<TModel>().ToList();
|
||||
return Queryable.ToList();
|
||||
}
|
||||
|
||||
public TModel Get(int id)
|
||||
{
|
||||
return ObjectDatabase.AsQueryable<TModel>().Single(c => c.OID == id);
|
||||
return Queryable.Single(c => c.OID == id);
|
||||
}
|
||||
|
||||
public TModel Add(TModel model)
|
||||
|
|
|
@ -12,10 +12,6 @@ namespace NzbDrone.Core.Datastore.Migrations
|
|||
{
|
||||
var objectDb = GetObjectDb();
|
||||
|
||||
|
||||
var rootFolderRepo = new RootFolderRepository(objectDb);
|
||||
|
||||
|
||||
using (var dataReader = Database.ExecuteQuery("SELECT * from RootDirs"))
|
||||
{
|
||||
var dirs = new List<RootFolder>();
|
||||
|
@ -26,6 +22,7 @@ namespace NzbDrone.Core.Datastore.Migrations
|
|||
}
|
||||
objectDb.InsertMany(dirs);
|
||||
}
|
||||
|
||||
//Database.RemoveTable("RootDirs");
|
||||
|
||||
}
|
||||
|
|
|
@ -620,7 +620,6 @@
|
|||
<Compile Include="Repository\Series.cs" />
|
||||
<Compile Include="CentralDispatch.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="RootFolders\RootFolderRepository.cs" />
|
||||
<Compile Include="Tvdb\Tvdb.cs" />
|
||||
<Compile Include="Tvdb\Tvdb.Sync.cs" />
|
||||
<Compile Include="Tvdb\TvdbActor.cs" />
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
using NzbDrone.Core.Datastore;
|
||||
using System.Linq;
|
||||
|
||||
namespace NzbDrone.Core.RootFolders
|
||||
{
|
||||
public interface IRootFolderRepository : IBasicRepository<RootFolder>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class RootFolderRepository : BasicRepository<RootFolder>, IRootFolderRepository
|
||||
{
|
||||
public RootFolderRepository(IObjectDatabase objectDatabase)
|
||||
: base(objectDatabase)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,8 +4,8 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Repository;
|
||||
|
||||
namespace NzbDrone.Core.RootFolders
|
||||
{
|
||||
|
@ -21,11 +21,11 @@ namespace NzbDrone.Core.RootFolders
|
|||
public class RootFolderService : IRootFolderService
|
||||
{
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
private readonly IRootFolderRepository _rootFolderRepository;
|
||||
private readonly IBasicRepository<RootFolder> _rootFolderRepository;
|
||||
private readonly DiskProvider _diskProvider;
|
||||
private readonly SeriesProvider _seriesProvider;
|
||||
|
||||
public RootFolderService(IRootFolderRepository rootFolderRepository, SeriesProvider seriesProvider, DiskProvider diskProvider)
|
||||
public RootFolderService(IBasicRepository<RootFolder> rootFolderRepository, SeriesProvider seriesProvider, DiskProvider diskProvider)
|
||||
{
|
||||
_rootFolderRepository = rootFolderRepository;
|
||||
_diskProvider = diskProvider;
|
||||
|
|
Loading…
Reference in New Issue