1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-11 05:22:44 +01:00
Radarr/NzbDrone.Core.Test/ConfigProviderTest.cs

64 lines
1.9 KiB
C#
Raw Normal View History

2011-04-10 04:44:01 +02:00
using AutoMoq;
using Moq;
2011-06-02 06:50:10 +02:00
using NUnit.Framework;
2011-04-04 05:50:12 +02:00
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Test.Framework;
using SubSonic.Repository;
namespace NzbDrone.Core.Test
{
[TestFixture]
2010-09-24 20:14:15 +02:00
// ReSharper disable InconsistentNaming
public class ConfigProviderTest : TestBase
{
[Test]
public void Overwrite_existing_value()
{
2010-09-24 20:14:15 +02:00
const string key = "MY_KEY";
const string value = "MY_VALUE";
2010-09-24 20:14:15 +02:00
//Arrange
2011-04-10 04:44:01 +02:00
var config = new Config {Key = key, Value = value};
var mocker = new AutoMoqer();
mocker.GetMock<IRepository>()
2011-04-10 04:44:01 +02:00
.Setup(r => r.Single<Config>(key))
.Returns(config);
//Act
mocker.Resolve<ConfigProvider>().SetValue(key, value);
//Assert
mocker.GetMock<IRepository>().Verify(c => c.Update(config));
mocker.GetMock<IRepository>().Verify(c => c.Add(It.IsAny<Config>()), Times.Never());
}
[Test]
public void Add_new_value()
{
2010-09-24 20:14:15 +02:00
const string key = "MY_KEY";
const string value = "MY_VALUE";
2010-09-24 20:14:15 +02:00
//Arrange
var mocker = new AutoMoqer();
mocker.GetMock<IRepository>()
2011-04-10 04:44:01 +02:00
.Setup(r => r.Single<Config>(It.IsAny<string>()))
.Returns<Config>(null)
.Verifiable();
//Act
mocker.Resolve<ConfigProvider>().SetValue(key, value);
//Assert
mocker.GetMock<IRepository>().Verify();
mocker.GetMock<IRepository>().Verify(r => r.Update(It.IsAny<Config>()), Times.Never());
2011-04-10 04:44:01 +02:00
mocker.GetMock<IRepository>().Verify(r => r.Add(It.Is<Config>(c => c.Key == key && c.Value == value)),
Times.Once());
2011-06-02 06:50:10 +02:00
Assert.Pass();
}
}
2011-04-10 04:44:01 +02:00
}