QualityProvider moved to PetaPoco.

pull/3113/head
Mark McDowall 14 years ago
parent 9daf1ccfc0
commit 446a939f45

@ -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<QualityProfile>(c => c.QualityProfileId == id);
var id = Convert.ToInt32(database.Insert(testProfile));
var fetch = database.SingleOrDefault<QualityProfile>(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<Series>.CreateNew().Build();
series.QualityProfileId = profileId;
repo.Add(testProfile);
repo.Add(series);
var result = repo.All<Series>();
database.Insert(testProfile);
database.Insert(series);
var result = database.Fetch<Series>();
result.Should().HaveCount(1);
Assert.AreEqual(result.ToList()[0].QualityProfile.Name, testProfile.Name);
//Act
var profile = database.SingleOrDefault<QualityProfile>(result[0].QualityProfileId);
Assert.AreEqual(profileId, result[0].QualityProfileId);
Assert.AreEqual(testProfile.Name, profile.Name);
}
}
}

@ -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()

@ -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<QualityProfile>(q => q.QualityProfileId == profile.QualityProfileId))
if (!_database.Exists<QualityProfile>("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<QualityProfile>(profileId);
_database.Delete<QualityProfile>(profileId);
}
public virtual List<QualityProfile> GetAllProfiles()
{
var profiles = _repository.All<QualityProfile>().ToList();
var profiles = _database.Fetch<QualityProfile>().ToList();
return profiles;
}
public virtual QualityProfile Find(int profileId)
{
return _repository.Single<QualityProfile>(q => q.QualityProfileId == profileId);
return _database.SingleOrDefault<QualityProfile>(profileId);
}
public virtual void SetupDefaultProfiles()

@ -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<QualityTypes> 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> Series { get; private set; }
}

Loading…
Cancel
Save