diff --git a/src/NzbDrone.Common.Test/ConfigFileProviderTest.cs b/src/NzbDrone.Common.Test/ConfigFileProviderTest.cs index e3a937f4a..76383d88e 100644 --- a/src/NzbDrone.Common.Test/ConfigFileProviderTest.cs +++ b/src/NzbDrone.Common.Test/ConfigFileProviderTest.cs @@ -1,6 +1,9 @@ -using System.IO; +using System.Collections.Generic; +using System.IO; using FluentAssertions; +using Moq; using NUnit.Framework; +using NzbDrone.Common.Disk; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.Extensions; using NzbDrone.Core.Authentication; @@ -13,6 +16,8 @@ namespace NzbDrone.Common.Test public class ConfigFileProviderTest : TestBase { + private string _configFileContents; + [SetUp] public void SetUp() { @@ -20,8 +25,24 @@ namespace NzbDrone.Common.Test var configFile = Mocker.Resolve().GetConfigPath(); - if (File.Exists(configFile)) - File.Delete(configFile); + _configFileContents = null; + + WithMockConfigFile(configFile); + } + + protected void WithMockConfigFile(string configFile) + { + Mocker.GetMock() + .Setup(v => v.FileExists(configFile)) + .Returns(p => _configFileContents != null); + + Mocker.GetMock() + .Setup(v => v.ReadAllText(configFile)) + .Returns(p => _configFileContents); + + Mocker.GetMock() + .Setup(v => v.WriteAllText(configFile, It.IsAny())) + .Callback((p, t) => _configFileContents = t); } [Test] @@ -142,8 +163,28 @@ namespace NzbDrone.Common.Test 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(); + dic["SslPort"] = sslPort; + Subject.SaveConfigDictionary(dic); Subject.Port.Should().Be(port); + Subject.SslPort.Should().Be(sslPort); } } diff --git a/src/NzbDrone.Core/Configuration/ConfigFileProvider.cs b/src/NzbDrone.Core/Configuration/ConfigFileProvider.cs index 6c10e7d0c..962eaa638 100644 --- a/src/NzbDrone.Core/Configuration/ConfigFileProvider.cs +++ b/src/NzbDrone.Core/Configuration/ConfigFileProvider.cs @@ -339,7 +339,7 @@ namespace NzbDrone.Core.Configuration { 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")); diff --git a/src/NzbDrone.Test.Common/TestBase.cs b/src/NzbDrone.Test.Common/TestBase.cs index dcaedfc98..20109e461 100644 --- a/src/NzbDrone.Test.Common/TestBase.cs +++ b/src/NzbDrone.Test.Common/TestBase.cs @@ -6,6 +6,7 @@ using Moq; using NLog; using NUnit.Framework; using NzbDrone.Common.Cache; +using NzbDrone.Common.Disk; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.Messaging; using NzbDrone.Core.Messaging.Events;