diff --git a/NzbDrone.Core.Test/EpisodeSearchJobTest.cs b/NzbDrone.Core.Test/EpisodeSearchJobTest.cs index 1e7be7186..26ea4c501 100644 --- a/NzbDrone.Core.Test/EpisodeSearchJobTest.cs +++ b/NzbDrone.Core.Test/EpisodeSearchJobTest.cs @@ -247,7 +247,7 @@ public void start_should_search_all_providers() mocker.GetMock() .Setup(c => c.IsQualityNeeded(It.Is(d => d.Series != null && d.Episodes.Count != 0))).Returns(false); - mocker.GetMock() + mocker.GetMock() .Setup(s => s.GetSceneName(It.IsAny())).Returns(""); //Act @@ -298,7 +298,7 @@ public void start_should_use_scene_name_to_search() mocker.GetMock() .Setup(c => c.IsQualityNeeded(It.Is(d => d.Series != null && d.Episodes.Count != 0))).Returns(false); - mocker.GetMock() + mocker.GetMock() .Setup(s => s.GetSceneName(71256)).Returns("The Daily Show"); //Act @@ -355,7 +355,7 @@ public void start_failed_indexer_should_not_break_job() mocker.GetMock() .Setup(c => c.IsQualityNeeded(It.Is(d => d.Series != null && d.Episodes.Count != 0))).Returns(false);; - mocker.GetMock() + mocker.GetMock() .Setup(s => s.GetSceneName(It.IsAny())).Returns(""); //Act diff --git a/NzbDrone.Core.Test/SceneNameHelperTest.cs b/NzbDrone.Core.Test/SceneMappingTest.cs similarity index 59% rename from NzbDrone.Core.Test/SceneNameHelperTest.cs rename to NzbDrone.Core.Test/SceneMappingTest.cs index 56b5c3cd8..f5d49708c 100644 --- a/NzbDrone.Core.Test/SceneNameHelperTest.cs +++ b/NzbDrone.Core.Test/SceneMappingTest.cs @@ -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.CreateNew() + var fakeMap = Builder.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() - .Setup(f => f.Single(It.IsAny>>())) - .Returns(fakeMap); + var emptyDatabase = MockLib.GetEmptyDatabase(); + mocker.SetConstant(emptyDatabase); + emptyDatabase.Insert(fakeMap); //Act - var sceneName = mocker.Resolve().GetSceneName(fakeMap.SeriesId); + var sceneName = mocker.Resolve().GetSceneName(fakeMap.SeriesId); //Assert Assert.AreEqual(fakeMap.SceneName, sceneName); @@ -47,7 +48,7 @@ public void GetSceneName_exists() public void GetSeriesId_exists() { //Setup - var fakeMap = Builder.CreateNew() + var fakeMap = Builder.CreateNew() .With(f => f.SeriesId = 12345) .With(f => f.SceneName = "Law and Order") .With(f => f.SceneName = "laworder") @@ -55,12 +56,12 @@ public void GetSeriesId_exists() var mocker = new AutoMoqer(); - mocker.GetMock() - .Setup(f => f.Single(It.IsAny>>())) - .Returns(fakeMap); + var emptyDatabase = MockLib.GetEmptyDatabase(); + mocker.SetConstant(emptyDatabase); + emptyDatabase.Insert(fakeMap); //Act - var seriesId = mocker.Resolve().GetSeriesId(fakeMap.SceneCleanName); + var seriesId = mocker.Resolve().GetSeriesId(fakeMap.CleanTitle); //Assert Assert.AreEqual(fakeMap.SeriesId, seriesId); @@ -70,18 +71,20 @@ public void GetSeriesId_exists() public void GetSceneName_null() { //Setup - var fakeMap = Builder.CreateNew() + var fakeMap = Builder.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() - .Setup(f => f.Single(It.IsAny>>())); + var emptyDatabase = MockLib.GetEmptyDatabase(); + mocker.SetConstant(emptyDatabase); + emptyDatabase.Insert(fakeMap); //Act - var sceneName = mocker.Resolve().GetSceneName(fakeMap.SeriesId); + var sceneName = mocker.Resolve().GetSceneName(54321); //Assert Assert.AreEqual(null, sceneName); @@ -91,19 +94,20 @@ public void GetSceneName_null() public void GetSeriesId_null() { //Setup - var fakeMap = Builder.CreateNew() + var fakeMap = Builder.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() - .Setup(f => f.Single(It.IsAny>>())); + var emptyDatabase = MockLib.GetEmptyDatabase(); + mocker.SetConstant(emptyDatabase); + emptyDatabase.Insert(fakeMap); //Act - var seriesId = mocker.Resolve().GetSeriesId(fakeMap.SceneCleanName); + var seriesId = mocker.Resolve().GetSeriesId("notlaworder"); //Assert Assert.AreEqual(null, seriesId); diff --git a/NzbDrone.Core/Datastore/Migrations/MigrationExport.cs b/NzbDrone.Core/Datastore/Migrations/MigrationExport.cs index d7714ab1a..1f6863fd6 100644 --- a/NzbDrone.Core/Datastore/Migrations/MigrationExport.cs +++ b/NzbDrone.Core/Datastore/Migrations/MigrationExport.cs @@ -56,7 +56,12 @@ public void Up(IDatabase db) 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); } } } diff --git a/NzbDrone.Core/Datastore/MigrationsHelper.cs b/NzbDrone.Core/Datastore/MigrationsHelper.cs index 192c1cd23..b0458d246 100644 --- a/NzbDrone.Core/Datastore/MigrationsHelper.cs +++ b/NzbDrone.Core/Datastore/MigrationsHelper.cs @@ -66,7 +66,7 @@ public static void ForceSubSonicMigration(IRepository repository) repository.Single(1); repository.Single(1); repository.Single(1); - repository.Single(1); + repository.Single(1); } diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index a4df3b791..c16233b1f 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -211,7 +211,7 @@ - + @@ -254,7 +254,7 @@ - + diff --git a/NzbDrone.Core/Providers/Jobs/EpisodeSearchJob.cs b/NzbDrone.Core/Providers/Jobs/EpisodeSearchJob.cs index 9e4f22769..b8842e6fe 100644 --- a/NzbDrone.Core/Providers/Jobs/EpisodeSearchJob.cs +++ b/NzbDrone.Core/Providers/Jobs/EpisodeSearchJob.cs @@ -17,13 +17,13 @@ public class EpisodeSearchJob : IJob 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; diff --git a/NzbDrone.Core/Providers/Jobs/UpdateSceneMappingsJob.cs b/NzbDrone.Core/Providers/Jobs/UpdateSceneMappingsJob.cs index ad517287e..179b7162f 100644 --- a/NzbDrone.Core/Providers/Jobs/UpdateSceneMappingsJob.cs +++ b/NzbDrone.Core/Providers/Jobs/UpdateSceneMappingsJob.cs @@ -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; } diff --git a/NzbDrone.Core/Providers/SceneNameMappingProvider.cs b/NzbDrone.Core/Providers/SceneMappingProvider.cs similarity index 68% rename from NzbDrone.Core/Providers/SceneNameMappingProvider.cs rename to NzbDrone.Core/Providers/SceneMappingProvider.cs index fd6869edd..f4d3269d5 100644 --- a/NzbDrone.Core/Providers/SceneNameMappingProvider.cs +++ b/NzbDrone.Core/Providers/SceneMappingProvider.cs @@ -7,23 +7,24 @@ 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 @@ public virtual bool UpdateMappings() { try { - var mapping = _httpProvider.DownloadString("http://vps.nzbdrone.com/SceneNameMappings.csv"); - var newMaps = new List(); + var mapping = _httpProvider.DownloadString("http://vps.nzbdrone.com/SceneMappings.csv"); + var newMaps = new List(); using (var reader = new StringReader(mapping)) { @@ -44,8 +45,8 @@ public virtual bool UpdateMappings() 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 @@ public virtual bool UpdateMappings() } Logger.Debug("Deleting all existing Scene Mappings."); - _repository.DeleteMany(GetAll()); + _database.Delete(String.Empty); Logger.Debug("Adding Scene Mappings"); - _repository.AddMany(newMaps); + _database.InsertMany(newMaps); } catch (Exception ex) @@ -68,14 +69,14 @@ public virtual bool UpdateMappings() return true; } - public virtual List GetAll() + public virtual List GetAll() { - return _repository.All().ToList(); + return _database.Fetch(); } public virtual string GetSceneName(int seriesId) { - var item = _repository.Single(s => s.SeriesId == seriesId); + var item = _database.SingleOrDefault("WHERE SeriesId = @0", seriesId); if (item == null) return null; @@ -85,7 +86,7 @@ public virtual string GetSceneName(int seriesId) public virtual Nullable GetSeriesId(string cleanName) { - var item = _repository.Single(s => s.SceneCleanName == cleanName); + var item = _database.SingleOrDefault("WHERE CleanTitle = @0", cleanName); if (item == null) return null; diff --git a/NzbDrone.Core/Providers/SeriesProvider.cs b/NzbDrone.Core/Providers/SeriesProvider.cs index a72080d93..5e1b64b5b 100644 --- a/NzbDrone.Core/Providers/SeriesProvider.cs +++ b/NzbDrone.Core/Providers/SeriesProvider.cs @@ -18,11 +18,11 @@ public class SeriesProvider 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(@"^(?