Alot of refactoring.

This commit is contained in:
kay.one 2011-11-12 23:27:16 -08:00
commit 72d0fc50ed
89 changed files with 503 additions and 767 deletions

View file

@ -0,0 +1,173 @@
using System.IO;
using AutoMoq;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Common.Model;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.ProviderTests
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class ConfigFileProviderTest : TestBase
{
[SetUp]
public void SetUp()
{
WithTempAsAppPath();
//Reset config file
var configFile = Mocker.Resolve<EnviromentProvider>().GetConfigPath();
if (File.Exists(configFile))
File.Delete(configFile);
Mocker.Resolve<ConfigFileProvider>().CreateDefaultConfigFile();
}
[Test]
public void GetValue_Success()
{
const string key = "Port";
const string value = "8989";
//Act
var result = Mocker.Resolve<ConfigFileProvider>().GetValue(key, value);
//Assert
result.Should().Be(value);
}
[Test]
public void GetInt_Success()
{
const string key = "Port";
const int value = 8989;
//Act
var result = Mocker.Resolve<ConfigFileProvider>().GetValueInt(key, value);
//Assert
result.Should().Be(value);
}
[Test]
public void GetBool_Success()
{
const string key = "LaunchBrowser";
const bool value = true;
var mocker = new AutoMoqer();
//Act
var result = Mocker.Resolve<ConfigFileProvider>().GetValueBoolean(key, value);
//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;
//Act
var result = Mocker.Resolve<ConfigFileProvider>().Port;
//Assert
result.Should().Be(value);
}
[Test]
public void SetValue_bool()
{
const string key = "LaunchBrowser";
const bool value = false;
//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;
//Act
Mocker.Resolve<ConfigFileProvider>().SetValue(key, value);
//Assert
var result = Mocker.Resolve<ConfigFileProvider>().Port;
result.Should().Be(value);
}
[Test]
public void GetValue_New_Key()
{
const string key = "Hello";
const string value = "World";
//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";
//Act
var result = Mocker.Resolve<ConfigFileProvider>().GetValue(key, value, "Universe");
//Assert
result.Should().Be(value);
}
[Test]
public void GetAuthenticationType_No_Existing_Value()
{
//Act
var result = Mocker.Resolve<ConfigFileProvider>().AuthenticationType;
//Assert
result.Should().Be(AuthenticationType.Anonymous);
}
[Test]
public void GetAuthenticationType_Windows()
{
Mocker.Resolve<ConfigFileProvider>().SetValue("AuthenticationType", 1);
//Act
var result = Mocker.Resolve<ConfigFileProvider>().AuthenticationType;
//Assert
result.Should().Be(AuthenticationType.Windows);
}
}
}

View file

@ -61,6 +61,8 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ConfigFileProviderTest.cs" />
<Compile Include="PathExtentionFixture.cs" />
<Compile Include="DiskProviderTests.cs" />
<Compile Include="EnviromentProviderTest.cs" />
<Compile Include="Fixtures.cs" />

View file

@ -0,0 +1,52 @@
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common;
namespace NzbDrone.App.Test
{
[TestFixture]
public class PathExtentionFixture
{
private EnviromentProvider GetEnviromentProvider()
{
var envMoq = new Mock<EnviromentProvider>();
envMoq.SetupGet(c => c.ApplicationPath).Returns(@"C:\NzbDrone\");
return envMoq.Object;
}
[Test]
public void AppDataDirectory_path_test()
{
GetEnviromentProvider().GetAppDataPath().Should().BeEquivalentTo(@"C:\NzbDrone\NzbDrone.Web\App_Data\");
}
[Test]
public void Config_path_test()
{
GetEnviromentProvider().GetConfigPath().Should().BeEquivalentTo(@"C:\NzbDrone\Config.xml");
}
[Test]
public void IISConfig_path_test()
{
GetEnviromentProvider().GetIISConfigPath().Should().BeEquivalentTo(@"C:\NzbDrone\IISExpress\AppServer\applicationhost.config");
}
[Test]
public void IISExe_path_test()
{
GetEnviromentProvider().GetIISExe().Should().BeEquivalentTo(@"C:\NzbDrone\IISExpress\IISExpress.exe");
}
[Test]
public void NlogConfig_path_test()
{
GetEnviromentProvider().GetNlogConfigPath().Should().BeEquivalentTo(@"C:\NzbDrone\NzbDrone.Web\log.config");
}
}
}