1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

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 @@ 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, "");

View File

@ -112,5 +112,25 @@ public void embedded_document_as_json()
var loadedQuality = Db.Single<History.History>().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 @@
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<QualityUpgradableSpecification>();
_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> {
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<Series>.CreateNew()
_fakeSeries = Builder<Series>.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<int> { 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<int> { 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<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);
}
private void WithFirstReportUpgradable()
{
firstQuality.Quality = Quality.SDTV;
Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(1)).Returns(_upgradableQuality);
}
private void WithSecondReportUpgradable()
{
secondQuality.Quality = Quality.SDTV;
Mocker.GetMock<IHistoryService>().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<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 @@ public interface ITestDatabase
{
void InsertMany<T>(IEnumerable<T> items) 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();
void Update<T>(T childModel) where T : ModelBase, new();
void Delete<T>(T childModel) where T : ModelBase, new();
@ -148,9 +148,9 @@ public TestTestDatabase(IDatabase dbConnection)
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()

View File

@ -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<HistoryRepository, History.History>
public class HistoryRepositoryFixture : DbTest<HistoryRepository, History.History>
{
[Test]
public void Trim_Items()

View File

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

Binary file not shown.

View File

@ -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; }
}
}

View File

@ -34,7 +34,7 @@ public Dictionary<String, Object> AllWithDefaults()
var type = GetType();
var properties = type.GetProperties();
foreach(var propertyInfo in properties)
foreach (var propertyInfo in properties)
{
var value = propertyInfo.GetValue(this, null);
@ -552,7 +552,7 @@ public void SaveValues(Dictionary<string, object> 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);
}
}
}

View File

@ -150,6 +150,8 @@ public void UpdateFields<TKey>(TModel model, Expression<Func<TModel, TKey>> only
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);
}
}