2010-09-24 06:16:43 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using Gallio.Framework;
|
|
|
|
|
using log4net;
|
|
|
|
|
using MbUnit.Framework;
|
|
|
|
|
using MbUnit.Framework.ContractVerifiers;
|
|
|
|
|
using Moq;
|
2010-10-08 03:35:04 +00:00
|
|
|
|
using NzbDrone.Core.Entities;
|
2010-09-28 04:25:41 +00:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2010-09-24 06:16:43 +00:00
|
|
|
|
using SubSonic.Repository;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2010-09-24 18:14:15 +00:00
|
|
|
|
// ReSharper disable InconsistentNaming
|
2010-09-24 06:16:43 +00:00
|
|
|
|
public class DbConfigControllerTest
|
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void Overwrite_existing_value()
|
|
|
|
|
{
|
2010-09-24 18:14:15 +00:00
|
|
|
|
const string key = "MY_KEY";
|
|
|
|
|
const string value = "MY_VALUE";
|
2010-09-24 06:16:43 +00:00
|
|
|
|
|
2010-09-24 18:14:15 +00:00
|
|
|
|
//Arrange
|
2010-09-24 06:16:43 +00:00
|
|
|
|
var repo = new Mock<IRepository>();
|
2010-09-24 18:14:15 +00:00
|
|
|
|
var config = new Config { Key = key, Value = value };
|
2010-09-24 06:16:43 +00:00
|
|
|
|
repo.Setup(r => r.Single<Config>(key)).Returns(config);
|
2010-10-05 06:21:18 +00:00
|
|
|
|
var target = new ConfigProvider(repo.Object);
|
2010-09-24 06:16:43 +00:00
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
target.SetValue(key, value);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
repo.Verify(c => c.Update(config));
|
|
|
|
|
repo.Verify(c => c.Add(It.IsAny<Config>()), Times.Never());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Add_new_value()
|
|
|
|
|
{
|
2010-09-24 18:14:15 +00:00
|
|
|
|
const string key = "MY_KEY";
|
|
|
|
|
const string value = "MY_VALUE";
|
2010-09-24 06:16:43 +00:00
|
|
|
|
|
2010-09-24 18:14:15 +00:00
|
|
|
|
//Arrange
|
2010-09-24 06:16:43 +00:00
|
|
|
|
var repo = new Mock<IRepository>();
|
|
|
|
|
repo.Setup(r => r.Single<Config>(It.IsAny<string>())).Returns<Config>(null).Verifiable();
|
2010-10-05 06:21:18 +00:00
|
|
|
|
var target = new ConfigProvider(repo.Object);
|
2010-09-24 06:16:43 +00:00
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
target.SetValue(key, value);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
repo.Verify();
|
|
|
|
|
repo.Verify(r => r.Update(It.IsAny<Config>()), Times.Never());
|
|
|
|
|
repo.Verify(r => r.Add(It.Is<Config>(c => c.Key == key && c.Value == value)), Times.Once());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|