1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00
Radarr/NzbDrone.Core.Test/DbConfigControllerTest.cs

60 lines
1.7 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Text;
using Gallio.Framework;
using log4net;
using MbUnit.Framework;
using MbUnit.Framework.ContractVerifiers;
using Moq;
using NzbDrone.Core.Entities;
using NzbDrone.Core.Providers;
using SubSonic.Repository;
namespace NzbDrone.Core.Test
{
[TestFixture]
2010-09-24 20:14:15 +02:00
// ReSharper disable InconsistentNaming
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 20:14:15 +02:00
//Arrange
var repo = new Mock<IRepository>();
2010-09-24 20:14:15 +02:00
var config = new Config { Key = key, Value = value };
repo.Setup(r => r.Single<Config>(key)).Returns(config);
2010-10-05 08:21:18 +02:00
var target = new ConfigProvider(repo.Object);
//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 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 repo = new Mock<IRepository>();
repo.Setup(r => r.Single<Config>(It.IsAny<string>())).Returns<Config>(null).Verifiable();
2010-10-05 08:21:18 +02:00
var target = new ConfigProvider(repo.Object);
//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());
}
}
}