fixed some broken tests. broke some new ones.

This commit is contained in:
Keivan Beigi 2013-03-26 17:51:37 -07:00
parent 57120c9eeb
commit 0a3b0c9973
10 changed files with 76 additions and 46 deletions

View File

@ -63,7 +63,6 @@ namespace NzbDrone.Core.Test.Configuration
Db.Insert(new Config { Key = key, Value = originalValue }); Db.Insert(new Config { Key = key, Value = originalValue });
//Act
Subject.SetValue(key, newValue); Subject.SetValue(key, newValue);
var result = Subject.GetValue(key, ""); var result = Subject.GetValue(key, "");

View File

@ -112,5 +112,25 @@ namespace NzbDrone.Core.Test.Datastore
var loadedQuality = Db.Single<History.History>().Quality; var loadedQuality = Db.Single<History.History>().Quality;
loadedQuality.Should().Be(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<History.History>.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<History.History>();
returnedHistory[0].Quality.Quality.Should().Be(Quality.HDTV1080p);
}
} }
} }

View File

@ -18,16 +18,15 @@ using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.DecisionEngineTests namespace NzbDrone.Core.Test.DecisionEngineTests
{ {
[TestFixture] [TestFixture]
// ReSharper disable InconsistentNaming
public class UpgradeHistorySpecificationFixture : CoreTest public class UpgradeHistorySpecificationFixture : CoreTest
{ {
private UpgradeHistorySpecification _upgradeHistory; private UpgradeHistorySpecification _upgradeHistory;
private EpisodeParseResult parseResultMulti; private EpisodeParseResult _parseResultMulti;
private EpisodeParseResult parseResultSingle; private EpisodeParseResult _parseResultSingle;
private QualityModel firstQuality; private QualityModel _upgradableQuality;
private QualityModel secondQuality; private QualityModel _notupgradableQuality;
private Series fakeSeries; private Series _fakeSeries;
[SetUp] [SetUp]
public void Setup() public void Setup()
@ -35,51 +34,53 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
Mocker.Resolve<QualityUpgradableSpecification>(); Mocker.Resolve<QualityUpgradableSpecification>();
_upgradeHistory = Mocker.Resolve<UpgradeHistorySpecification>(); _upgradeHistory = Mocker.Resolve<UpgradeHistorySpecification>();
var singleEpisodeList = new List<Episode> { new Episode { SeasonNumber = 12, EpisodeNumber = 3 } }; var singleEpisodeList = new List<Episode> { new Episode { Id = 1, SeasonNumber = 12, EpisodeNumber = 3 } };
var doubleEpisodeList = new List<Episode> { var doubleEpisodeList = new List<Episode> {
new Episode { SeasonNumber = 12, EpisodeNumber = 3 }, new Episode {Id = 1, SeasonNumber = 12, EpisodeNumber = 3 },
new Episode { SeasonNumber = 12, EpisodeNumber = 4 }, new Episode {Id = 2, SeasonNumber = 12, EpisodeNumber = 4 },
new Episode { SeasonNumber = 12, EpisodeNumber = 5 } new Episode {Id = 3, SeasonNumber = 12, EpisodeNumber = 5 }
}; };
fakeSeries = Builder<Series>.CreateNew() _fakeSeries = Builder<Series>.CreateNew()
.With(c => c.QualityProfile = new QualityProfile { Cutoff = Quality.Bluray1080p }) .With(c => c.QualityProfile = new QualityProfile { Cutoff = Quality.Bluray1080p })
.Build(); .Build();
parseResultMulti = new EpisodeParseResult _parseResultMulti = new EpisodeParseResult
{ {
Series = fakeSeries, Series = _fakeSeries,
Quality = new QualityModel(Quality.DVD, true), Quality = new QualityModel(Quality.DVD, true),
EpisodeNumbers = new List<int> { 3, 4 }, EpisodeNumbers = new List<int> { 3, 4 },
SeasonNumber = 12, SeasonNumber = 12,
Episodes = doubleEpisodeList Episodes = doubleEpisodeList
}; };
parseResultSingle = new EpisodeParseResult _parseResultSingle = new EpisodeParseResult
{ {
Series = fakeSeries, Series = _fakeSeries,
Quality = new QualityModel(Quality.DVD, true), Quality = new QualityModel(Quality.DVD, true),
EpisodeNumbers = new List<int> { 3 }, EpisodeNumbers = new List<int> { 3 },
SeasonNumber = 12, SeasonNumber = 12,
Episodes = singleEpisodeList Episodes = singleEpisodeList
}; };
firstQuality = new QualityModel(Quality.Bluray1080p, true); _upgradableQuality = new QualityModel(Quality.SDTV, false);
secondQuality = new QualityModel(Quality.Bluray1080p, true); _notupgradableQuality = new QualityModel(Quality.HDTV1080p, true);
Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(1)).Returns(firstQuality);
Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(2)).Returns(secondQuality);
Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(1)).Returns(_notupgradableQuality);
Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(2)).Returns(_notupgradableQuality);
Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(3)).Returns<QualityModel>(null); Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(3)).Returns<QualityModel>(null);
} }
private void WithFirstReportUpgradable() private void WithFirstReportUpgradable()
{ {
firstQuality.Quality = Quality.SDTV; Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(1)).Returns(_upgradableQuality);
} }
private void WithSecondReportUpgradable() private void WithSecondReportUpgradable()
{ {
secondQuality.Quality = Quality.SDTV; Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(2)).Returns(_upgradableQuality);
} }
@ -87,7 +88,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
public void should_be_upgradable_if_only_episode_is_upgradable() public void should_be_upgradable_if_only_episode_is_upgradable()
{ {
WithFirstReportUpgradable(); WithFirstReportUpgradable();
_upgradeHistory.IsSatisfiedBy(parseResultSingle).Should().BeTrue(); _upgradeHistory.IsSatisfiedBy(_parseResultSingle).Should().BeTrue();
} }
[Test] [Test]
@ -95,39 +96,39 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
{ {
WithFirstReportUpgradable(); WithFirstReportUpgradable();
WithSecondReportUpgradable(); WithSecondReportUpgradable();
_upgradeHistory.IsSatisfiedBy(parseResultMulti).Should().BeTrue(); _upgradeHistory.IsSatisfiedBy(_parseResultMulti).Should().BeTrue();
} }
[Test] [Test]
public void should_not_be_upgradable_if_both_episodes_are_not_upgradable() public void should_not_be_upgradable_if_both_episodes_are_not_upgradable()
{ {
_upgradeHistory.IsSatisfiedBy(parseResultMulti).Should().BeFalse(); _upgradeHistory.IsSatisfiedBy(_parseResultMulti).Should().BeFalse();
} }
[Test] [Test]
public void should_be_not_upgradable_if_only_first_episodes_is_upgradable() public void should_be_not_upgradable_if_only_first_episodes_is_upgradable()
{ {
WithFirstReportUpgradable(); WithFirstReportUpgradable();
_upgradeHistory.IsSatisfiedBy(parseResultMulti).Should().BeFalse(); _upgradeHistory.IsSatisfiedBy(_parseResultMulti).Should().BeFalse();
} }
[Test] [Test]
public void should_be_not_upgradable_if_only_second_episodes_is_upgradable() public void should_be_not_upgradable_if_only_second_episodes_is_upgradable()
{ {
WithSecondReportUpgradable(); WithSecondReportUpgradable();
_upgradeHistory.IsSatisfiedBy(parseResultMulti).Should().BeFalse(); _upgradeHistory.IsSatisfiedBy(_parseResultMulti).Should().BeFalse();
} }
[Test] [Test]
public void should_not_be_upgradable_if_episode_is_of_same_quality_as_existing() public void should_not_be_upgradable_if_episode_is_of_same_quality_as_existing()
{ {
fakeSeries.QualityProfile = new QualityProfile { Cutoff = Quality.WEBDL1080p }; _fakeSeries.QualityProfile = new QualityProfile { Cutoff = Quality.WEBDL1080p };
parseResultSingle.Quality = new QualityModel(Quality.WEBDL1080p, false); _parseResultSingle.Quality = new QualityModel(Quality.WEBDL1080p, false);
firstQuality = new QualityModel(Quality.WEBDL1080p, false); _upgradableQuality = new QualityModel(Quality.WEBDL1080p, false);
Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(1)).Returns(firstQuality); Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(1)).Returns(_upgradableQuality);
_upgradeHistory.IsSatisfiedBy(parseResultSingle).Should().BeFalse(); _upgradeHistory.IsSatisfiedBy(_parseResultSingle).Should().BeFalse();
} }
} }
} }

View File

@ -123,7 +123,7 @@ namespace NzbDrone.Core.Test.Framework
{ {
void InsertMany<T>(IEnumerable<T> items) where T : ModelBase, new(); void InsertMany<T>(IEnumerable<T> items) where T : ModelBase, new();
void Insert<T>(T item) where T : ModelBase, new(); void Insert<T>(T item) where T : ModelBase, new();
IEnumerable<T> All<T>() where T : ModelBase, new(); List<T> All<T>() where T : ModelBase, new();
T Single<T>() where T : ModelBase, new(); T Single<T>() where T : ModelBase, new();
void Update<T>(T childModel) where T : ModelBase, new(); void Update<T>(T childModel) where T : ModelBase, new();
void Delete<T>(T childModel) where T : ModelBase, new(); void Delete<T>(T childModel) where T : ModelBase, new();
@ -148,9 +148,9 @@ namespace NzbDrone.Core.Test.Framework
new BasicRepository<T>(_dbConnection).Insert(item); new BasicRepository<T>(_dbConnection).Insert(item);
} }
public IEnumerable<T> All<T>() where T : ModelBase, new() public List<T> All<T>() where T : ModelBase, new()
{ {
return new BasicRepository<T>(_dbConnection).All(); return new BasicRepository<T>(_dbConnection).All().ToList();
} }
public T Single<T>() where T : ModelBase, new() public T Single<T>() where T : ModelBase, new()

View File

@ -1,9 +1,7 @@
using System; using System;
using System.Linq;
using FizzWare.NBuilder; using FizzWare.NBuilder;
using FluentAssertions; using FluentAssertions;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.History; using NzbDrone.Core.History;
using NzbDrone.Core.Qualities; using NzbDrone.Core.Qualities;
using NzbDrone.Core.Tv; using NzbDrone.Core.Tv;
@ -12,7 +10,7 @@ using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.HistoryTests namespace NzbDrone.Core.Test.HistoryTests
{ {
[TestFixture] [TestFixture]
public class HistoryServiceTest : DbTest<HistoryRepository, History.History> public class HistoryRepositoryFixture : DbTest<HistoryRepository, History.History>
{ {
[Test] [Test]
public void Trim_Items() public void Trim_Items()

View File

@ -242,7 +242,7 @@
<Compile Include="TvTests\QualityModelFixture.cs" /> <Compile Include="TvTests\QualityModelFixture.cs" />
<Compile Include="RootFolderTests\RootFolderServiceFixture.cs" /> <Compile Include="RootFolderTests\RootFolderServiceFixture.cs" />
<Compile Include="Indexers\IndexerServiceTest.cs" /> <Compile Include="Indexers\IndexerServiceTest.cs" />
<Compile Include="HistoryTests\HistoryServiceTest.cs" /> <Compile Include="HistoryTests\HistoryRepositoryFixture.cs" />
<Compile Include="MediaFileTests\MediaFileServiceTest.cs" /> <Compile Include="MediaFileTests\MediaFileServiceTest.cs" />
<Compile Include="Configuration\ConfigServiceFixture.cs" /> <Compile Include="Configuration\ConfigServiceFixture.cs" />
<Compile Include="TvTests\EpisodeProviderTests\EpisodeProviderTest.cs" /> <Compile Include="TvTests\EpisodeProviderTests\EpisodeProviderTest.cs" />
@ -301,6 +301,9 @@
<Content Include="Files\JsonError.txt"> <Content Include="Files\JsonError.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content> </Content>
<Content Include="SQLite.Interop.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="Files\RSS\nzbx_search.json"> <None Include="Files\RSS\nzbx_search.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None> </None>

Binary file not shown.

View File

@ -4,7 +4,14 @@ namespace NzbDrone.Core.Configuration
{ {
public class Config : ModelBase 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; } public string Value { get; set; }
} }
} }

View File

@ -571,7 +571,7 @@ namespace NzbDrone.Core.Configuration
{ {
if (!_cache.Any()) if (!_cache.Any())
{ {
_cache = All().ToDictionary(c => c.Key, c => c.Value); _cache = All().ToDictionary(c => c.Key.ToLower(), c => c.Value);
} }
} }
} }

View File

@ -150,6 +150,8 @@ namespace NzbDrone.Core.Datastore
throw new InvalidOperationException("Attempted to updated model without ID"); throw new InvalidOperationException("Attempted to updated model without ID");
} }
_dataMapper.Update<TModel>(model, m => m.Id == model.Id);
// _database.UpdateOnly(model, onlyFields, m => m.Id == model.Id); // _database.UpdateOnly(model, onlyFields, m => m.Id == model.Id);
} }
} }