2011-10-01 10:04:06 +03:00
|
|
|
using System.IO;
|
|
|
|
using AutoMoq;
|
2011-10-01 06:12:18 +03:00
|
|
|
using FluentAssertions;
|
|
|
|
using NUnit.Framework;
|
2011-10-07 07:36:47 +03:00
|
|
|
using NzbDrone.Core.Model;
|
2011-10-01 06:12:18 +03:00
|
|
|
using NzbDrone.Core.Providers.Core;
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test
|
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
// ReSharper disable InconsistentNaming
|
|
|
|
public class ConfigFileProviderTest : TestBase
|
|
|
|
{
|
2011-10-01 10:04:06 +03:00
|
|
|
[SetUp]
|
|
|
|
public void SetUp()
|
|
|
|
{
|
|
|
|
//Reset config file
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
var configFile = mocker.Resolve<ConfigFileProvider>().ConfigFile;
|
2011-10-17 23:20:09 +03:00
|
|
|
|
|
|
|
if (File.Exists(configFile))
|
|
|
|
File.Delete(configFile);
|
2011-10-01 10:04:06 +03:00
|
|
|
|
|
|
|
mocker.Resolve<ConfigFileProvider>().CreateDefaultConfigFile();
|
|
|
|
}
|
|
|
|
|
2011-10-01 06:12:18 +03:00
|
|
|
[Test]
|
|
|
|
public void GetValue_Success()
|
|
|
|
{
|
|
|
|
const string key = "Port";
|
|
|
|
const string value = "8989";
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
|
|
//Act
|
2011-10-07 07:36:47 +03:00
|
|
|
var result = mocker.Resolve<ConfigFileProvider>().GetValue(key, value);
|
2011-10-01 06:12:18 +03:00
|
|
|
|
|
|
|
//Assert
|
|
|
|
result.Should().Be(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetInt_Success()
|
|
|
|
{
|
|
|
|
const string key = "Port";
|
|
|
|
const int value = 8989;
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
|
|
//Act
|
2011-10-07 07:36:47 +03:00
|
|
|
var result = mocker.Resolve<ConfigFileProvider>().GetValueInt(key, value);
|
2011-10-01 06:12:18 +03:00
|
|
|
|
|
|
|
//Assert
|
|
|
|
result.Should().Be(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetBool_Success()
|
|
|
|
{
|
|
|
|
const string key = "LaunchBrowser";
|
2011-10-07 07:36:47 +03:00
|
|
|
const bool value = true;
|
2011-10-01 06:12:18 +03:00
|
|
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
|
|
//Act
|
2011-10-07 07:36:47 +03:00
|
|
|
var result = mocker.Resolve<ConfigFileProvider>().GetValueBoolean(key, value);
|
2011-10-01 06:12:18 +03:00
|
|
|
|
|
|
|
//Assert
|
|
|
|
result.Should().BeTrue();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetLaunchBrowser_Success()
|
|
|
|
{
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
|
|
//Act
|
|
|
|
var result = mocker.Resolve<ConfigFileProvider>().LaunchBrowser;
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
result.Should().Be(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetPort_Success()
|
|
|
|
{
|
|
|
|
const int value = 8989;
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
|
|
//Act
|
|
|
|
var result = mocker.Resolve<ConfigFileProvider>().Port;
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
result.Should().Be(value);
|
|
|
|
}
|
2011-10-01 10:04:06 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void SetValue_bool()
|
|
|
|
{
|
|
|
|
const string key = "LaunchBrowser";
|
|
|
|
const bool value = false;
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
|
|
//Act
|
|
|
|
mocker.Resolve<ConfigFileProvider>().SetValue(key, value);
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
var result = mocker.Resolve<ConfigFileProvider>().LaunchBrowser;
|
|
|
|
result.Should().Be(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void SetValue_int()
|
|
|
|
{
|
|
|
|
const string key = "Port";
|
|
|
|
const int value = 12345;
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
|
|
//Act
|
|
|
|
mocker.Resolve<ConfigFileProvider>().SetValue(key, value);
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
var result = mocker.Resolve<ConfigFileProvider>().Port;
|
|
|
|
result.Should().Be(value);
|
|
|
|
}
|
2011-10-07 07:36:47 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetValue_New_Key()
|
|
|
|
{
|
|
|
|
const string key = "Hello";
|
|
|
|
const string value = "World";
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
|
|
//Act
|
|
|
|
var result = mocker.Resolve<ConfigFileProvider>().GetValue(key, value);
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
result.Should().Be(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetValue_New_Key_with_new_parent()
|
|
|
|
{
|
|
|
|
const string key = "Hello";
|
|
|
|
const string value = "World";
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
|
|
//Act
|
|
|
|
var result = mocker.Resolve<ConfigFileProvider>().GetValue(key, value, "Universe");
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
result.Should().Be(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetAuthenticationType_No_Existing_Value()
|
|
|
|
{
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
|
|
//Act
|
|
|
|
var result = mocker.Resolve<ConfigFileProvider>().AuthenticationType;
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
result.Should().Be(AuthenticationType.Anonymous);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetAuthenticationType_Windows()
|
|
|
|
{
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
mocker.Resolve<ConfigFileProvider>().SetValue("AuthenticationType", 1);
|
|
|
|
|
|
|
|
//Act
|
|
|
|
var result = mocker.Resolve<ConfigFileProvider>().AuthenticationType;
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
result.Should().Be(AuthenticationType.Windows);
|
|
|
|
}
|
2011-10-01 06:12:18 +03:00
|
|
|
}
|
|
|
|
}
|