Added test to check Config behavior.

pull/4/head
Taloth Saldono 10 years ago
parent 3a938e18fa
commit 6e179839d9

@ -1,6 +1,9 @@
using System.IO; using System.Collections.Generic;
using System.IO;
using FluentAssertions; using FluentAssertions;
using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Common.Disk;
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Core.Authentication; using NzbDrone.Core.Authentication;
@ -13,6 +16,8 @@ namespace NzbDrone.Common.Test
public class ConfigFileProviderTest : TestBase<ConfigFileProvider> public class ConfigFileProviderTest : TestBase<ConfigFileProvider>
{ {
private string _configFileContents;
[SetUp] [SetUp]
public void SetUp() public void SetUp()
{ {
@ -20,8 +25,24 @@ namespace NzbDrone.Common.Test
var configFile = Mocker.Resolve<IAppFolderInfo>().GetConfigPath(); var configFile = Mocker.Resolve<IAppFolderInfo>().GetConfigPath();
if (File.Exists(configFile)) _configFileContents = null;
File.Delete(configFile);
WithMockConfigFile(configFile);
}
protected void WithMockConfigFile(string configFile)
{
Mocker.GetMock<IDiskProvider>()
.Setup(v => v.FileExists(configFile))
.Returns<string>(p => _configFileContents != null);
Mocker.GetMock<IDiskProvider>()
.Setup(v => v.ReadAllText(configFile))
.Returns<string>(p => _configFileContents);
Mocker.GetMock<IDiskProvider>()
.Setup(v => v.WriteAllText(configFile, It.IsAny<string>()))
.Callback<string, string>((p, t) => _configFileContents = t);
} }
[Test] [Test]
@ -142,8 +163,28 @@ namespace NzbDrone.Common.Test
Subject.SaveConfigDictionary(dic); Subject.SaveConfigDictionary(dic);
Subject.Port.Should().Be(port);
}
[Test]
public void SaveDictionary_should_only_save_specified_values()
{
int port = 20555;
int origSslPort = 20551;
int sslPort = 20552;
var dic = Subject.GetConfigDictionary();
dic["Port"] = port;
dic["SslPort"] = origSslPort;
Subject.SaveConfigDictionary(dic);
dic = new Dictionary<string, object>();
dic["SslPort"] = sslPort;
Subject.SaveConfigDictionary(dic);
Subject.Port.Should().Be(port); Subject.Port.Should().Be(port);
Subject.SslPort.Should().Be(sslPort);
} }
} }

@ -339,7 +339,7 @@ namespace NzbDrone.Core.Configuration
{ {
if (_diskProvider.FileExists(_configFile)) if (_diskProvider.FileExists(_configFile))
{ {
return XDocument.Load(_configFile); return XDocument.Parse(_diskProvider.ReadAllText(_configFile));
} }
var xDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes")); var xDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));

@ -6,6 +6,7 @@ using Moq;
using NLog; using NLog;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Common.Cache; using NzbDrone.Common.Cache;
using NzbDrone.Common.Disk;
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Messaging; using NzbDrone.Common.Messaging;
using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Messaging.Events;

Loading…
Cancel
Save