diff --git a/NzbDrone.Core.Test/Configuration/ConfigServiceFixture.cs b/NzbDrone.Core.Test/Configuration/ConfigServiceFixture.cs index 48a95ada2..2772b33c1 100644 --- a/NzbDrone.Core.Test/Configuration/ConfigServiceFixture.cs +++ b/NzbDrone.Core.Test/Configuration/ConfigServiceFixture.cs @@ -63,7 +63,6 @@ public void New_value_should_update_old_value_new_value() Db.Insert(new Config { Key = key, Value = originalValue }); - //Act Subject.SetValue(key, newValue); var result = Subject.GetValue(key, ""); diff --git a/NzbDrone.Core.Test/Datastore/DatabaseRelationshipFixture.cs b/NzbDrone.Core.Test/Datastore/DatabaseRelationshipFixture.cs index 7ef89cef3..c78c5a4b5 100644 --- a/NzbDrone.Core.Test/Datastore/DatabaseRelationshipFixture.cs +++ b/NzbDrone.Core.Test/Datastore/DatabaseRelationshipFixture.cs @@ -112,5 +112,25 @@ public void embedded_document_as_json() var loadedQuality = Db.Single().Quality; loadedQuality.Should().Be(quality); } + + [Test] + public void embedded_list_of_document_with_json() + { + var quality = new QualityModel { Quality = Quality.Bluray720p, Proper = true }; + + var history = Builder.CreateListOfSize(2) + .All().With(c => c.Id = 0) + .Build().ToList(); + + history[0].Quality = new QualityModel(Quality.HDTV1080p, true); + history[1].Quality = new QualityModel(Quality.Bluray720p, true); + + + Db.InsertMany(history); + + var returnedHistory = Db.All(); + + returnedHistory[0].Quality.Quality.Should().Be(Quality.HDTV1080p); + } } } diff --git a/NzbDrone.Core.Test/DecisionEngineTests/UpgradeHistorySpecificationFixture.cs b/NzbDrone.Core.Test/DecisionEngineTests/UpgradeHistorySpecificationFixture.cs index 202fcbe44..9aa21c6ab 100644 --- a/NzbDrone.Core.Test/DecisionEngineTests/UpgradeHistorySpecificationFixture.cs +++ b/NzbDrone.Core.Test/DecisionEngineTests/UpgradeHistorySpecificationFixture.cs @@ -18,16 +18,15 @@ namespace NzbDrone.Core.Test.DecisionEngineTests { [TestFixture] - // ReSharper disable InconsistentNaming public class UpgradeHistorySpecificationFixture : CoreTest { private UpgradeHistorySpecification _upgradeHistory; - private EpisodeParseResult parseResultMulti; - private EpisodeParseResult parseResultSingle; - private QualityModel firstQuality; - private QualityModel secondQuality; - private Series fakeSeries; + private EpisodeParseResult _parseResultMulti; + private EpisodeParseResult _parseResultSingle; + private QualityModel _upgradableQuality; + private QualityModel _notupgradableQuality; + private Series _fakeSeries; [SetUp] public void Setup() @@ -35,51 +34,53 @@ public void Setup() Mocker.Resolve(); _upgradeHistory = Mocker.Resolve(); - var singleEpisodeList = new List { new Episode { SeasonNumber = 12, EpisodeNumber = 3 } }; + var singleEpisodeList = new List { new Episode { Id = 1, SeasonNumber = 12, EpisodeNumber = 3 } }; var doubleEpisodeList = new List { - new Episode { SeasonNumber = 12, EpisodeNumber = 3 }, - new Episode { SeasonNumber = 12, EpisodeNumber = 4 }, - new Episode { SeasonNumber = 12, EpisodeNumber = 5 } + new Episode {Id = 1, SeasonNumber = 12, EpisodeNumber = 3 }, + new Episode {Id = 2, SeasonNumber = 12, EpisodeNumber = 4 }, + new Episode {Id = 3, SeasonNumber = 12, EpisodeNumber = 5 } }; - fakeSeries = Builder.CreateNew() + _fakeSeries = Builder.CreateNew() .With(c => c.QualityProfile = new QualityProfile { Cutoff = Quality.Bluray1080p }) .Build(); - parseResultMulti = new EpisodeParseResult + _parseResultMulti = new EpisodeParseResult { - Series = fakeSeries, + Series = _fakeSeries, Quality = new QualityModel(Quality.DVD, true), EpisodeNumbers = new List { 3, 4 }, SeasonNumber = 12, Episodes = doubleEpisodeList }; - parseResultSingle = new EpisodeParseResult + _parseResultSingle = new EpisodeParseResult { - Series = fakeSeries, + Series = _fakeSeries, Quality = new QualityModel(Quality.DVD, true), EpisodeNumbers = new List { 3 }, SeasonNumber = 12, Episodes = singleEpisodeList }; - firstQuality = new QualityModel(Quality.Bluray1080p, true); - secondQuality = new QualityModel(Quality.Bluray1080p, true); + _upgradableQuality = new QualityModel(Quality.SDTV, false); + _notupgradableQuality = new QualityModel(Quality.HDTV1080p, true); - Mocker.GetMock().Setup(c => c.GetBestQualityInHistory(1)).Returns(firstQuality); - Mocker.GetMock().Setup(c => c.GetBestQualityInHistory(2)).Returns(secondQuality); + + + Mocker.GetMock().Setup(c => c.GetBestQualityInHistory(1)).Returns(_notupgradableQuality); + Mocker.GetMock().Setup(c => c.GetBestQualityInHistory(2)).Returns(_notupgradableQuality); Mocker.GetMock().Setup(c => c.GetBestQualityInHistory(3)).Returns(null); } private void WithFirstReportUpgradable() { - firstQuality.Quality = Quality.SDTV; + Mocker.GetMock().Setup(c => c.GetBestQualityInHistory(1)).Returns(_upgradableQuality); } private void WithSecondReportUpgradable() { - secondQuality.Quality = Quality.SDTV; + Mocker.GetMock().Setup(c => c.GetBestQualityInHistory(2)).Returns(_upgradableQuality); } @@ -87,7 +88,7 @@ private void WithSecondReportUpgradable() public void should_be_upgradable_if_only_episode_is_upgradable() { WithFirstReportUpgradable(); - _upgradeHistory.IsSatisfiedBy(parseResultSingle).Should().BeTrue(); + _upgradeHistory.IsSatisfiedBy(_parseResultSingle).Should().BeTrue(); } [Test] @@ -95,39 +96,39 @@ public void should_be_upgradable_if_both_episodes_are_upgradable() { WithFirstReportUpgradable(); WithSecondReportUpgradable(); - _upgradeHistory.IsSatisfiedBy(parseResultMulti).Should().BeTrue(); + _upgradeHistory.IsSatisfiedBy(_parseResultMulti).Should().BeTrue(); } [Test] public void should_not_be_upgradable_if_both_episodes_are_not_upgradable() { - _upgradeHistory.IsSatisfiedBy(parseResultMulti).Should().BeFalse(); + _upgradeHistory.IsSatisfiedBy(_parseResultMulti).Should().BeFalse(); } [Test] public void should_be_not_upgradable_if_only_first_episodes_is_upgradable() { WithFirstReportUpgradable(); - _upgradeHistory.IsSatisfiedBy(parseResultMulti).Should().BeFalse(); + _upgradeHistory.IsSatisfiedBy(_parseResultMulti).Should().BeFalse(); } [Test] public void should_be_not_upgradable_if_only_second_episodes_is_upgradable() { WithSecondReportUpgradable(); - _upgradeHistory.IsSatisfiedBy(parseResultMulti).Should().BeFalse(); + _upgradeHistory.IsSatisfiedBy(_parseResultMulti).Should().BeFalse(); } [Test] public void should_not_be_upgradable_if_episode_is_of_same_quality_as_existing() { - fakeSeries.QualityProfile = new QualityProfile { Cutoff = Quality.WEBDL1080p }; - parseResultSingle.Quality = new QualityModel(Quality.WEBDL1080p, false); - firstQuality = new QualityModel(Quality.WEBDL1080p, false); + _fakeSeries.QualityProfile = new QualityProfile { Cutoff = Quality.WEBDL1080p }; + _parseResultSingle.Quality = new QualityModel(Quality.WEBDL1080p, false); + _upgradableQuality = new QualityModel(Quality.WEBDL1080p, false); - Mocker.GetMock().Setup(c => c.GetBestQualityInHistory(1)).Returns(firstQuality); + Mocker.GetMock().Setup(c => c.GetBestQualityInHistory(1)).Returns(_upgradableQuality); - _upgradeHistory.IsSatisfiedBy(parseResultSingle).Should().BeFalse(); + _upgradeHistory.IsSatisfiedBy(_parseResultSingle).Should().BeFalse(); } } } \ No newline at end of file diff --git a/NzbDrone.Core.Test/Framework/DbTest.cs b/NzbDrone.Core.Test/Framework/DbTest.cs index 382aa01aa..f43d3070b 100644 --- a/NzbDrone.Core.Test/Framework/DbTest.cs +++ b/NzbDrone.Core.Test/Framework/DbTest.cs @@ -123,7 +123,7 @@ public interface ITestDatabase { void InsertMany(IEnumerable items) where T : ModelBase, new(); void Insert(T item) where T : ModelBase, new(); - IEnumerable All() where T : ModelBase, new(); + List All() where T : ModelBase, new(); T Single() where T : ModelBase, new(); void Update(T childModel) where T : ModelBase, new(); void Delete(T childModel) where T : ModelBase, new(); @@ -148,9 +148,9 @@ public TestTestDatabase(IDatabase dbConnection) new BasicRepository(_dbConnection).Insert(item); } - public IEnumerable All() where T : ModelBase, new() + public List All() where T : ModelBase, new() { - return new BasicRepository(_dbConnection).All(); + return new BasicRepository(_dbConnection).All().ToList(); } public T Single() where T : ModelBase, new() diff --git a/NzbDrone.Core.Test/HistoryTests/HistoryServiceTest.cs b/NzbDrone.Core.Test/HistoryTests/HistoryRepositoryFixture.cs similarity index 96% rename from NzbDrone.Core.Test/HistoryTests/HistoryServiceTest.cs rename to NzbDrone.Core.Test/HistoryTests/HistoryRepositoryFixture.cs index 559daaf00..b10f1cf4f 100644 --- a/NzbDrone.Core.Test/HistoryTests/HistoryServiceTest.cs +++ b/NzbDrone.Core.Test/HistoryTests/HistoryRepositoryFixture.cs @@ -1,9 +1,7 @@ using System; -using System.Linq; using FizzWare.NBuilder; using FluentAssertions; using NUnit.Framework; -using NzbDrone.Core.Datastore; using NzbDrone.Core.History; using NzbDrone.Core.Qualities; using NzbDrone.Core.Tv; @@ -12,7 +10,7 @@ namespace NzbDrone.Core.Test.HistoryTests { [TestFixture] - public class HistoryServiceTest : DbTest + public class HistoryRepositoryFixture : DbTest { [Test] public void Trim_Items() diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index e9ff43b01..1f1254a87 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -242,7 +242,7 @@ - + @@ -301,6 +301,9 @@ Always + + PreserveNewest + Always diff --git a/NzbDrone.Core.Test/SQLite.Interop.dll b/NzbDrone.Core.Test/SQLite.Interop.dll new file mode 100644 index 000000000..1838fba8d Binary files /dev/null and b/NzbDrone.Core.Test/SQLite.Interop.dll differ diff --git a/NzbDrone.Core/Configuration/Config.cs b/NzbDrone.Core/Configuration/Config.cs index 53ff3f921..7aa02522a 100644 --- a/NzbDrone.Core/Configuration/Config.cs +++ b/NzbDrone.Core/Configuration/Config.cs @@ -4,7 +4,14 @@ namespace NzbDrone.Core.Configuration { public class Config : ModelBase { - public string Key { get; set; } + private string _key; + + public string Key + { + get { return _key; } + set { _key = value.ToLowerInvariant(); } + } + public string Value { get; set; } } } \ No newline at end of file diff --git a/NzbDrone.Core/Configuration/ConfigService.cs b/NzbDrone.Core/Configuration/ConfigService.cs index 276689a16..cf9c33587 100644 --- a/NzbDrone.Core/Configuration/ConfigService.cs +++ b/NzbDrone.Core/Configuration/ConfigService.cs @@ -34,10 +34,10 @@ public Dictionary AllWithDefaults() var type = GetType(); var properties = type.GetProperties(); - foreach(var propertyInfo in properties) + foreach (var propertyInfo in properties) { var value = propertyInfo.GetValue(this, null); - + dict.Add(propertyInfo.Name, value); } @@ -268,7 +268,7 @@ public string TwitterAccessTokenSecret get { return GetValue("TwitterAccessTokenSecret", String.Empty); } set { SetValue("TwitterAccessTokenSecret", value); } } - + public string GrowlHost { get { return GetValue("GrowlHost", "localhost:23053"); } @@ -280,7 +280,7 @@ public string GrowlPassword get { return GetValue("GrowlPassword", String.Empty); } set { SetValue("GrowlPassword", value); } } - + public string ProwlApiKeys { get { return GetValue("ProwlApiKeys", String.Empty); } @@ -552,7 +552,7 @@ public void SaveValues(Dictionary configValues) { var allWithDefaults = AllWithDefaults(); - foreach(var configValue in configValues) + foreach (var configValue in configValues) { object currentValue; allWithDefaults.TryGetValue(configValue.Key, out currentValue); @@ -571,7 +571,7 @@ private void EnsureCache() { if (!_cache.Any()) { - _cache = All().ToDictionary(c => c.Key, c => c.Value); + _cache = All().ToDictionary(c => c.Key.ToLower(), c => c.Value); } } } diff --git a/NzbDrone.Core/Datastore/BasicRepository.cs b/NzbDrone.Core/Datastore/BasicRepository.cs index 7a8560d73..e80d6843c 100644 --- a/NzbDrone.Core/Datastore/BasicRepository.cs +++ b/NzbDrone.Core/Datastore/BasicRepository.cs @@ -150,6 +150,8 @@ public void UpdateFields(TModel model, Expression> only throw new InvalidOperationException("Attempted to updated model without ID"); } + _dataMapper.Update(model, m => m.Id == model.Id); + // _database.UpdateOnly(model, onlyFields, m => m.Id == model.Id); } }