sonarr-repo-only/NzbDrone.Common.Test/ConfigFileProviderTest.cs

166 lines
3.9 KiB
C#
Raw Normal View History

using System.Linq;
using System.IO;
using FluentAssertions;
using NUnit.Framework;
2011-11-13 07:27:16 +00:00
using NzbDrone.Common.Model;
using NzbDrone.Test.Common;
using NzbDrone.Test.Common.AutoMoq;
2011-11-13 07:27:16 +00:00
namespace NzbDrone.Common.Test
{
[TestFixture]
2013-03-28 22:07:09 +00:00
public class ConfigFileProviderTest : TestBase
{
[SetUp]
public void SetUp()
{
2011-11-13 07:27:16 +00:00
WithTempAsAppPath();
//Reset config file
var configFile = Mocker.Resolve<EnvironmentProvider>().GetConfigPath();
if (File.Exists(configFile))
File.Delete(configFile);
}
[Test]
public void GetValue_Success()
{
const string key = "Port";
const string value = "8989";
2013-01-19 18:19:29 +00:00
var result = Mocker.Resolve<ConfigFileProvider>().GetValue(key, value);
2013-01-19 18:19:29 +00:00
result.Should().Be(value);
}
[Test]
public void GetInt_Success()
{
const string key = "Port";
const int value = 8989;
2013-01-19 18:19:29 +00:00
var result = Mocker.Resolve<ConfigFileProvider>().GetValueInt(key, value);
2013-01-19 18:19:29 +00:00
result.Should().Be(value);
}
[Test]
public void GetBool_Success()
{
const string key = "LaunchBrowser";
const bool value = true;
2013-01-19 18:19:29 +00:00
var result = Mocker.Resolve<ConfigFileProvider>().GetValueBoolean(key, value);
2013-01-19 18:19:29 +00:00
result.Should().BeTrue();
}
[Test]
public void GetLaunchBrowser_Success()
{
2013-01-19 18:19:29 +00:00
var result = Mocker.Resolve<ConfigFileProvider>().LaunchBrowser;
2013-01-19 18:19:29 +00:00
result.Should().Be(true);
}
[Test]
public void GetPort_Success()
{
const int value = 8989;
2013-01-19 18:19:29 +00:00
var result = Mocker.Resolve<ConfigFileProvider>().Port;
2013-01-19 18:19:29 +00:00
result.Should().Be(value);
}
[Test]
public void SetValue_bool()
{
const string key = "LaunchBrowser";
const bool value = false;
2013-01-19 18:19:29 +00:00
Mocker.Resolve<ConfigFileProvider>().SetValue(key, value);
2013-01-19 18:19:29 +00:00
var result = Mocker.Resolve<ConfigFileProvider>().LaunchBrowser;
result.Should().Be(value);
}
[Test]
public void SetValue_int()
{
const string key = "Port";
const int value = 12345;
2013-01-19 18:19:29 +00:00
Mocker.Resolve<ConfigFileProvider>().SetValue(key, value);
2013-01-19 18:19:29 +00:00
var result = Mocker.Resolve<ConfigFileProvider>().Port;
result.Should().Be(value);
}
[Test]
public void GetValue_New_Key()
{
const string key = "Hello";
const string value = "World";
2013-01-19 18:19:29 +00:00
var result = Mocker.Resolve<ConfigFileProvider>().GetValue(key, value);
2013-01-19 18:19:29 +00:00
result.Should().Be(value);
}
[Test]
public void GetAuthenticationType_No_Existing_Value()
{
2013-01-19 18:19:29 +00:00
var result = Mocker.Resolve<ConfigFileProvider>().AuthenticationType;
2013-01-19 18:19:29 +00:00
result.Should().Be(AuthenticationType.Anonymous);
}
[Test]
public void GetAuthenticationType_Windows()
{
Mocker.Resolve<ConfigFileProvider>().SetValue("AuthenticationType", 1);
2013-01-19 18:19:29 +00:00
var result = Mocker.Resolve<ConfigFileProvider>().AuthenticationType;
2013-01-19 18:19:29 +00:00
result.Should().Be(AuthenticationType.Windows);
}
[Test]
public void Guid_should_return_the_same_every_time()
{
2013-01-19 18:19:29 +00:00
var firstResponse = Mocker.Resolve<ConfigFileProvider>().Guid;
var secondResponse = Mocker.Resolve<ConfigFileProvider>().Guid;
2013-01-19 18:19:29 +00:00
secondResponse.Should().Be(firstResponse);
}
}
}