diff --git a/NzbDrone.App.Test/ConfigProviderTest.cs b/NzbDrone.App.Test/ConfigProviderTest.cs new file mode 100644 index 000000000..9bed9a381 --- /dev/null +++ b/NzbDrone.App.Test/ConfigProviderTest.cs @@ -0,0 +1,58 @@ +using FluentAssertions; +using Moq; +using NUnit.Framework; +using NzbDrone.Providers; + +namespace NzbDrone.App.Test +{ + [TestFixture] + public class ConfigProviderTest + { + + private ConfigProvider GetConfigProvider() + { + var envMoq = new Mock(); + envMoq.SetupGet(c => c.ApplicationPath).Returns(@"C:\NzbDrone\"); + + return new ConfigProvider(envMoq.Object); + } + + + [Test] + public void IISExpress_path_test() + { + GetConfigProvider().IISDirectory.Should().BeEquivalentTo(@"C:\NzbDrone\IISExpress"); + } + + [Test] + public void AppDataDirectory_path_test() + { + GetConfigProvider().AppDataDirectory.Should().BeEquivalentTo(@"C:\NzbDrone\NzbDrone.Web\App_Data"); + } + + + [Test] + public void Config_path_test() + { + GetConfigProvider().ConfigFile.Should().BeEquivalentTo(@"C:\NzbDrone\NzbDrone.Web\App_Data\Config.xml"); + } + + [Test] + public void IISConfig_path_test() + { + GetConfigProvider().IISConfigPath.Should().BeEquivalentTo(@"C:\NzbDrone\IISExpress\AppServer\applicationhost.config"); + } + + [Test] + public void IISExe_path_test() + { + GetConfigProvider().IISExePath.Should().BeEquivalentTo(@"C:\NzbDrone\IISExpress\IISExpress.exe"); + } + + [Test] + public void NlogConfig_path_test() + { + GetConfigProvider().NlogConfigPath.Should().BeEquivalentTo(@"C:\NzbDrone\NzbDrone.Web\log.config"); + } + } +} diff --git a/NzbDrone.App.Test/EnviromentControllerTest.cs b/NzbDrone.App.Test/EnviromentProviderTest.cs similarity index 94% rename from NzbDrone.App.Test/EnviromentControllerTest.cs rename to NzbDrone.App.Test/EnviromentProviderTest.cs index ac0d82077..f2615bf76 100644 --- a/NzbDrone.App.Test/EnviromentControllerTest.cs +++ b/NzbDrone.App.Test/EnviromentProviderTest.cs @@ -9,7 +9,7 @@ using NzbDrone.Providers; namespace NzbDrone.App.Test { [TestFixture] - public class EnviromentControllerTest + public class EnviromentProviderTest { [Test] diff --git a/NzbDrone.App.Test/ApplicationTest.cs b/NzbDrone.App.Test/MonitoringProviderTest.cs similarity index 100% rename from NzbDrone.App.Test/ApplicationTest.cs rename to NzbDrone.App.Test/MonitoringProviderTest.cs diff --git a/NzbDrone.App.Test/NzbDrone.App.Test.csproj b/NzbDrone.App.Test/NzbDrone.App.Test.csproj index 2c2c2cec6..93f582cfa 100644 --- a/NzbDrone.App.Test/NzbDrone.App.Test.csproj +++ b/NzbDrone.App.Test/NzbDrone.App.Test.csproj @@ -72,10 +72,11 @@ - + + - + diff --git a/NzbDrone.App.Test/ProcessProviderTests.cs b/NzbDrone.App.Test/ProcessProviderTests.cs index 9c9d166b5..35aea670c 100644 --- a/NzbDrone.App.Test/ProcessProviderTests.cs +++ b/NzbDrone.App.Test/ProcessProviderTests.cs @@ -43,6 +43,14 @@ namespace NzbDrone.App.Test dummyProcess.HasExited.Should().BeTrue(); } + [TestCase(0)] + [TestCase(-1)] + [TestCase(9999)] + public void GetProcessById_should_return_null_for_invalid_process(int processId) + { + _processProvider.GetProcessById(processId).Should().BeNull(); + } + public Process StartDummyProcess() { diff --git a/NzbDrone.Core/Properties/AssemblyInfo.cs b/NzbDrone.Core/Properties/AssemblyInfo.cs index 77251d559..62545d84a 100644 --- a/NzbDrone.Core/Properties/AssemblyInfo.cs +++ b/NzbDrone.Core/Properties/AssemblyInfo.cs @@ -50,5 +50,5 @@ using System.Runtime.InteropServices; // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.5.0.*")] +[assembly: AssemblyVersion("0.6.0.*")] [assembly: InternalsVisibleTo("NzbDrone.Core.Test")] \ No newline at end of file diff --git a/NzbDrone.Web/Properties/AssemblyInfo.cs b/NzbDrone.Web/Properties/AssemblyInfo.cs index 752fec6d1..24001ff67 100644 --- a/NzbDrone.Web/Properties/AssemblyInfo.cs +++ b/NzbDrone.Web/Properties/AssemblyInfo.cs @@ -34,4 +34,4 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("0.5.0.*")] \ No newline at end of file +[assembly: AssemblyVersion("0.6.0.*")] \ No newline at end of file diff --git a/NzbDrone/Application.cs b/NzbDrone/Application.cs index 2e34bae12..8c90cfa42 100644 --- a/NzbDrone/Application.cs +++ b/NzbDrone/Application.cs @@ -33,7 +33,7 @@ namespace NzbDrone _configProvider.ConfigureNlog(); _configProvider.CreateDefaultConfigFile(); - Logger.Info("Starting NZBDrone. Start-up Path:'{0}'", _configProvider.ApplicationRoot); + Logger.Info("Starting NZBDrone. Start-up Path:'{0}'", _enviromentProvider.ApplicationPath); Thread.CurrentThread.Name = "Host"; } diff --git a/NzbDrone/Program.cs b/NzbDrone/Program.cs index 5c391cd5a..acd830e37 100644 --- a/NzbDrone/Program.cs +++ b/NzbDrone/Program.cs @@ -1,4 +1,5 @@ using System; +using System.Reflection; using NLog; using Ninject; using NzbDrone.Providers; @@ -25,7 +26,7 @@ namespace NzbDrone Kernel.Bind().ToSelf().InSingletonScope(); Kernel.Bind().ToSelf().InSingletonScope(); - Console.WriteLine("Starting Console."); + Console.WriteLine("Starting NzbDrone Console. Version " + Assembly.GetExecutingAssembly().GetName().Version); Kernel.Get().Start(); Kernel.Get().Start(); } diff --git a/NzbDrone/Properties/AssemblyInfo.cs b/NzbDrone/Properties/AssemblyInfo.cs index c1e66ade6..0fb14c3d9 100644 --- a/NzbDrone/Properties/AssemblyInfo.cs +++ b/NzbDrone/Properties/AssemblyInfo.cs @@ -36,4 +36,4 @@ using System.Runtime.InteropServices; // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.5.0.*")] \ No newline at end of file +[assembly: AssemblyVersion("0.6.0.*")] \ No newline at end of file diff --git a/NzbDrone/Providers/ConfigProvider.cs b/NzbDrone/Providers/ConfigProvider.cs index 4b65078cf..b53590ef5 100644 --- a/NzbDrone/Providers/ConfigProvider.cs +++ b/NzbDrone/Providers/ConfigProvider.cs @@ -1,36 +1,32 @@ using System; using System.IO; using System.Linq; -using System.Reflection; using System.Xml.Linq; using System.Xml.XPath; using NLog; using NLog.Config; +using Ninject; using NzbDrone.Model; namespace NzbDrone.Providers { public class ConfigProvider { + private readonly EnviromentProvider _enviromentProvider; private static readonly Logger Logger = LogManager.GetLogger("Host.ConfigProvider"); - public virtual string ApplicationRoot + [Inject] + public ConfigProvider(EnviromentProvider enviromentProvider) { - get - { - var appDir = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory; + _enviromentProvider = enviromentProvider; + } - while (appDir.GetDirectories("iisexpress").Length == 0) - { - if (appDir.Parent == null) throw new ApplicationException("Can't fine IISExpress folder."); - appDir = appDir.Parent; - } + public ConfigProvider() + { - return appDir.FullName; - } } - public virtual int Port + public virtual int PortNumber { get { return GetValueInt("Port", 8989); } } @@ -40,29 +36,34 @@ namespace NzbDrone.Providers get { return GetValueBoolean("LaunchBrowser", true); } } - public virtual string AppDataDirectory + public virtual string IISDirectory { - get { return Path.Combine(ApplicationRoot, "NzbDrone.Web", "App_Data"); } + get { return Path.Combine(_enviromentProvider.ApplicationPath, "IISExpress"); } } - public virtual string ConfigFile + public virtual string IISExePath { - get { return Path.Combine(AppDataDirectory, "Config.xml"); } + get { return Path.Combine(IISDirectory, "iisexpress.exe"); } } - public virtual string IISFolder + public virtual string IISConfigPath { - get { return Path.Combine(ApplicationRoot, @"IISExpress\"); } + get { return Path.Combine(IISDirectory, "AppServer", "applicationhost.config"); } } - public virtual string IISExePath + public virtual string AppDataDirectory { - get { return IISFolder + @"iisexpress.exe"; } + get { return Path.Combine(_enviromentProvider.ApplicationPath, "NzbDrone.Web", "App_Data"); } } - public virtual string IISConfigPath + public virtual string ConfigFile + { + get { return Path.Combine(AppDataDirectory, "Config.xml"); } + } + + public virtual string NlogConfigPath { - get { return Path.Combine(IISFolder, "AppServer", "applicationhost.config"); } + get { return Path.Combine(_enviromentProvider.ApplicationPath, "NzbDrone.Web\\log.config"); } } public virtual AuthenticationType AuthenticationType @@ -73,14 +74,13 @@ namespace NzbDrone.Providers public virtual void ConfigureNlog() { - LogManager.Configuration = new XmlLoggingConfiguration( - Path.Combine(ApplicationRoot, "NzbDrone.Web\\log.config"), false); + LogManager.Configuration = new XmlLoggingConfiguration(NlogConfigPath, false); } public virtual void UpdateIISConfig(string configPath) { Logger.Info(@"Server configuration file: {0}", configPath); - Logger.Info(@"Configuring server to: [http://localhost:{0}]", Port); + Logger.Info(@"Configuring server to: [http://localhost:{0}]", PortNumber); var configXml = XDocument.Load(configPath); @@ -91,13 +91,13 @@ namespace NzbDrone.Providers bindings.Add( new XElement("binding", new XAttribute("protocol", "http"), - new XAttribute("bindingInformation", String.Format("*:{0}:localhost", Port)) + new XAttribute("bindingInformation", String.Format("*:{0}:localhost", PortNumber)) )); bindings.Add( new XElement("binding", new XAttribute("protocol", "http"), - new XAttribute("bindingInformation", String.Format("*:{0}:", Port)) + new XAttribute("bindingInformation", String.Format("*:{0}:", PortNumber)) )); //Update the authenticationTypes @@ -133,7 +133,7 @@ namespace NzbDrone.Providers } } - public virtual string GetValue(string key, object defaultValue, string parent = null) + private string GetValue(string key, object defaultValue, string parent = null) { var xDoc = XDocument.Load(ConfigFile); var config = xDoc.Descendants("Config").Single(); diff --git a/NzbDrone/Providers/EnviromentProvider.cs b/NzbDrone/Providers/EnviromentProvider.cs index 45c914342..2659806bc 100644 --- a/NzbDrone/Providers/EnviromentProvider.cs +++ b/NzbDrone/Providers/EnviromentProvider.cs @@ -1,4 +1,6 @@ using System; +using System.IO; +using System.Reflection; namespace NzbDrone.Providers { @@ -13,5 +15,21 @@ namespace NzbDrone.Providers { get { return Environment.UserInteractive; } } + + public virtual string ApplicationPath + { + get + { + var dir = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory; + + while (dir.GetDirectories("iisexpress").Length == 0) + { + if (dir.Parent == null) throw new ApplicationException("Can't fine IISExpress folder."); + dir = dir.Parent; + } + + return dir.FullName; + } + } } } \ No newline at end of file diff --git a/NzbDrone/Providers/IISProvider.cs b/NzbDrone/Providers/IISProvider.cs index 14b042c81..ce2478f7d 100644 --- a/NzbDrone/Providers/IISProvider.cs +++ b/NzbDrone/Providers/IISProvider.cs @@ -12,13 +12,15 @@ namespace NzbDrone.Providers private static readonly Logger Logger = LogManager.GetLogger("Host.IISProvider"); private readonly ConfigProvider _configProvider; private readonly ProcessProvider _processProvider; + private readonly EnviromentProvider _enviromentProvider; [Inject] - public IISProvider(ConfigProvider configProvider, ProcessProvider processProvider) + public IISProvider(ConfigProvider configProvider, ProcessProvider processProvider, EnviromentProvider enviromentProvider) { _configProvider = configProvider; _processProvider = processProvider; + _enviromentProvider = enviromentProvider; } public IISProvider() @@ -27,7 +29,7 @@ namespace NzbDrone.Providers public string AppUrl { - get { return string.Format("http://localhost:{0}/", _configProvider.Port); } + get { return string.Format("http://localhost:{0}/", _configProvider.PortNumber); } } public int IISProcessId { get; private set; } @@ -42,7 +44,7 @@ namespace NzbDrone.Providers startInfo.FileName = _configProvider.IISExePath; startInfo.Arguments = String.Format("/config:\"{0}\" /trace:i", _configProvider.IISConfigPath); - startInfo.WorkingDirectory = _configProvider.ApplicationRoot; + startInfo.WorkingDirectory = _enviromentProvider.ApplicationPath; startInfo.UseShellExecute = false; startInfo.RedirectStandardOutput = true; @@ -50,7 +52,7 @@ namespace NzbDrone.Providers startInfo.CreateNoWindow = true; //Set Variables for the config file. - startInfo.EnvironmentVariables.Add("NZBDRONE_PATH", _configProvider.ApplicationRoot); + startInfo.EnvironmentVariables.Add("NZBDRONE_PATH", _enviromentProvider.ApplicationPath); startInfo.EnvironmentVariables.Add("NZBDRONE_PID", Process.GetCurrentProcess().Id.ToString()); try diff --git a/NzbDrone/Providers/ProcessProvider.cs b/NzbDrone/Providers/ProcessProvider.cs index 9b7855673..fd12e3e68 100644 --- a/NzbDrone/Providers/ProcessProvider.cs +++ b/NzbDrone/Providers/ProcessProvider.cs @@ -73,7 +73,7 @@ namespace NzbDrone.Providers private static ProcessInfo ConvertToProcessInfo(Process process) { - if (process == null) return null; + if (process == null || process.Id <= 0) return null; return new ProcessInfo {