mirror of
https://github.com/lidarr/Lidarr
synced 2025-03-03 10:06:06 +00:00
QualityProvider moved to PetaPoco.
This commit is contained in:
parent
9daf1ccfc0
commit
446a939f45
4 changed files with 36 additions and 22 deletions
|
@ -22,7 +22,7 @@ public class QualityProfileTest : TestBase
|
||||||
public void Test_Storage()
|
public void Test_Storage()
|
||||||
{
|
{
|
||||||
//Arrange
|
//Arrange
|
||||||
var repo = MockLib.GetEmptyRepository();
|
var database = MockLib.GetEmptyDatabase();
|
||||||
var testProfile = new QualityProfile
|
var testProfile = new QualityProfile
|
||||||
{
|
{
|
||||||
Name = Guid.NewGuid().ToString(),
|
Name = Guid.NewGuid().ToString(),
|
||||||
|
@ -31,8 +31,8 @@ public void Test_Storage()
|
||||||
};
|
};
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
var id = (int)repo.Add(testProfile);
|
var id = Convert.ToInt32(database.Insert(testProfile));
|
||||||
var fetch = repo.Single<QualityProfile>(c => c.QualityProfileId == id);
|
var fetch = database.SingleOrDefault<QualityProfile>(id);
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
Assert.AreEqual(id, fetch.QualityProfileId);
|
Assert.AreEqual(id, fetch.QualityProfileId);
|
||||||
|
@ -45,7 +45,7 @@ public void Test_Storage()
|
||||||
public void Test_Series_Quality()
|
public void Test_Series_Quality()
|
||||||
{
|
{
|
||||||
//Arrange
|
//Arrange
|
||||||
var repo = MockLib.GetEmptyRepository();
|
var database = MockLib.GetEmptyDatabase();
|
||||||
|
|
||||||
var testProfile = new QualityProfile
|
var testProfile = new QualityProfile
|
||||||
{
|
{
|
||||||
|
@ -55,21 +55,20 @@ public void Test_Series_Quality()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
var profileId = (int)repo.Add(testProfile);
|
var profileId = Convert.ToInt32(database.Insert(testProfile));
|
||||||
|
|
||||||
var series = Builder<Series>.CreateNew().Build();
|
var series = Builder<Series>.CreateNew().Build();
|
||||||
series.QualityProfileId = profileId;
|
series.QualityProfileId = profileId;
|
||||||
|
|
||||||
repo.Add(testProfile);
|
database.Insert(testProfile);
|
||||||
repo.Add(series);
|
database.Insert(series);
|
||||||
|
|
||||||
var result = repo.All<Series>();
|
|
||||||
|
|
||||||
|
var result = database.Fetch<Series>();
|
||||||
|
|
||||||
result.Should().HaveCount(1);
|
result.Should().HaveCount(1);
|
||||||
Assert.AreEqual(result.ToList()[0].QualityProfile.Name, testProfile.Name);
|
var profile = database.SingleOrDefault<QualityProfile>(result[0].QualityProfileId);
|
||||||
|
Assert.AreEqual(profileId, result[0].QualityProfileId);
|
||||||
//Act
|
Assert.AreEqual(testProfile.Name, profile.Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -93,7 +93,7 @@ public override void Up()
|
||||||
|
|
||||||
Database.AddTable("History", "SQLite", new[]
|
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("EpisodeId", DbType.Int32, ColumnProperty.NotNull),
|
||||||
new Column("SeriesId", DbType.Int32, ColumnProperty.NotNull),
|
new Column("SeriesId", DbType.Int32, ColumnProperty.NotNull),
|
||||||
new Column("NzbTitle", DbType.String, ColumnProperty.NotNull),
|
new Column("NzbTitle", DbType.String, ColumnProperty.NotNull),
|
||||||
|
@ -127,6 +127,14 @@ public override void Up()
|
||||||
new Column("LastExecution", DbType.DateTime, ColumnProperty.NotNull),
|
new Column("LastExecution", DbType.DateTime, ColumnProperty.NotNull),
|
||||||
new Column("Success", DbType.Boolean, 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()
|
public override void Down()
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
using Ninject;
|
using Ninject;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Core.Repository.Quality;
|
using NzbDrone.Core.Repository.Quality;
|
||||||
|
using PetaPoco;
|
||||||
using SubSonic.Repository;
|
using SubSonic.Repository;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Providers
|
namespace NzbDrone.Core.Providers
|
||||||
|
@ -11,49 +12,49 @@ namespace NzbDrone.Core.Providers
|
||||||
public class QualityProvider
|
public class QualityProvider
|
||||||
{
|
{
|
||||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||||
private readonly IRepository _repository;
|
private readonly IDatabase _database;
|
||||||
|
|
||||||
public QualityProvider()
|
public QualityProvider()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
[Inject]
|
[Inject]
|
||||||
public QualityProvider(IRepository repository)
|
public QualityProvider(IDatabase database)
|
||||||
{
|
{
|
||||||
_repository = repository;
|
_database = database;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual int Add(QualityProfile profile)
|
public virtual int Add(QualityProfile profile)
|
||||||
{
|
{
|
||||||
return Convert.ToInt32(_repository.Add(profile));
|
return Convert.ToInt32(_database.Insert(profile));
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Update(QualityProfile profile)
|
public virtual void Update(QualityProfile profile)
|
||||||
{
|
{
|
||||||
if (!_repository.Exists<QualityProfile>(q => q.QualityProfileId == profile.QualityProfileId))
|
if (!_database.Exists<QualityProfile>("WHERE QualityProfileid = @0", profile.QualityProfileId))
|
||||||
{
|
{
|
||||||
Logger.Error("Unable to update non-existing profile");
|
Logger.Error("Unable to update non-existing profile");
|
||||||
throw new InvalidOperationException("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)
|
public virtual void Delete(int profileId)
|
||||||
{
|
{
|
||||||
_repository.Delete<QualityProfile>(profileId);
|
_database.Delete<QualityProfile>(profileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual List<QualityProfile> GetAllProfiles()
|
public virtual List<QualityProfile> GetAllProfiles()
|
||||||
{
|
{
|
||||||
var profiles = _repository.All<QualityProfile>().ToList();
|
var profiles = _database.Fetch<QualityProfile>().ToList();
|
||||||
|
|
||||||
return profiles;
|
return profiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual QualityProfile Find(int profileId)
|
public virtual QualityProfile Find(int profileId)
|
||||||
{
|
{
|
||||||
return _repository.Single<QualityProfile>(q => q.QualityProfileId == profileId);
|
return _database.SingleOrDefault<QualityProfile>(profileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void SetupDefaultProfiles()
|
public virtual void SetupDefaultProfiles()
|
||||||
|
|
|
@ -2,10 +2,13 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using PetaPoco;
|
||||||
using SubSonic.SqlGeneration.Schema;
|
using SubSonic.SqlGeneration.Schema;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Repository.Quality
|
namespace NzbDrone.Core.Repository.Quality
|
||||||
{
|
{
|
||||||
|
[TableName("QualityProfiles")]
|
||||||
|
[PrimaryKey("QualityProfileId", autoIncrement = true)]
|
||||||
public class QualityProfile
|
public class QualityProfile
|
||||||
{
|
{
|
||||||
[SubSonicPrimaryKey]
|
[SubSonicPrimaryKey]
|
||||||
|
@ -16,10 +19,12 @@ public class QualityProfile
|
||||||
[DisplayFormat(ConvertEmptyStringToNull = false)]
|
[DisplayFormat(ConvertEmptyStringToNull = false)]
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
[Ignore]
|
||||||
[SubSonicIgnore]
|
[SubSonicIgnore]
|
||||||
[DisplayName("Allowed Qualities")]
|
[DisplayName("Allowed Qualities")]
|
||||||
public List<QualityTypes> Allowed { get; set; }
|
public List<QualityTypes> Allowed { get; set; }
|
||||||
|
|
||||||
|
[Ignore]
|
||||||
[SubSonicIgnore]
|
[SubSonicIgnore]
|
||||||
[DisplayName("Allowed Qualities String")]
|
[DisplayName("Allowed Qualities String")]
|
||||||
[DisplayFormat(ConvertEmptyStringToNull = false)]
|
[DisplayFormat(ConvertEmptyStringToNull = false)]
|
||||||
|
@ -54,6 +59,7 @@ private set
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Ignore]
|
||||||
[SubSonicToManyRelation]
|
[SubSonicToManyRelation]
|
||||||
public virtual List<Series> Series { get; private set; }
|
public virtual List<Series> Series { get; private set; }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue