using AutoMoq; using FluentAssertions; using NUnit.Framework; using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Repository; using NzbDrone.Core.Test.Framework; namespace NzbDrone.Core.Test { [TestFixture] // ReSharper disable InconsistentNaming public class ConfigProviderTest : TestBase { [Test] public void Add_new_value_to_database() { const string key = "MY_KEY"; const string value = "MY_VALUE"; var mocker = new AutoMoqer(); var db = MockLib.GetEmptyDatabase(); mocker.SetConstant(db); //Act mocker.Resolve().SetValue(key, value); //Assert mocker.Resolve().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(); var db = MockLib.GetEmptyDatabase(); mocker.SetConstant(db); db.Insert(new Config { Key = key, Value = value }); //Act var result = mocker.Resolve().GetValue(key, ""); //Assert result.Should().Be(value); } [Test] public void Get_value_should_return_default_when_no_value() { const string key = "MY_KEY"; const string value = "MY_VALUE"; var mocker = new AutoMoqer(); var db = MockLib.GetEmptyDatabase(); mocker.SetConstant(db); //Act var result = mocker.Resolve().GetValue(key, value); //Assert result.Should().Be(value); } [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().SetValue(key, newValue); var result = mocker.Resolve().GetValue(key, ""); //Assert result.Should().Be(newValue); db.Fetch().Should().HaveCount(1); } } }