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