2010-09-24 09:16:43 +03:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Text;
|
|
|
|
using Gallio.Framework;
|
|
|
|
using MbUnit.Framework;
|
|
|
|
using MbUnit.Framework.ContractVerifiers;
|
|
|
|
using Moq;
|
2010-09-28 07:25:41 +03:00
|
|
|
using NzbDrone.Core.Providers;
|
2010-10-21 04:49:23 +03:00
|
|
|
using NzbDrone.Core.Repository;
|
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
|
2010-09-24 09:16:43 +03:00
|
|
|
public class DbConfigControllerTest
|
|
|
|
{
|
|
|
|
[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
|
2010-09-24 09:16:43 +03:00
|
|
|
var repo = new Mock<IRepository>();
|
2010-09-24 21:14:15 +03:00
|
|
|
var config = new Config { Key = key, Value = value };
|
2010-09-24 09:16:43 +03:00
|
|
|
repo.Setup(r => r.Single<Config>(key)).Returns(config);
|
2010-10-05 09:21:18 +03:00
|
|
|
var target = new ConfigProvider(repo.Object);
|
2010-09-24 09:16:43 +03: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 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
|
2010-09-24 09:16:43 +03:00
|
|
|
var repo = new Mock<IRepository>();
|
|
|
|
repo.Setup(r => r.Single<Config>(It.IsAny<string>())).Returns<Config>(null).Verifiable();
|
2010-10-05 09:21:18 +03:00
|
|
|
var target = new ConfigProvider(repo.Object);
|
2010-09-24 09:16:43 +03: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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|