diff --git a/NzbDrone.Core.Test/QualityProfileTest.cs b/NzbDrone.Core.Test/QualityProfileTest.cs index 76ba97b57..773dc524b 100644 --- a/NzbDrone.Core.Test/QualityProfileTest.cs +++ b/NzbDrone.Core.Test/QualityProfileTest.cs @@ -22,7 +22,7 @@ namespace NzbDrone.Core.Test public void Test_Storage() { //Arrange - var repo = MockLib.GetEmptyRepository(); + var database = MockLib.GetEmptyDatabase(); var testProfile = new QualityProfile { Name = Guid.NewGuid().ToString(), @@ -31,8 +31,8 @@ namespace NzbDrone.Core.Test }; //Act - var id = (int)repo.Add(testProfile); - var fetch = repo.Single(c => c.QualityProfileId == id); + var id = Convert.ToInt32(database.Insert(testProfile)); + var fetch = database.SingleOrDefault(id); //Assert Assert.AreEqual(id, fetch.QualityProfileId); @@ -45,7 +45,7 @@ namespace NzbDrone.Core.Test public void Test_Series_Quality() { //Arrange - var repo = MockLib.GetEmptyRepository(); + var database = MockLib.GetEmptyDatabase(); var testProfile = new QualityProfile { @@ -55,21 +55,20 @@ namespace NzbDrone.Core.Test }; - var profileId = (int)repo.Add(testProfile); + var profileId = Convert.ToInt32(database.Insert(testProfile)); var series = Builder.CreateNew().Build(); series.QualityProfileId = profileId; - repo.Add(testProfile); - repo.Add(series); - - var result = repo.All(); + database.Insert(testProfile); + database.Insert(series); + var result = database.Fetch(); result.Should().HaveCount(1); - Assert.AreEqual(result.ToList()[0].QualityProfile.Name, testProfile.Name); - - //Act + var profile = database.SingleOrDefault(result[0].QualityProfileId); + Assert.AreEqual(profileId, result[0].QualityProfileId); + Assert.AreEqual(testProfile.Name, profile.Name); } } } \ No newline at end of file diff --git a/NzbDrone.Core/Datastore/Migrations/Migration.cs b/NzbDrone.Core/Datastore/Migrations/Migration.cs index e49124513..a09611225 100644 --- a/NzbDrone.Core/Datastore/Migrations/Migration.cs +++ b/NzbDrone.Core/Datastore/Migrations/Migration.cs @@ -93,7 +93,7 @@ namespace NzbDrone.Core.Datastore.Migrations Database.AddTable("History", "SQLite", new[] { - new Column("HistoryId", DbType.Int64, ColumnProperty.NotNull), + new Column("HistoryId", DbType.Int64, ColumnProperty.PrimaryKey), new Column("EpisodeId", DbType.Int32, ColumnProperty.NotNull), new Column("SeriesId", DbType.Int32, ColumnProperty.NotNull), new Column("NzbTitle", DbType.String, ColumnProperty.NotNull), @@ -127,6 +127,14 @@ namespace NzbDrone.Core.Datastore.Migrations new Column("LastExecution", DbType.DateTime, ColumnProperty.NotNull), new Column("Success", DbType.Boolean, ColumnProperty.NotNull) }); + + Database.AddTable("QualityProfiles", "SQLite", new[] + { + new Column("QualityProfileId", DbType.Int32, ColumnProperty.PrimaryKey), + new Column("Name", DbType.String, ColumnProperty.NotNull), + new Column("Cutoff", DbType.Int32, ColumnProperty.NotNull), + new Column("SonicAllowed", DbType.String, ColumnProperty.NotNull), + }); } public override void Down() diff --git a/NzbDrone.Core/Providers/QualityProvider.cs b/NzbDrone.Core/Providers/QualityProvider.cs index ec636ae9b..df0c78b7f 100644 --- a/NzbDrone.Core/Providers/QualityProvider.cs +++ b/NzbDrone.Core/Providers/QualityProvider.cs @@ -4,6 +4,7 @@ using System.Linq; using Ninject; using NLog; using NzbDrone.Core.Repository.Quality; +using PetaPoco; using SubSonic.Repository; namespace NzbDrone.Core.Providers @@ -11,49 +12,49 @@ namespace NzbDrone.Core.Providers public class QualityProvider { private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - private readonly IRepository _repository; + private readonly IDatabase _database; public QualityProvider() { } [Inject] - public QualityProvider(IRepository repository) + public QualityProvider(IDatabase database) { - _repository = repository; + _database = database; } public virtual int Add(QualityProfile profile) { - return Convert.ToInt32(_repository.Add(profile)); + return Convert.ToInt32(_database.Insert(profile)); } public virtual void Update(QualityProfile profile) { - if (!_repository.Exists(q => q.QualityProfileId == profile.QualityProfileId)) + if (!_database.Exists("WHERE QualityProfileid = @0", profile.QualityProfileId)) { Logger.Error("Unable to update non-existing profile"); throw new InvalidOperationException("Unable to update non-existing profile"); } - _repository.Update(profile); + _database.Update(profile); } public virtual void Delete(int profileId) { - _repository.Delete(profileId); + _database.Delete(profileId); } public virtual List GetAllProfiles() { - var profiles = _repository.All().ToList(); + var profiles = _database.Fetch().ToList(); return profiles; } public virtual QualityProfile Find(int profileId) { - return _repository.Single(q => q.QualityProfileId == profileId); + return _database.SingleOrDefault(profileId); } public virtual void SetupDefaultProfiles() diff --git a/NzbDrone.Core/Repository/Quality/QualityProfile.cs b/NzbDrone.Core/Repository/Quality/QualityProfile.cs index ec50f0f90..802617e3a 100644 --- a/NzbDrone.Core/Repository/Quality/QualityProfile.cs +++ b/NzbDrone.Core/Repository/Quality/QualityProfile.cs @@ -2,10 +2,13 @@ using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; +using PetaPoco; using SubSonic.SqlGeneration.Schema; namespace NzbDrone.Core.Repository.Quality { + [TableName("QualityProfiles")] + [PrimaryKey("QualityProfileId", autoIncrement = true)] public class QualityProfile { [SubSonicPrimaryKey] @@ -16,10 +19,12 @@ namespace NzbDrone.Core.Repository.Quality [DisplayFormat(ConvertEmptyStringToNull = false)] public string Name { get; set; } + [Ignore] [SubSonicIgnore] [DisplayName("Allowed Qualities")] public List Allowed { get; set; } + [Ignore] [SubSonicIgnore] [DisplayName("Allowed Qualities String")] [DisplayFormat(ConvertEmptyStringToNull = false)] @@ -54,6 +59,7 @@ namespace NzbDrone.Core.Repository.Quality } } + [Ignore] [SubSonicToManyRelation] public virtual List Series { get; private set; } }