From af3ffa1c48a4e94aa81e6acb9ccc8e99b6551d84 Mon Sep 17 00:00:00 2001 From: kayone Date: Sun, 10 Nov 2013 23:26:13 -0800 Subject: [PATCH] more reliable apikey for integration tests. --- .../Notifications/Xbmc/HttpApiProvider.cs | 2 +- .../NzbDroneRunner.cs | 24 ++++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/NzbDrone.Core/Notifications/Xbmc/HttpApiProvider.cs b/src/NzbDrone.Core/Notifications/Xbmc/HttpApiProvider.cs index e0a2fa260..6178056f9 100644 --- a/src/NzbDrone.Core/Notifications/Xbmc/HttpApiProvider.cs +++ b/src/NzbDrone.Core/Notifications/Xbmc/HttpApiProvider.cs @@ -119,7 +119,7 @@ namespace NzbDrone.Core.Notifications.Xbmc return String.Empty; var xDoc = XDocument.Load(new StringReader(response.Replace("&", "&"))); - var xml = (from x in xDoc.Descendants("xml") select x).FirstOrDefault(); + var xml = xDoc.Descendants("xml").Select(x => x).FirstOrDefault(); if (xml == null) return null; diff --git a/src/NzbDrone.Integration.Test/NzbDroneRunner.cs b/src/NzbDrone.Integration.Test/NzbDroneRunner.cs index 44dc3f5be..318f6b01a 100644 --- a/src/NzbDrone.Integration.Test/NzbDroneRunner.cs +++ b/src/NzbDrone.Integration.Test/NzbDroneRunner.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Threading; using System.Xml.Linq; +using System.Xml.XPath; using NUnit.Framework; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.Processes; @@ -56,7 +57,7 @@ namespace NzbDrone.Integration.Test Assert.Fail("Process has exited"); } - ApiKey = GetApiKey(); + SetApiKey(); var request = new RestRequest("system/status"); request.AddHeader("Authorization", ApiKey); @@ -98,16 +99,23 @@ namespace NzbDrone.Integration.Test } } - private string GetApiKey() + private void SetApiKey() { var configFile = Path.Combine(AppData, "config.xml"); - if (!String.IsNullOrWhiteSpace(ApiKey)) return ApiKey; - if (!File.Exists(configFile)) return null; - - var xDoc = XDocument.Load(configFile); - var config = xDoc.Descendants(ConfigFileProvider.CONFIG_ELEMENT_NAME).Single(); - return config.Descendants("ApiKey").Single().Value; + while (ApiKey == null) + { + if (File.Exists(configFile)) + { + var apiKeyElement = XDocument.Load(configFile) + .XPathSelectElement("Config/ApiKey"); + if (apiKeyElement != null) + { + ApiKey = apiKeyElement.Value; + } + } + Thread.Sleep(1000); + } } } } \ No newline at end of file