Renamed SceneNameMapping to SceneMapping.

SceneMappingProvider moved to PetaPoco.
This commit is contained in:
Mark McDowall 2011-06-16 23:04:01 -07:00
parent 310c317361
commit ab26d2dd61
11 changed files with 63 additions and 50 deletions

View File

@ -247,7 +247,7 @@ namespace NzbDrone.Core.Test
mocker.GetMock<InventoryProvider>() mocker.GetMock<InventoryProvider>()
.Setup(c => c.IsQualityNeeded(It.Is<EpisodeParseResult>(d => d.Series != null && d.Episodes.Count != 0))).Returns(false); .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(""); .Setup(s => s.GetSceneName(It.IsAny<int>())).Returns("");
//Act //Act
@ -298,7 +298,7 @@ namespace NzbDrone.Core.Test
mocker.GetMock<InventoryProvider>() mocker.GetMock<InventoryProvider>()
.Setup(c => c.IsQualityNeeded(It.Is<EpisodeParseResult>(d => d.Series != null && d.Episodes.Count != 0))).Returns(false); .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"); .Setup(s => s.GetSceneName(71256)).Returns("The Daily Show");
//Act //Act
@ -355,7 +355,7 @@ namespace NzbDrone.Core.Test
mocker.GetMock<InventoryProvider>() mocker.GetMock<InventoryProvider>()
.Setup(c => c.IsQualityNeeded(It.Is<EpisodeParseResult>(d => d.Series != null && d.Episodes.Count != 0))).Returns(false);; .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(""); .Setup(s => s.GetSceneName(It.IsAny<int>())).Returns("");
//Act //Act

View File

@ -19,25 +19,26 @@ namespace NzbDrone.Core.Test
{ {
[TestFixture] [TestFixture]
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
public class SceneNameHelperTest : TestBase public class SceneMappingTest : TestBase
{ {
[Test] [Test]
public void GetSceneName_exists() public void GetSceneName_exists()
{ {
//Setup //Setup
var fakeMap = Builder<SceneNameMapping>.CreateNew() var fakeMap = Builder<SceneMapping>.CreateNew()
.With(f => f.CleanTitle = "laworder")
.With(f => f.SeriesId = 12345) .With(f => f.SeriesId = 12345)
.With(f => f.SceneName = "Law and Order") .With(f => f.SceneName = "Law and Order")
.Build(); .Build();
var mocker = new AutoMoqer(); var mocker = new AutoMoqer();
mocker.GetMock<IRepository>() var emptyDatabase = MockLib.GetEmptyDatabase();
.Setup(f => f.Single<SceneNameMapping>(It.IsAny<Expression<Func<SceneNameMapping, bool>>>())) mocker.SetConstant(emptyDatabase);
.Returns(fakeMap); emptyDatabase.Insert(fakeMap);
//Act //Act
var sceneName = mocker.Resolve<SceneNameMappingProvider>().GetSceneName(fakeMap.SeriesId); var sceneName = mocker.Resolve<SceneMappingProvider>().GetSceneName(fakeMap.SeriesId);
//Assert //Assert
Assert.AreEqual(fakeMap.SceneName, sceneName); Assert.AreEqual(fakeMap.SceneName, sceneName);
@ -47,7 +48,7 @@ namespace NzbDrone.Core.Test
public void GetSeriesId_exists() public void GetSeriesId_exists()
{ {
//Setup //Setup
var fakeMap = Builder<SceneNameMapping>.CreateNew() var fakeMap = Builder<SceneMapping>.CreateNew()
.With(f => f.SeriesId = 12345) .With(f => f.SeriesId = 12345)
.With(f => f.SceneName = "Law and Order") .With(f => f.SceneName = "Law and Order")
.With(f => f.SceneName = "laworder") .With(f => f.SceneName = "laworder")
@ -55,12 +56,12 @@ namespace NzbDrone.Core.Test
var mocker = new AutoMoqer(); var mocker = new AutoMoqer();
mocker.GetMock<IRepository>() var emptyDatabase = MockLib.GetEmptyDatabase();
.Setup(f => f.Single<SceneNameMapping>(It.IsAny<Expression<Func<SceneNameMapping, bool>>>())) mocker.SetConstant(emptyDatabase);
.Returns(fakeMap); emptyDatabase.Insert(fakeMap);
//Act //Act
var seriesId = mocker.Resolve<SceneNameMappingProvider>().GetSeriesId(fakeMap.SceneCleanName); var seriesId = mocker.Resolve<SceneMappingProvider>().GetSeriesId(fakeMap.CleanTitle);
//Assert //Assert
Assert.AreEqual(fakeMap.SeriesId, seriesId); Assert.AreEqual(fakeMap.SeriesId, seriesId);
@ -70,18 +71,20 @@ namespace NzbDrone.Core.Test
public void GetSceneName_null() public void GetSceneName_null()
{ {
//Setup //Setup
var fakeMap = Builder<SceneNameMapping>.CreateNew() var fakeMap = Builder<SceneMapping>.CreateNew()
.With(f => f.SeriesId = 12345) .With(f => f.SeriesId = 12345)
.With(f => f.SceneName = "Law and Order") .With(f => f.SceneName = "Law and Order")
.With(f => f.SceneName = "laworder")
.Build(); .Build();
var mocker = new AutoMoqer(); var mocker = new AutoMoqer();
mocker.GetMock<IRepository>() var emptyDatabase = MockLib.GetEmptyDatabase();
.Setup(f => f.Single<SceneNameMapping>(It.IsAny<Expression<Func<SceneNameMapping, bool>>>())); mocker.SetConstant(emptyDatabase);
emptyDatabase.Insert(fakeMap);
//Act //Act
var sceneName = mocker.Resolve<SceneNameMappingProvider>().GetSceneName(fakeMap.SeriesId); var sceneName = mocker.Resolve<SceneMappingProvider>().GetSceneName(54321);
//Assert //Assert
Assert.AreEqual(null, sceneName); Assert.AreEqual(null, sceneName);
@ -91,19 +94,20 @@ namespace NzbDrone.Core.Test
public void GetSeriesId_null() public void GetSeriesId_null()
{ {
//Setup //Setup
var fakeMap = Builder<SceneNameMapping>.CreateNew() var fakeMap = Builder<SceneMapping>.CreateNew()
.With(f => f.SeriesId = 12345) .With(f => f.SeriesId = 12345)
.With(f => f.SceneName = "Law and Order") .With(f => f.SceneName = "Law and Order")
.With(f => f.SceneName = "laworder") .With(f => f.CleanTitle = "laworder")
.Build(); .Build();
var mocker = new AutoMoqer(); var mocker = new AutoMoqer();
mocker.GetMock<IRepository>() var emptyDatabase = MockLib.GetEmptyDatabase();
.Setup(f => f.Single<SceneNameMapping>(It.IsAny<Expression<Func<SceneNameMapping, bool>>>())); mocker.SetConstant(emptyDatabase);
emptyDatabase.Insert(fakeMap);
//Act //Act
var seriesId = mocker.Resolve<SceneNameMappingProvider>().GetSeriesId(fakeMap.SceneCleanName); var seriesId = mocker.Resolve<SceneMappingProvider>().GetSeriesId("notlaworder");
//Assert //Assert
Assert.AreEqual(null, seriesId); Assert.AreEqual(null, seriesId);

View File

@ -57,6 +57,11 @@ namespace NzbDrone.Core.Datastore.Migrations
db.CreateTable("Config") db.CreateTable("Config")
.WithNotNullableColumn("Key", DbType.String).Unique() .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);
} }
} }
} }

View File

@ -66,7 +66,7 @@ namespace NzbDrone.Core.Datastore
repository.Single<QualityProfile>(1); repository.Single<QualityProfile>(1);
repository.Single<History>(1); repository.Single<History>(1);
repository.Single<IndexerSetting>(1); repository.Single<IndexerSetting>(1);
repository.Single<SceneNameMapping>(1); repository.Single<SceneMapping>(1);
} }

View File

@ -211,7 +211,7 @@
<Compile Include="Providers\Jobs\IJob.cs" /> <Compile Include="Providers\Jobs\IJob.cs" />
<Compile Include="Providers\Jobs\RssSyncJob.cs" /> <Compile Include="Providers\Jobs\RssSyncJob.cs" />
<Compile Include="Providers\Jobs\UpdateInfoJob.cs" /> <Compile Include="Providers\Jobs\UpdateInfoJob.cs" />
<Compile Include="Providers\SceneNameMappingProvider.cs" /> <Compile Include="Providers\SceneMappingProvider.cs" />
<Compile Include="Providers\StatsProvider.cs" /> <Compile Include="Providers\StatsProvider.cs" />
<Compile Include="Repository\ExternalNotificationSetting.cs" /> <Compile Include="Repository\ExternalNotificationSetting.cs" />
<Compile Include="Repository\JobSetting.cs" /> <Compile Include="Repository\JobSetting.cs" />
@ -254,7 +254,7 @@
<Compile Include="Repository\Quality\QualityProfile.cs" /> <Compile Include="Repository\Quality\QualityProfile.cs" />
<Compile Include="Repository\RootDir.cs" /> <Compile Include="Repository\RootDir.cs" />
<Compile Include="Repository\Quality\QualityTypes.cs" /> <Compile Include="Repository\Quality\QualityTypes.cs" />
<Compile Include="Repository\SceneNameMapping.cs" /> <Compile Include="Repository\SceneMapping.cs" />
<Compile Include="Repository\Series.cs" /> <Compile Include="Repository\Series.cs" />
<Compile Include="CentralDispatch.cs" /> <Compile Include="CentralDispatch.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />

View File

@ -17,13 +17,13 @@ namespace NzbDrone.Core.Providers.Jobs
private readonly DownloadProvider _downloadProvider; private readonly DownloadProvider _downloadProvider;
private readonly IndexerProvider _indexerProvider; private readonly IndexerProvider _indexerProvider;
private readonly EpisodeProvider _episodeProvider; private readonly EpisodeProvider _episodeProvider;
private readonly SceneNameMappingProvider _sceneNameMappingProvider; private readonly SceneMappingProvider _sceneNameMappingProvider;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public EpisodeSearchJob(InventoryProvider inventoryProvider, DownloadProvider downloadProvider, public EpisodeSearchJob(InventoryProvider inventoryProvider, DownloadProvider downloadProvider,
IndexerProvider indexerProvider, EpisodeProvider episodeProvider, IndexerProvider indexerProvider, EpisodeProvider episodeProvider,
SceneNameMappingProvider sceneNameMappingProvider) SceneMappingProvider sceneNameMappingProvider)
{ {
_inventoryProvider = inventoryProvider; _inventoryProvider = inventoryProvider;
_downloadProvider = downloadProvider; _downloadProvider = downloadProvider;

View File

@ -7,9 +7,9 @@ namespace NzbDrone.Core.Providers.Jobs
{ {
public class UpdateSceneMappingsJob : IJob public class UpdateSceneMappingsJob : IJob
{ {
private readonly SceneNameMappingProvider _sceneNameMappingProvider; private readonly SceneMappingProvider _sceneNameMappingProvider;
public UpdateSceneMappingsJob(SceneNameMappingProvider sceneNameMappingProvider) public UpdateSceneMappingsJob(SceneMappingProvider sceneNameMappingProvider)
{ {
_sceneNameMappingProvider = sceneNameMappingProvider; _sceneNameMappingProvider = sceneNameMappingProvider;
} }

View File

@ -7,23 +7,24 @@ using System.Text;
using NLog; using NLog;
using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository; using NzbDrone.Core.Repository;
using PetaPoco;
using SubSonic.Repository; using SubSonic.Repository;
namespace NzbDrone.Core.Providers namespace NzbDrone.Core.Providers
{ {
public class SceneNameMappingProvider public class SceneMappingProvider
{ {
private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly IRepository _repository; private readonly IDatabase _database;
private readonly HttpProvider _httpProvider; private readonly HttpProvider _httpProvider;
public SceneNameMappingProvider(IRepository repository, HttpProvider httpProvider) public SceneMappingProvider(IDatabase database, HttpProvider httpProvider)
{ {
_repository = repository; _database = database;
_httpProvider = httpProvider; _httpProvider = httpProvider;
} }
public SceneNameMappingProvider() public SceneMappingProvider()
{ {
} }
@ -32,8 +33,8 @@ namespace NzbDrone.Core.Providers
{ {
try try
{ {
var mapping = _httpProvider.DownloadString("http://vps.nzbdrone.com/SceneNameMappings.csv"); var mapping = _httpProvider.DownloadString("http://vps.nzbdrone.com/SceneMappings.csv");
var newMaps = new List<SceneNameMapping>(); var newMaps = new List<SceneMapping>();
using (var reader = new StringReader(mapping)) using (var reader = new StringReader(mapping))
{ {
@ -44,8 +45,8 @@ namespace NzbDrone.Core.Providers
var seriesId = 0; var seriesId = 0;
Int32.TryParse(split[1], out seriesId); Int32.TryParse(split[1], out seriesId);
var map = new SceneNameMapping(); var map = new SceneMapping();
map.SceneCleanName = split[0]; map.CleanTitle = split[0];
map.SeriesId = seriesId; map.SeriesId = seriesId;
map.SceneName = split[2]; map.SceneName = split[2];
@ -54,10 +55,10 @@ namespace NzbDrone.Core.Providers
} }
Logger.Debug("Deleting all existing Scene Mappings."); Logger.Debug("Deleting all existing Scene Mappings.");
_repository.DeleteMany<SceneNameMapping>(GetAll()); _database.Delete<SceneMapping>(String.Empty);
Logger.Debug("Adding Scene Mappings"); Logger.Debug("Adding Scene Mappings");
_repository.AddMany(newMaps); _database.InsertMany(newMaps);
} }
catch (Exception ex) catch (Exception ex)
@ -68,14 +69,14 @@ namespace NzbDrone.Core.Providers
return true; 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) 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) if (item == null)
return null; return null;
@ -85,7 +86,7 @@ namespace NzbDrone.Core.Providers
public virtual Nullable<Int32> GetSeriesId(string cleanName) 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) if (item == null)
return null; return null;

View File

@ -18,11 +18,11 @@ namespace NzbDrone.Core.Providers
private readonly TvDbProvider _tvDbProvider; private readonly TvDbProvider _tvDbProvider;
private readonly IDatabase _database; private readonly IDatabase _database;
private readonly QualityProvider _qualityProvider; 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); 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, public SeriesProvider(IDatabase database, ConfigProvider configProviderProvider, QualityProvider qualityProvider,
TvDbProvider tvDbProviderProvider, SceneNameMappingProvider sceneNameMappingProvider) TvDbProvider tvDbProviderProvider, SceneMappingProvider sceneNameMappingProvider)
{ {
_database = database; _database = database;
_configProvider = configProviderProvider; _configProvider = configProviderProvider;

View File

@ -2,14 +2,17 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using PetaPoco;
using SubSonic.SqlGeneration.Schema; using SubSonic.SqlGeneration.Schema;
namespace NzbDrone.Core.Repository namespace NzbDrone.Core.Repository
{ {
public class SceneNameMapping [TableName("SceneMappings")]
[PrimaryKey("CleanTitle", autoIncrement = false)]
public class SceneMapping
{ {
[SubSonicPrimaryKey] [SubSonicPrimaryKey]
public virtual string SceneCleanName { get; set; } public virtual string CleanTitle { get; set; }
public virtual int SeriesId { get; set; } public virtual int SeriesId { get; set; }