diff --git a/NzbDrone.Web.UI.Test/AutomationTestBase.cs b/NzbDrone.Web.UI.Test/AutomationTestBase.cs index 18134b26d..27ad765b2 100644 --- a/NzbDrone.Web.UI.Test/AutomationTestBase.cs +++ b/NzbDrone.Web.UI.Test/AutomationTestBase.cs @@ -11,12 +11,15 @@ using OpenQA.Selenium.Remote; namespace NzbDrone.Web.UI.Automation { + [Explicit] public abstract class AutomationTestBase { - static readonly EnviromentProvider enviromentProvider = new EnviromentProvider(); - private static readonly string testFolder; + private static readonly EnviromentProvider enviromentProvider = new EnviromentProvider(); - public string AppUrl + private readonly string _clonePackagePath; + private readonly string _masterPackagePath; + + protected string AppUrl { get { @@ -24,26 +27,28 @@ namespace NzbDrone.Web.UI.Automation } } - - public RemoteWebDriver Driver { get; private set; } - - static AutomationTestBase() + protected AutomationTestBase() { - CleanBinFolder(); - testFolder = CreatePackage(); - StartNzbDrone(); + var rawPackagePath = Path.Combine(enviromentProvider.ApplicationPath, "_rawPackage"); + _clonePackagePath = Path.Combine(rawPackagePath, "NzbDrone_Automation"); + _masterPackagePath = Path.Combine(rawPackagePath, "NzbDrone"); } + + protected RemoteWebDriver Driver { get; private set; } + + + [SetUp] public void AutomationSetup() { - + } [TearDown] public void AutomationTearDown() { - + if (!Directory.Exists(Directory.GetCurrentDirectory() + "\\Screenshots")) { @@ -62,18 +67,26 @@ namespace NzbDrone.Web.UI.Automation public void AutomationTestFixtureSetup() { StopNzbDrone(); - ResetUserData(); - StartNzbDrone(); + + + DeleteClone(); + ClonePackage(); + + //StartNzbDrone(); + InstallNzbDroneService(); + + new HttpProvider().DownloadString(AppUrl); + Driver = new FirefoxDriver(); } + + [TestFixtureTearDown] public void AutomationTestFixtureTearDown() { Driver.Close(); StopNzbDrone(); - - File.Copy(Path.Combine(testFolder, "nzbdrone.log"), Path.Combine(Directory.GetCurrentDirectory(), "nzbdrone.log"), true); } @@ -86,70 +99,90 @@ namespace NzbDrone.Web.UI.Automation ((ITakesScreenshot)Driver).GetScreenshot().SaveAsFile(fileName, ImageFormat.Png); } - private void ResetUserData() - { - var appDataPath = Path.Combine(testFolder, "NzbDrone.Web", "app_data"); - if (Directory.Exists(appDataPath)) - Directory.Delete(appDataPath, true); - } + private void StartNzbDrone() + { + StartProcess("nzbdrone.exe", false); + } - private static void CleanBinFolder() + private void StopNzbDrone() { - var folderName = "Debug"; - - if (EnviromentProvider.IsDebug) + foreach (var process in Process.GetProcessesByName("nzbdrone")) { - folderName = "Release"; + process.Kill(); + process.WaitForExit(); } - var dirs = Directory.GetDirectories(enviromentProvider.ApplicationPath, folderName, SearchOption.AllDirectories); - + foreach (var process in Process.GetProcessesByName("iisexpress")) + { + process.Kill(); + process.WaitForExit(); + } - foreach (var dir in dirs) + try { - Directory.Delete(dir, true); + StartProcess("ServiceUninstall.exe", true); + } + catch (Exception) + { + } } - static void StartNzbDrone() + private void InstallNzbDroneService() + { + StartProcess("ServiceInstall.exe", true); + } + + private void StartProcess(string fileName, bool waitForExit) { var startInfo = new ProcessStartInfo { - FileName = Path.Combine(testFolder, "nzbdrone.exe"), + FileName = Path.Combine(_clonePackagePath, fileName), RedirectStandardOutput = true, - UseShellExecute = false + RedirectStandardError = true, + UseShellExecute = false, + CreateNoWindow = true, }; var nzbDroneProcess = new Process - { - StartInfo = startInfo - }; - nzbDroneProcess.OutputDataReceived += - delegate(object o, DataReceivedEventArgs args) - { - Console.WriteLine(args.Data); - }; + { + StartInfo = startInfo + }; + + nzbDroneProcess.OutputDataReceived += (o, args) => Console.WriteLine(args.Data); + nzbDroneProcess.ErrorDataReceived += (o, args) => Console.WriteLine(args.Data); nzbDroneProcess.Start(); + + nzbDroneProcess.BeginErrorReadLine(); + nzbDroneProcess.BeginOutputReadLine(); + + if (waitForExit) + { + nzbDroneProcess.WaitForExit(); + } } + private void ClonePackage() + { + new DiskProvider().CopyDirectory(_masterPackagePath, _clonePackagePath); + } - public static void StopNzbDrone() + private void DeleteClone() { - foreach (var process in Process.GetProcessesByName("nzbdrone")) + if (Directory.Exists(_clonePackagePath)) { - process.Kill(); - process.WaitForExit(); + Directory.Delete(_clonePackagePath, true); } } - private static string CreatePackage() + private string CreatePackage() { Console.WriteLine("Creating NzbDrone Package"); @@ -183,5 +216,32 @@ namespace NzbDrone.Web.UI.Automation return testFolder; } + + private void ResetUserData() + { + var appDataPath = Path.Combine(_clonePackagePath, "NzbDrone.Web", "app_data"); + + if (Directory.Exists(appDataPath)) + Directory.Delete(appDataPath, true); + } + + + private static void CleanBinFolder() + { + var folderName = "Debug"; + + if (EnviromentProvider.IsDebug) + { + folderName = "Release"; + } + + var dirs = Directory.GetDirectories(enviromentProvider.ApplicationPath, folderName, SearchOption.AllDirectories); + + + foreach (var dir in dirs) + { + Directory.Delete(dir, true); + } + } } } diff --git a/NzbDrone.Web.UI.Test/BasicPageFixture.cs b/NzbDrone.Web.UI.Test/BasicPageFixture.cs index ea0909dd6..a6cb0a1eb 100644 --- a/NzbDrone.Web.UI.Test/BasicPageFixture.cs +++ b/NzbDrone.Web.UI.Test/BasicPageFixture.cs @@ -5,7 +5,6 @@ using NzbDrone.Web.UI.Automation.Fluent; namespace NzbDrone.Web.UI.Automation { [TestFixture] - [Explicit] public class BasicPageFixture : AutomationTestBase { diff --git a/NzbDrone.Web.UI.Test/NzbDrone.Web.UI.Automation.csproj b/NzbDrone.Web.UI.Test/NzbDrone.Web.UI.Automation.csproj index 54d44ed31..7270cccbd 100644 --- a/NzbDrone.Web.UI.Test/NzbDrone.Web.UI.Automation.csproj +++ b/NzbDrone.Web.UI.Test/NzbDrone.Web.UI.Automation.csproj @@ -35,10 +35,10 @@ ..\packages\FluentAssertions.1.7.0\Lib\net40\FluentAssertions.dll - + ..\packages\DotNetZip.1.9.1.8\lib\net20\Ionic.Zip.dll - + ..\packages\Newtonsoft.Json.4.0.6\lib\net40\Newtonsoft.Json.dll @@ -53,7 +53,6 @@ - False ..\packages\Selenium.WebDriver.2.19.0\lib\net40\WebDriver.dll @@ -85,7 +84,9 @@ - + + Always + diff --git a/NzbDrone.Web.UI.Test/app.config b/NzbDrone.Web.UI.Test/app.config index 575e97791..57e575d47 100644 --- a/NzbDrone.Web.UI.Test/app.config +++ b/NzbDrone.Web.UI.Test/app.config @@ -4,7 +4,7 @@ - + diff --git a/ServiceHelpers/ServiceInstall/Program.cs b/ServiceHelpers/ServiceInstall/Program.cs index 3736beeb3..816d1a231 100644 --- a/ServiceHelpers/ServiceInstall/Program.cs +++ b/ServiceHelpers/ServiceInstall/Program.cs @@ -8,8 +8,6 @@ namespace ServiceInstall static void Main() { ServiceHelper.Run(@"/i"); - Console.WriteLine("Press any key to continue"); - Console.ReadLine(); } } } diff --git a/ServiceHelpers/ServiceUninstall/Program.cs b/ServiceHelpers/ServiceUninstall/Program.cs index 4f2459bea..06f247102 100644 --- a/ServiceHelpers/ServiceUninstall/Program.cs +++ b/ServiceHelpers/ServiceUninstall/Program.cs @@ -1,5 +1,4 @@ using System.Linq; -using System; namespace ServiceUninstall { @@ -8,8 +7,6 @@ namespace ServiceUninstall static void Main() { ServiceHelper.Run(@"/u"); - Console.WriteLine("Press any key to continue"); - Console.ReadLine(); } } }