Renamed SceneNameMapping to SceneMapping.
SceneMappingProvider moved to PetaPoco.
This commit is contained in:
parent
310c317361
commit
ab26d2dd61
|
@ -247,7 +247,7 @@ namespace NzbDrone.Core.Test
|
|||
mocker.GetMock<InventoryProvider>()
|
||||
.Setup(c => c.IsQualityNeeded(It.Is<EpisodeParseResult>(d => d.Series != null && d.Episodes.Count != 0))).Returns(false);
|
||||
|
||||
mocker.GetMock<SceneNameMappingProvider>()
|
||||
mocker.GetMock<SceneMappingProvider>()
|
||||
.Setup(s => s.GetSceneName(It.IsAny<int>())).Returns("");
|
||||
|
||||
//Act
|
||||
|
@ -298,7 +298,7 @@ namespace NzbDrone.Core.Test
|
|||
mocker.GetMock<InventoryProvider>()
|
||||
.Setup(c => c.IsQualityNeeded(It.Is<EpisodeParseResult>(d => d.Series != null && d.Episodes.Count != 0))).Returns(false);
|
||||
|
||||
mocker.GetMock<SceneNameMappingProvider>()
|
||||
mocker.GetMock<SceneMappingProvider>()
|
||||
.Setup(s => s.GetSceneName(71256)).Returns("The Daily Show");
|
||||
|
||||
//Act
|
||||
|
@ -355,7 +355,7 @@ namespace NzbDrone.Core.Test
|
|||
mocker.GetMock<InventoryProvider>()
|
||||
.Setup(c => c.IsQualityNeeded(It.Is<EpisodeParseResult>(d => d.Series != null && d.Episodes.Count != 0))).Returns(false);;
|
||||
|
||||
mocker.GetMock<SceneNameMappingProvider>()
|
||||
mocker.GetMock<SceneMappingProvider>()
|
||||
.Setup(s => s.GetSceneName(It.IsAny<int>())).Returns("");
|
||||
|
||||
//Act
|
||||
|
|
|
@ -19,25 +19,26 @@ namespace NzbDrone.Core.Test
|
|||
{
|
||||
[TestFixture]
|
||||
// ReSharper disable InconsistentNaming
|
||||
public class SceneNameHelperTest : TestBase
|
||||
public class SceneMappingTest : TestBase
|
||||
{
|
||||
[Test]
|
||||
public void GetSceneName_exists()
|
||||
{
|
||||
//Setup
|
||||
var fakeMap = Builder<SceneNameMapping>.CreateNew()
|
||||
var fakeMap = Builder<SceneMapping>.CreateNew()
|
||||
.With(f => f.CleanTitle = "laworder")
|
||||
.With(f => f.SeriesId = 12345)
|
||||
.With(f => f.SceneName = "Law and Order")
|
||||
.Build();
|
||||
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
mocker.GetMock<IRepository>()
|
||||
.Setup(f => f.Single<SceneNameMapping>(It.IsAny<Expression<Func<SceneNameMapping, bool>>>()))
|
||||
.Returns(fakeMap);
|
||||
var emptyDatabase = MockLib.GetEmptyDatabase();
|
||||
mocker.SetConstant(emptyDatabase);
|
||||
emptyDatabase.Insert(fakeMap);
|
||||
|
||||
//Act
|
||||
var sceneName = mocker.Resolve<SceneNameMappingProvider>().GetSceneName(fakeMap.SeriesId);
|
||||
var sceneName = mocker.Resolve<SceneMappingProvider>().GetSceneName(fakeMap.SeriesId);
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual(fakeMap.SceneName, sceneName);
|
||||
|
@ -47,7 +48,7 @@ namespace NzbDrone.Core.Test
|
|||
public void GetSeriesId_exists()
|
||||
{
|
||||
//Setup
|
||||
var fakeMap = Builder<SceneNameMapping>.CreateNew()
|
||||
var fakeMap = Builder<SceneMapping>.CreateNew()
|
||||
.With(f => f.SeriesId = 12345)
|
||||
.With(f => f.SceneName = "Law and Order")
|
||||
.With(f => f.SceneName = "laworder")
|
||||
|
@ -55,12 +56,12 @@ namespace NzbDrone.Core.Test
|
|||
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
mocker.GetMock<IRepository>()
|
||||
.Setup(f => f.Single<SceneNameMapping>(It.IsAny<Expression<Func<SceneNameMapping, bool>>>()))
|
||||
.Returns(fakeMap);
|
||||
var emptyDatabase = MockLib.GetEmptyDatabase();
|
||||
mocker.SetConstant(emptyDatabase);
|
||||
emptyDatabase.Insert(fakeMap);
|
||||
|
||||
//Act
|
||||
var seriesId = mocker.Resolve<SceneNameMappingProvider>().GetSeriesId(fakeMap.SceneCleanName);
|
||||
var seriesId = mocker.Resolve<SceneMappingProvider>().GetSeriesId(fakeMap.CleanTitle);
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual(fakeMap.SeriesId, seriesId);
|
||||
|
@ -70,18 +71,20 @@ namespace NzbDrone.Core.Test
|
|||
public void GetSceneName_null()
|
||||
{
|
||||
//Setup
|
||||
var fakeMap = Builder<SceneNameMapping>.CreateNew()
|
||||
var fakeMap = Builder<SceneMapping>.CreateNew()
|
||||
.With(f => f.SeriesId = 12345)
|
||||
.With(f => f.SceneName = "Law and Order")
|
||||
.With(f => f.SceneName = "laworder")
|
||||
.Build();
|
||||
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
mocker.GetMock<IRepository>()
|
||||
.Setup(f => f.Single<SceneNameMapping>(It.IsAny<Expression<Func<SceneNameMapping, bool>>>()));
|
||||
var emptyDatabase = MockLib.GetEmptyDatabase();
|
||||
mocker.SetConstant(emptyDatabase);
|
||||
emptyDatabase.Insert(fakeMap);
|
||||
|
||||
//Act
|
||||
var sceneName = mocker.Resolve<SceneNameMappingProvider>().GetSceneName(fakeMap.SeriesId);
|
||||
var sceneName = mocker.Resolve<SceneMappingProvider>().GetSceneName(54321);
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual(null, sceneName);
|
||||
|
@ -91,19 +94,20 @@ namespace NzbDrone.Core.Test
|
|||
public void GetSeriesId_null()
|
||||
{
|
||||
//Setup
|
||||
var fakeMap = Builder<SceneNameMapping>.CreateNew()
|
||||
var fakeMap = Builder<SceneMapping>.CreateNew()
|
||||
.With(f => f.SeriesId = 12345)
|
||||
.With(f => f.SceneName = "Law and Order")
|
||||
.With(f => f.SceneName = "laworder")
|
||||
.With(f => f.CleanTitle = "laworder")
|
||||
.Build();
|
||||
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
mocker.GetMock<IRepository>()
|
||||
.Setup(f => f.Single<SceneNameMapping>(It.IsAny<Expression<Func<SceneNameMapping, bool>>>()));
|
||||
var emptyDatabase = MockLib.GetEmptyDatabase();
|
||||
mocker.SetConstant(emptyDatabase);
|
||||
emptyDatabase.Insert(fakeMap);
|
||||
|
||||
//Act
|
||||
var seriesId = mocker.Resolve<SceneNameMappingProvider>().GetSeriesId(fakeMap.SceneCleanName);
|
||||
var seriesId = mocker.Resolve<SceneMappingProvider>().GetSeriesId("notlaworder");
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual(null, seriesId);
|
|
@ -56,7 +56,12 @@ namespace NzbDrone.Core.Datastore.Migrations
|
|||
|
||||
db.CreateTable("Config")
|
||||
.WithNotNullableColumn("Key", DbType.String).Unique()
|
||||
.WithNotNullableColumn("Value", DbType.String);
|
||||
.WithNotNullableColumn("Value", DbType.String);
|
||||
|
||||
db.CreateTable("SceneMappings")
|
||||
.WithNotNullableColumn("CleanTitle", DbType.String).Unique()
|
||||
.WithNotNullableColumn("SeriesId", DbType.Int32)
|
||||
.WithNotNullableColumn("SceneName", DbType.String);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ namespace NzbDrone.Core.Datastore
|
|||
repository.Single<QualityProfile>(1);
|
||||
repository.Single<History>(1);
|
||||
repository.Single<IndexerSetting>(1);
|
||||
repository.Single<SceneNameMapping>(1);
|
||||
repository.Single<SceneMapping>(1);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -211,7 +211,7 @@
|
|||
<Compile Include="Providers\Jobs\IJob.cs" />
|
||||
<Compile Include="Providers\Jobs\RssSyncJob.cs" />
|
||||
<Compile Include="Providers\Jobs\UpdateInfoJob.cs" />
|
||||
<Compile Include="Providers\SceneNameMappingProvider.cs" />
|
||||
<Compile Include="Providers\SceneMappingProvider.cs" />
|
||||
<Compile Include="Providers\StatsProvider.cs" />
|
||||
<Compile Include="Repository\ExternalNotificationSetting.cs" />
|
||||
<Compile Include="Repository\JobSetting.cs" />
|
||||
|
@ -254,7 +254,7 @@
|
|||
<Compile Include="Repository\Quality\QualityProfile.cs" />
|
||||
<Compile Include="Repository\RootDir.cs" />
|
||||
<Compile Include="Repository\Quality\QualityTypes.cs" />
|
||||
<Compile Include="Repository\SceneNameMapping.cs" />
|
||||
<Compile Include="Repository\SceneMapping.cs" />
|
||||
<Compile Include="Repository\Series.cs" />
|
||||
<Compile Include="CentralDispatch.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
|
|
|
@ -17,13 +17,13 @@ namespace NzbDrone.Core.Providers.Jobs
|
|||
private readonly DownloadProvider _downloadProvider;
|
||||
private readonly IndexerProvider _indexerProvider;
|
||||
private readonly EpisodeProvider _episodeProvider;
|
||||
private readonly SceneNameMappingProvider _sceneNameMappingProvider;
|
||||
private readonly SceneMappingProvider _sceneNameMappingProvider;
|
||||
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public EpisodeSearchJob(InventoryProvider inventoryProvider, DownloadProvider downloadProvider,
|
||||
IndexerProvider indexerProvider, EpisodeProvider episodeProvider,
|
||||
SceneNameMappingProvider sceneNameMappingProvider)
|
||||
SceneMappingProvider sceneNameMappingProvider)
|
||||
{
|
||||
_inventoryProvider = inventoryProvider;
|
||||
_downloadProvider = downloadProvider;
|
||||
|
|
|
@ -7,9 +7,9 @@ namespace NzbDrone.Core.Providers.Jobs
|
|||
{
|
||||
public class UpdateSceneMappingsJob : IJob
|
||||
{
|
||||
private readonly SceneNameMappingProvider _sceneNameMappingProvider;
|
||||
private readonly SceneMappingProvider _sceneNameMappingProvider;
|
||||
|
||||
public UpdateSceneMappingsJob(SceneNameMappingProvider sceneNameMappingProvider)
|
||||
public UpdateSceneMappingsJob(SceneMappingProvider sceneNameMappingProvider)
|
||||
{
|
||||
_sceneNameMappingProvider = sceneNameMappingProvider;
|
||||
}
|
||||
|
|
|
@ -7,23 +7,24 @@ using System.Text;
|
|||
using NLog;
|
||||
using NzbDrone.Core.Providers.Core;
|
||||
using NzbDrone.Core.Repository;
|
||||
using PetaPoco;
|
||||
using SubSonic.Repository;
|
||||
|
||||
namespace NzbDrone.Core.Providers
|
||||
{
|
||||
public class SceneNameMappingProvider
|
||||
public class SceneMappingProvider
|
||||
{
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
private readonly IRepository _repository;
|
||||
private readonly IDatabase _database;
|
||||
private readonly HttpProvider _httpProvider;
|
||||
|
||||
public SceneNameMappingProvider(IRepository repository, HttpProvider httpProvider)
|
||||
public SceneMappingProvider(IDatabase database, HttpProvider httpProvider)
|
||||
{
|
||||
_repository = repository;
|
||||
_database = database;
|
||||
_httpProvider = httpProvider;
|
||||
}
|
||||
|
||||
public SceneNameMappingProvider()
|
||||
public SceneMappingProvider()
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -32,8 +33,8 @@ namespace NzbDrone.Core.Providers
|
|||
{
|
||||
try
|
||||
{
|
||||
var mapping = _httpProvider.DownloadString("http://vps.nzbdrone.com/SceneNameMappings.csv");
|
||||
var newMaps = new List<SceneNameMapping>();
|
||||
var mapping = _httpProvider.DownloadString("http://vps.nzbdrone.com/SceneMappings.csv");
|
||||
var newMaps = new List<SceneMapping>();
|
||||
|
||||
using (var reader = new StringReader(mapping))
|
||||
{
|
||||
|
@ -44,8 +45,8 @@ namespace NzbDrone.Core.Providers
|
|||
var seriesId = 0;
|
||||
Int32.TryParse(split[1], out seriesId);
|
||||
|
||||
var map = new SceneNameMapping();
|
||||
map.SceneCleanName = split[0];
|
||||
var map = new SceneMapping();
|
||||
map.CleanTitle = split[0];
|
||||
map.SeriesId = seriesId;
|
||||
map.SceneName = split[2];
|
||||
|
||||
|
@ -54,10 +55,10 @@ namespace NzbDrone.Core.Providers
|
|||
}
|
||||
|
||||
Logger.Debug("Deleting all existing Scene Mappings.");
|
||||
_repository.DeleteMany<SceneNameMapping>(GetAll());
|
||||
_database.Delete<SceneMapping>(String.Empty);
|
||||
|
||||
Logger.Debug("Adding Scene Mappings");
|
||||
_repository.AddMany(newMaps);
|
||||
_database.InsertMany(newMaps);
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
|
@ -68,14 +69,14 @@ namespace NzbDrone.Core.Providers
|
|||
return true;
|
||||
}
|
||||
|
||||
public virtual List<SceneNameMapping> GetAll()
|
||||
public virtual List<SceneMapping> GetAll()
|
||||
{
|
||||
return _repository.All<SceneNameMapping>().ToList();
|
||||
return _database.Fetch<SceneMapping>();
|
||||
}
|
||||
|
||||
public virtual string GetSceneName(int seriesId)
|
||||
{
|
||||
var item = _repository.Single<SceneNameMapping>(s => s.SeriesId == seriesId);
|
||||
var item = _database.SingleOrDefault<SceneMapping>("WHERE SeriesId = @0", seriesId);
|
||||
|
||||
if (item == null)
|
||||
return null;
|
||||
|
@ -85,7 +86,7 @@ namespace NzbDrone.Core.Providers
|
|||
|
||||
public virtual Nullable<Int32> GetSeriesId(string cleanName)
|
||||
{
|
||||
var item = _repository.Single<SceneNameMapping>(s => s.SceneCleanName == cleanName);
|
||||
var item = _database.SingleOrDefault<SceneMapping>("WHERE CleanTitle = @0", cleanName);
|
||||
|
||||
if (item == null)
|
||||
return null;
|
|
@ -18,11 +18,11 @@ namespace NzbDrone.Core.Providers
|
|||
private readonly TvDbProvider _tvDbProvider;
|
||||
private readonly IDatabase _database;
|
||||
private readonly QualityProvider _qualityProvider;
|
||||
private readonly SceneNameMappingProvider _sceneNameMappingProvider;
|
||||
private readonly SceneMappingProvider _sceneNameMappingProvider;
|
||||
private static readonly Regex TimeRegex = new Regex(@"^(?<time>\d+:?\d*)\W*(?<meridiem>am|pm)?", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||
|
||||
public SeriesProvider(IDatabase database, ConfigProvider configProviderProvider, QualityProvider qualityProvider,
|
||||
TvDbProvider tvDbProviderProvider, SceneNameMappingProvider sceneNameMappingProvider)
|
||||
TvDbProvider tvDbProviderProvider, SceneMappingProvider sceneNameMappingProvider)
|
||||
{
|
||||
_database = database;
|
||||
_configProvider = configProviderProvider;
|
||||
|
|
|
@ -2,14 +2,17 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using PetaPoco;
|
||||
using SubSonic.SqlGeneration.Schema;
|
||||
|
||||
namespace NzbDrone.Core.Repository
|
||||
{
|
||||
public class SceneNameMapping
|
||||
[TableName("SceneMappings")]
|
||||
[PrimaryKey("CleanTitle", autoIncrement = false)]
|
||||
public class SceneMapping
|
||||
{
|
||||
[SubSonicPrimaryKey]
|
||||
public virtual string SceneCleanName { get; set; }
|
||||
public virtual string CleanTitle { get; set; }
|
||||
|
||||
public virtual int SeriesId { get; set; }
|
||||
|
Loading…
Reference in New Issue