2010-09-24 08:16:43 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
2011-04-07 05:34:48 +02:00
|
|
|
|
using AutoMoq;
|
2010-09-24 08:16:43 +02:00
|
|
|
|
using Gallio.Framework;
|
|
|
|
|
using MbUnit.Framework;
|
|
|
|
|
using MbUnit.Framework.ContractVerifiers;
|
|
|
|
|
using Moq;
|
2010-09-28 06:25:41 +02:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2011-04-04 05:50:12 +02:00
|
|
|
|
using NzbDrone.Core.Providers.Core;
|
2010-10-21 03:49:23 +02:00
|
|
|
|
using NzbDrone.Core.Repository;
|
2010-09-24 08:16:43 +02:00
|
|
|
|
using SubSonic.Repository;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2010-09-24 20:14:15 +02:00
|
|
|
|
// ReSharper disable InconsistentNaming
|
2010-09-24 08:16:43 +02:00
|
|
|
|
public class DbConfigControllerTest
|
|
|
|
|
{
|
|
|
|
|
[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 08:16:43 +02:00
|
|
|
|
|
2010-09-24 20:14:15 +02:00
|
|
|
|
//Arrange
|
|
|
|
|
var config = new Config { Key = key, Value = value };
|
2011-04-07 05:34:48 +02:00
|
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<IRepository>()
|
|
|
|
|
.Setup(r => r.Single<Config>(key))
|
|
|
|
|
.Returns(config);
|
2010-09-24 08:16:43 +02:00
|
|
|
|
|
|
|
|
|
//Act
|
2011-04-07 05:34:48 +02:00
|
|
|
|
mocker.Resolve<ConfigProvider>().SetValue(key, value);
|
2010-09-24 08:16:43 +02:00
|
|
|
|
|
|
|
|
|
//Assert
|
2011-04-07 05:34:48 +02:00
|
|
|
|
mocker.GetMock<IRepository>().Verify(c => c.Update(config));
|
|
|
|
|
mocker.GetMock<IRepository>().Verify(c => c.Add(It.IsAny<Config>()), Times.Never());
|
2010-09-24 08:16:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[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 08:16:43 +02:00
|
|
|
|
|
2010-09-24 20:14:15 +02:00
|
|
|
|
//Arrange
|
2011-04-07 05:34:48 +02:00
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<IRepository>()
|
|
|
|
|
.Setup(r => r.Single<Config>(It.IsAny<string>()))
|
|
|
|
|
.Returns<Config>(null)
|
|
|
|
|
.Verifiable();
|
2010-09-24 08:16:43 +02:00
|
|
|
|
|
|
|
|
|
//Act
|
2011-04-07 05:34:48 +02:00
|
|
|
|
mocker.Resolve<ConfigProvider>().SetValue(key, value);
|
2010-09-24 08:16:43 +02:00
|
|
|
|
|
|
|
|
|
//Assert
|
2011-04-07 05:34:48 +02:00
|
|
|
|
mocker.GetMock<IRepository>().Verify();
|
|
|
|
|
mocker.GetMock<IRepository>().Verify(r => r.Update(It.IsAny<Config>()), Times.Never());
|
|
|
|
|
mocker.GetMock<IRepository>().Verify(r => r.Add(It.Is<Config>(c => c.Key == key && c.Value == value)), Times.Once());
|
2010-09-24 08:16:43 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|