1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-28 02:40:01 +00:00
Radarr/NzbDrone.Core.Test/ConfigProviderTest.cs

92 lines
2.5 KiB
C#
Raw Normal View History

2011-04-10 02:44:01 +00:00
using AutoMoq;
2011-06-17 02:27:10 +00:00
using FluentAssertions;
2011-06-02 04:50:10 +00:00
using NUnit.Framework;
2011-04-04 03:50:12 +00:00
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test
{
[TestFixture]
2010-09-24 18:14:15 +00:00
// ReSharper disable InconsistentNaming
public class ConfigProviderTest : TestBase
{
[Test]
2011-06-17 02:27:10 +00:00
public void Add_new_value_to_database()
{
2010-09-24 18:14:15 +00:00
const string key = "MY_KEY";
const string value = "MY_VALUE";
2011-06-17 02:27:10 +00:00
var mocker = new AutoMoqer();
var db = MockLib.GetEmptyDatabase();
mocker.SetConstant(db);
//Act
mocker.Resolve<ConfigProvider>().SetValue(key, value);
//Assert
mocker.Resolve<ConfigProvider>().GetValue(key, "").Should().Be(value);
}
[Test]
public void Get_value_from_database()
{
const string key = "MY_KEY";
const string value = "MY_VALUE";
var mocker = new AutoMoqer();
2011-06-17 02:27:10 +00:00
var db = MockLib.GetEmptyDatabase();
mocker.SetConstant(db);
2011-06-17 02:27:10 +00:00
db.Insert(new Config { Key = key, Value = value });
//Act
2011-06-17 02:27:10 +00:00
var result = mocker.Resolve<ConfigProvider>().GetValue(key, "");
//Assert
2011-06-17 02:27:10 +00:00
result.Should().Be(value);
}
2011-06-17 02:27:10 +00:00
[Test]
2011-06-17 02:27:10 +00:00
public void Get_value_should_return_default_when_no_value()
{
2010-09-24 18:14:15 +00:00
const string key = "MY_KEY";
const string value = "MY_VALUE";
var mocker = new AutoMoqer();
2011-06-17 02:27:10 +00:00
var db = MockLib.GetEmptyDatabase();
mocker.SetConstant(db);
//Act
2011-06-17 02:27:10 +00:00
var result = mocker.Resolve<ConfigProvider>().GetValue(key, value);
//Assert
2011-06-17 02:27:10 +00:00
result.Should().Be(value);
}
2011-06-02 04:50:10 +00:00
2011-06-17 02:27:10 +00:00
[Test]
public void New_value_should_update_old_value()
{
const string key = "MY_KEY";
const string originalValue = "OLD_VALUE";
const string newValue = "NEW_VALUE";
var mocker = new AutoMoqer();
var db = MockLib.GetEmptyDatabase();
mocker.SetConstant(db);
db.Insert(new Config { Key = key, Value = originalValue });
//Act
mocker.Resolve<ConfigProvider>().SetValue(key, newValue);
var result = mocker.Resolve<ConfigProvider>().GetValue(key, "");
//Assert
result.Should().Be(newValue);
db.Fetch<Config>().Should().HaveCount(1);
}
2011-06-17 02:27:10 +00:00
}
2011-04-10 02:44:01 +00:00
}