2011-11-14 03:22:18 +03:00
|
|
|
using System.Linq;
|
|
|
|
using System.IO;
|
|
|
|
|
2011-10-01 06:12:18 +03:00
|
|
|
using FluentAssertions;
|
|
|
|
using NUnit.Framework;
|
2011-11-13 10:27:16 +03:00
|
|
|
using NzbDrone.Common.Model;
|
|
|
|
using NzbDrone.Test.Common;
|
2011-11-14 03:22:18 +03:00
|
|
|
using NzbDrone.Test.Common.AutoMoq;
|
2011-11-13 10:27:16 +03:00
|
|
|
|
2011-11-14 03:22:18 +03:00
|
|
|
namespace NzbDrone.Common.Test
|
2011-10-01 06:12:18 +03:00
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
// ReSharper disable InconsistentNaming
|
|
|
|
public class ConfigFileProviderTest : TestBase
|
|
|
|
{
|
2011-10-01 10:04:06 +03:00
|
|
|
[SetUp]
|
|
|
|
public void SetUp()
|
|
|
|
{
|
2011-11-13 10:27:16 +03:00
|
|
|
WithTempAsAppPath();
|
2011-11-03 08:04:14 +03:00
|
|
|
|
2011-10-01 10:04:06 +03:00
|
|
|
//Reset config file
|
2011-11-13 10:27:16 +03:00
|
|
|
var configFile = Mocker.Resolve<EnviromentProvider>().GetConfigPath();
|
2011-10-17 23:20:09 +03:00
|
|
|
|
|
|
|
if (File.Exists(configFile))
|
|
|
|
File.Delete(configFile);
|
2011-10-01 10:04:06 +03:00
|
|
|
}
|
|
|
|
|
2011-10-01 06:12:18 +03:00
|
|
|
[Test]
|
|
|
|
public void GetValue_Success()
|
|
|
|
{
|
|
|
|
const string key = "Port";
|
|
|
|
const string value = "8989";
|
|
|
|
|
|
|
|
//Act
|
2011-11-03 08:04:14 +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;
|
|
|
|
|
|
|
|
//Act
|
2011-11-03 08:04:14 +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-11-03 08:04:14 +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
|
2011-11-03 08:04:14 +03:00
|
|
|
var result = Mocker.Resolve<ConfigFileProvider>().LaunchBrowser;
|
2011-10-01 06:12:18 +03:00
|
|
|
|
|
|
|
//Assert
|
|
|
|
result.Should().Be(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetPort_Success()
|
|
|
|
{
|
|
|
|
const int value = 8989;
|
|
|
|
|
|
|
|
//Act
|
2011-11-03 08:04:14 +03:00
|
|
|
var result = Mocker.Resolve<ConfigFileProvider>().Port;
|
2011-10-01 06:12:18 +03:00
|
|
|
|
|
|
|
//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;
|
|
|
|
|
|
|
|
//Act
|
2011-11-03 08:04:14 +03:00
|
|
|
Mocker.Resolve<ConfigFileProvider>().SetValue(key, value);
|
2011-10-01 10:04:06 +03:00
|
|
|
|
|
|
|
//Assert
|
2011-11-03 08:04:14 +03:00
|
|
|
var result = Mocker.Resolve<ConfigFileProvider>().LaunchBrowser;
|
2011-10-01 10:04:06 +03:00
|
|
|
result.Should().Be(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void SetValue_int()
|
|
|
|
{
|
|
|
|
const string key = "Port";
|
|
|
|
const int value = 12345;
|
|
|
|
|
|
|
|
//Act
|
2011-11-03 08:04:14 +03:00
|
|
|
Mocker.Resolve<ConfigFileProvider>().SetValue(key, value);
|
2011-10-01 10:04:06 +03:00
|
|
|
|
|
|
|
//Assert
|
2011-11-03 08:04:14 +03:00
|
|
|
var result = Mocker.Resolve<ConfigFileProvider>().Port;
|
2011-10-01 10:04:06 +03:00
|
|
|
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";
|
|
|
|
|
|
|
|
//Act
|
2011-11-03 08:04:14 +03:00
|
|
|
var result = Mocker.Resolve<ConfigFileProvider>().GetValue(key, value);
|
2011-10-07 07:36:47 +03:00
|
|
|
|
|
|
|
//Assert
|
|
|
|
result.Should().Be(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetAuthenticationType_No_Existing_Value()
|
|
|
|
{
|
|
|
|
|
|
|
|
//Act
|
2011-11-03 08:04:14 +03:00
|
|
|
var result = Mocker.Resolve<ConfigFileProvider>().AuthenticationType;
|
2011-10-07 07:36:47 +03:00
|
|
|
|
|
|
|
//Assert
|
|
|
|
result.Should().Be(AuthenticationType.Anonymous);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetAuthenticationType_Windows()
|
|
|
|
{
|
2011-11-03 08:04:14 +03:00
|
|
|
|
|
|
|
Mocker.Resolve<ConfigFileProvider>().SetValue("AuthenticationType", 1);
|
2011-10-07 07:36:47 +03:00
|
|
|
|
|
|
|
//Act
|
2011-11-03 08:04:14 +03:00
|
|
|
var result = Mocker.Resolve<ConfigFileProvider>().AuthenticationType;
|
2011-10-07 07:36:47 +03:00
|
|
|
|
|
|
|
//Assert
|
|
|
|
result.Should().Be(AuthenticationType.Windows);
|
|
|
|
}
|
2011-11-14 03:22:18 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Guid_should_return_the_same_every_time()
|
|
|
|
{
|
|
|
|
//Act
|
|
|
|
var firstResponse = Mocker.Resolve<ConfigFileProvider>().Guid;
|
|
|
|
var secondResponse = Mocker.Resolve<ConfigFileProvider>().Guid;
|
|
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
secondResponse.Should().Be(firstResponse);
|
|
|
|
}
|
2011-10-01 06:12:18 +03:00
|
|
|
}
|
|
|
|
}
|