mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-11 12:02:35 +02:00
67 lines
1.9 KiB
C#
67 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using AutoMoq;
|
|
using Gallio.Framework;
|
|
using MbUnit.Framework;
|
|
using MbUnit.Framework.ContractVerifiers;
|
|
using Moq;
|
|
using NzbDrone.Core.Providers;
|
|
using NzbDrone.Core.Providers.Core;
|
|
using NzbDrone.Core.Repository;
|
|
using SubSonic.Repository;
|
|
|
|
namespace NzbDrone.Core.Test
|
|
{
|
|
[TestFixture]
|
|
// ReSharper disable InconsistentNaming
|
|
public class DbConfigControllerTest
|
|
{
|
|
[Test]
|
|
public void Overwrite_existing_value()
|
|
{
|
|
const string key = "MY_KEY";
|
|
const string value = "MY_VALUE";
|
|
|
|
//Arrange
|
|
var config = new Config { Key = key, Value = value };
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
mocker.GetMock<IRepository>()
|
|
.Setup(r => r.Single<Config>(key))
|
|
.Returns(config);
|
|
|
|
//Act
|
|
mocker.Resolve<ConfigProvider>().SetValue(key, value);
|
|
|
|
//Assert
|
|
mocker.GetMock<IRepository>().Verify(c => c.Update(config));
|
|
mocker.GetMock<IRepository>().Verify(c => c.Add(It.IsAny<Config>()), Times.Never());
|
|
}
|
|
|
|
[Test]
|
|
public void Add_new_value()
|
|
{
|
|
const string key = "MY_KEY";
|
|
const string value = "MY_VALUE";
|
|
|
|
//Arrange
|
|
var mocker = new AutoMoqer();
|
|
|
|
mocker.GetMock<IRepository>()
|
|
.Setup(r => r.Single<Config>(It.IsAny<string>()))
|
|
.Returns<Config>(null)
|
|
.Verifiable();
|
|
|
|
//Act
|
|
mocker.Resolve<ConfigProvider>().SetValue(key, value);
|
|
|
|
//Assert
|
|
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());
|
|
}
|
|
}
|
|
}
|