2013-05-10 23:53:50 +00:00
|
|
|
|
using System.IO;
|
2011-10-01 03:12:18 +00:00
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using NUnit.Framework;
|
2013-06-28 00:04:52 +00:00
|
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
2013-05-23 05:12:01 +00:00
|
|
|
|
using NzbDrone.Core.Configuration;
|
2011-11-13 07:27:16 +00:00
|
|
|
|
using NzbDrone.Test.Common;
|
|
|
|
|
|
2011-11-14 00:22:18 +00:00
|
|
|
|
namespace NzbDrone.Common.Test
|
2011-10-01 03:12:18 +00:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2013-05-10 23:53:50 +00:00
|
|
|
|
|
|
|
|
|
public class ConfigFileProviderTest : TestBase<ConfigFileProvider>
|
2011-10-01 03:12:18 +00:00
|
|
|
|
{
|
2011-10-01 07:04:06 +00:00
|
|
|
|
[SetUp]
|
|
|
|
|
public void SetUp()
|
|
|
|
|
{
|
2011-11-13 07:27:16 +00:00
|
|
|
|
WithTempAsAppPath();
|
2011-11-03 05:04:14 +00:00
|
|
|
|
|
2013-07-05 04:43:28 +00:00
|
|
|
|
var configFile = Mocker.Resolve<IAppFolderInfo>().GetConfigPath();
|
2011-10-17 20:20:09 +00:00
|
|
|
|
|
|
|
|
|
if (File.Exists(configFile))
|
|
|
|
|
File.Delete(configFile);
|
2011-10-01 07:04:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-10-01 03:12:18 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void GetValue_Success()
|
|
|
|
|
{
|
|
|
|
|
const string key = "Port";
|
|
|
|
|
const string value = "8989";
|
|
|
|
|
|
|
|
|
|
|
2013-05-10 23:53:50 +00:00
|
|
|
|
var result = Subject.GetValue(key, value);
|
|
|
|
|
|
|
|
|
|
|
2011-10-01 03:12:18 +00:00
|
|
|
|
result.Should().Be(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void GetInt_Success()
|
|
|
|
|
{
|
|
|
|
|
const string key = "Port";
|
|
|
|
|
const int value = 8989;
|
|
|
|
|
|
|
|
|
|
|
2013-05-10 23:53:50 +00:00
|
|
|
|
var result = Subject.GetValueInt(key, value);
|
|
|
|
|
|
|
|
|
|
|
2011-10-01 03:12:18 +00:00
|
|
|
|
result.Should().Be(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void GetBool_Success()
|
|
|
|
|
{
|
|
|
|
|
const string key = "LaunchBrowser";
|
2011-10-07 04:36:47 +00:00
|
|
|
|
const bool value = true;
|
2011-10-01 03:12:18 +00:00
|
|
|
|
|
|
|
|
|
|
2013-05-10 23:53:50 +00:00
|
|
|
|
var result = Subject.GetValueBoolean(key, value);
|
|
|
|
|
|
|
|
|
|
|
2011-10-01 03:12:18 +00:00
|
|
|
|
result.Should().BeTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void GetLaunchBrowser_Success()
|
|
|
|
|
{
|
|
|
|
|
|
2013-05-10 23:53:50 +00:00
|
|
|
|
var result = Subject.LaunchBrowser;
|
|
|
|
|
|
|
|
|
|
|
2011-10-01 03:12:18 +00:00
|
|
|
|
result.Should().Be(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void GetPort_Success()
|
|
|
|
|
{
|
|
|
|
|
const int value = 8989;
|
|
|
|
|
|
|
|
|
|
|
2013-05-10 23:53:50 +00:00
|
|
|
|
var result = Subject.Port;
|
|
|
|
|
|
|
|
|
|
|
2011-10-01 03:12:18 +00:00
|
|
|
|
result.Should().Be(value);
|
|
|
|
|
}
|
2011-10-01 07:04:06 +00:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void SetValue_bool()
|
|
|
|
|
{
|
|
|
|
|
const string key = "LaunchBrowser";
|
|
|
|
|
const bool value = false;
|
|
|
|
|
|
|
|
|
|
|
2013-05-10 23:53:50 +00:00
|
|
|
|
Subject.SetValue(key, value);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var result = Subject.LaunchBrowser;
|
2011-10-01 07:04:06 +00:00
|
|
|
|
result.Should().Be(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void SetValue_int()
|
|
|
|
|
{
|
|
|
|
|
const string key = "Port";
|
|
|
|
|
const int value = 12345;
|
|
|
|
|
|
|
|
|
|
|
2013-05-10 23:53:50 +00:00
|
|
|
|
Subject.SetValue(key, value);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var result = Subject.Port;
|
2011-10-01 07:04:06 +00:00
|
|
|
|
result.Should().Be(value);
|
|
|
|
|
}
|
2011-10-07 04:36:47 +00:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void GetValue_New_Key()
|
|
|
|
|
{
|
|
|
|
|
const string key = "Hello";
|
|
|
|
|
const string value = "World";
|
|
|
|
|
|
|
|
|
|
|
2013-05-10 23:53:50 +00:00
|
|
|
|
var result = Subject.GetValue(key, value);
|
|
|
|
|
|
|
|
|
|
|
2011-10-07 04:36:47 +00:00
|
|
|
|
result.Should().Be(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void GetAuthenticationType_No_Existing_Value()
|
|
|
|
|
{
|
2013-07-14 07:00:50 +00:00
|
|
|
|
var result = Subject.AuthenticationEnabled;
|
2013-05-10 23:53:50 +00:00
|
|
|
|
|
2013-07-14 07:00:50 +00:00
|
|
|
|
result.Should().Be(false);
|
2011-10-07 04:36:47 +00:00
|
|
|
|
}
|
2011-11-14 00:22:18 +00:00
|
|
|
|
|
|
|
|
|
[Test]
|
2013-05-23 05:12:01 +00:00
|
|
|
|
public void SaveDictionary_should_save_proper_value()
|
2011-11-14 00:22:18 +00:00
|
|
|
|
{
|
2013-05-23 05:12:01 +00:00
|
|
|
|
int port = 20555;
|
2013-05-10 23:53:50 +00:00
|
|
|
|
|
2013-05-23 05:12:01 +00:00
|
|
|
|
var dic = Subject.GetConfigDictionary();
|
|
|
|
|
dic["Port"] = 20555;
|
2013-05-10 23:53:50 +00:00
|
|
|
|
|
2013-05-23 05:12:01 +00:00
|
|
|
|
Subject.SaveConfigDictionary(dic);
|
2011-11-14 00:22:18 +00:00
|
|
|
|
|
|
|
|
|
|
2013-05-23 05:12:01 +00:00
|
|
|
|
Subject.Port.Should().Be(port);
|
2011-11-14 00:22:18 +00:00
|
|
|
|
}
|
2013-05-23 05:12:01 +00:00
|
|
|
|
|
2011-10-01 03:12:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|