mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-09 12:32:31 +01:00
2nd shot at automation using service instead of console.
This commit is contained in:
parent
59516c240f
commit
61d6a81446
@ -11,12 +11,15 @@
|
|||||||
|
|
||||||
namespace NzbDrone.Web.UI.Automation
|
namespace NzbDrone.Web.UI.Automation
|
||||||
{
|
{
|
||||||
|
[Explicit]
|
||||||
public abstract class AutomationTestBase
|
public abstract class AutomationTestBase
|
||||||
{
|
{
|
||||||
static readonly EnviromentProvider enviromentProvider = new EnviromentProvider();
|
private static readonly EnviromentProvider enviromentProvider = new EnviromentProvider();
|
||||||
private static readonly string testFolder;
|
|
||||||
|
|
||||||
public string AppUrl
|
private readonly string _clonePackagePath;
|
||||||
|
private readonly string _masterPackagePath;
|
||||||
|
|
||||||
|
protected string AppUrl
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
@ -24,16 +27,18 @@ public string AppUrl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected AutomationTestBase()
|
||||||
public RemoteWebDriver Driver { get; private set; }
|
|
||||||
|
|
||||||
static AutomationTestBase()
|
|
||||||
{
|
{
|
||||||
CleanBinFolder();
|
var rawPackagePath = Path.Combine(enviromentProvider.ApplicationPath, "_rawPackage");
|
||||||
testFolder = CreatePackage();
|
_clonePackagePath = Path.Combine(rawPackagePath, "NzbDrone_Automation");
|
||||||
StartNzbDrone();
|
_masterPackagePath = Path.Combine(rawPackagePath, "NzbDrone");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected RemoteWebDriver Driver { get; private set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void AutomationSetup()
|
public void AutomationSetup()
|
||||||
{
|
{
|
||||||
@ -62,18 +67,26 @@ public void AutomationTearDown()
|
|||||||
public void AutomationTestFixtureSetup()
|
public void AutomationTestFixtureSetup()
|
||||||
{
|
{
|
||||||
StopNzbDrone();
|
StopNzbDrone();
|
||||||
ResetUserData();
|
|
||||||
StartNzbDrone();
|
|
||||||
|
DeleteClone();
|
||||||
|
ClonePackage();
|
||||||
|
|
||||||
|
//StartNzbDrone();
|
||||||
|
InstallNzbDroneService();
|
||||||
|
|
||||||
|
new HttpProvider().DownloadString(AppUrl);
|
||||||
|
|
||||||
Driver = new FirefoxDriver();
|
Driver = new FirefoxDriver();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[TestFixtureTearDown]
|
[TestFixtureTearDown]
|
||||||
public void AutomationTestFixtureTearDown()
|
public void AutomationTestFixtureTearDown()
|
||||||
{
|
{
|
||||||
Driver.Close();
|
Driver.Close();
|
||||||
StopNzbDrone();
|
StopNzbDrone();
|
||||||
|
|
||||||
File.Copy(Path.Combine(testFolder, "nzbdrone.log"), Path.Combine(Directory.GetCurrentDirectory(), "nzbdrone.log"), true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -86,70 +99,90 @@ protected void CaptureScreen()
|
|||||||
((ITakesScreenshot)Driver).GetScreenshot().SaveAsFile(fileName, ImageFormat.Png);
|
((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 void StopNzbDrone()
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static void StartNzbDrone()
|
|
||||||
{
|
|
||||||
|
|
||||||
var startInfo = new ProcessStartInfo
|
|
||||||
{
|
|
||||||
FileName = Path.Combine(testFolder, "nzbdrone.exe"),
|
|
||||||
RedirectStandardOutput = true,
|
|
||||||
UseShellExecute = false
|
|
||||||
};
|
|
||||||
|
|
||||||
var nzbDroneProcess = new Process
|
|
||||||
{
|
|
||||||
StartInfo = startInfo
|
|
||||||
};
|
|
||||||
nzbDroneProcess.OutputDataReceived +=
|
|
||||||
delegate(object o, DataReceivedEventArgs args)
|
|
||||||
{
|
|
||||||
Console.WriteLine(args.Data);
|
|
||||||
};
|
|
||||||
|
|
||||||
nzbDroneProcess.Start();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void StopNzbDrone()
|
|
||||||
{
|
{
|
||||||
foreach (var process in Process.GetProcessesByName("nzbdrone"))
|
foreach (var process in Process.GetProcessesByName("nzbdrone"))
|
||||||
{
|
{
|
||||||
process.Kill();
|
process.Kill();
|
||||||
process.WaitForExit();
|
process.WaitForExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (var process in Process.GetProcessesByName("iisexpress"))
|
||||||
|
{
|
||||||
|
process.Kill();
|
||||||
|
process.WaitForExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string CreatePackage()
|
try
|
||||||
|
{
|
||||||
|
StartProcess("ServiceUninstall.exe", true);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InstallNzbDroneService()
|
||||||
|
{
|
||||||
|
StartProcess("ServiceInstall.exe", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StartProcess(string fileName, bool waitForExit)
|
||||||
|
{
|
||||||
|
|
||||||
|
var startInfo = new ProcessStartInfo
|
||||||
|
{
|
||||||
|
FileName = Path.Combine(_clonePackagePath, fileName),
|
||||||
|
RedirectStandardOutput = true,
|
||||||
|
RedirectStandardError = true,
|
||||||
|
UseShellExecute = false,
|
||||||
|
CreateNoWindow = true,
|
||||||
|
};
|
||||||
|
|
||||||
|
var nzbDroneProcess = new Process
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DeleteClone()
|
||||||
|
{
|
||||||
|
if (Directory.Exists(_clonePackagePath))
|
||||||
|
{
|
||||||
|
Directory.Delete(_clonePackagePath, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string CreatePackage()
|
||||||
{
|
{
|
||||||
Console.WriteLine("Creating NzbDrone Package");
|
Console.WriteLine("Creating NzbDrone Package");
|
||||||
|
|
||||||
@ -183,5 +216,32 @@ private static string CreatePackage()
|
|||||||
|
|
||||||
return testFolder;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
namespace NzbDrone.Web.UI.Automation
|
namespace NzbDrone.Web.UI.Automation
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
[Explicit]
|
|
||||||
public class BasicPageFixture : AutomationTestBase
|
public class BasicPageFixture : AutomationTestBase
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -35,10 +35,10 @@
|
|||||||
<Reference Include="FluentAssertions">
|
<Reference Include="FluentAssertions">
|
||||||
<HintPath>..\packages\FluentAssertions.1.7.0\Lib\net40\FluentAssertions.dll</HintPath>
|
<HintPath>..\packages\FluentAssertions.1.7.0\Lib\net40\FluentAssertions.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Ionic.Zip">
|
<Reference Include="Ionic.Zip, Version=1.9.1.8, Culture=neutral, PublicKeyToken=edbe51ad942a3f5c, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\DotNetZip.1.9.1.8\lib\net20\Ionic.Zip.dll</HintPath>
|
<HintPath>..\packages\DotNetZip.1.9.1.8\lib\net20\Ionic.Zip.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Newtonsoft.Json">
|
<Reference Include="Newtonsoft.Json, Version=4.0.6.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\Newtonsoft.Json.4.0.6\lib\net40\Newtonsoft.Json.dll</HintPath>
|
<HintPath>..\packages\Newtonsoft.Json.4.0.6\lib\net40\Newtonsoft.Json.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="nunit.framework">
|
<Reference Include="nunit.framework">
|
||||||
@ -53,7 +53,6 @@
|
|||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
<Reference Include="WebDriver, Version=2.19.0.0, Culture=neutral, PublicKeyToken=1c2bd1631853048f, processorArchitecture=MSIL">
|
<Reference Include="WebDriver, Version=2.19.0.0, Culture=neutral, PublicKeyToken=1c2bd1631853048f, processorArchitecture=MSIL">
|
||||||
<SpecificVersion>False</SpecificVersion>
|
|
||||||
<HintPath>..\packages\Selenium.WebDriver.2.19.0\lib\net40\WebDriver.dll</HintPath>
|
<HintPath>..\packages\Selenium.WebDriver.2.19.0\lib\net40\WebDriver.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@ -85,7 +84,9 @@
|
|||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="app.config" />
|
<None Include="app.config">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||||
<dependentAssembly>
|
<dependentAssembly>
|
||||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30AD4FE6B2A6AEED" culture="neutral"/>
|
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30AD4FE6B2A6AEED" culture="neutral"/>
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.7.0" newVersion="4.0.7.0"/>
|
<bindingRedirect oldVersion="0.0.0.0-4.0.8.0" newVersion="4.0.6.0"/>
|
||||||
</dependentAssembly>
|
</dependentAssembly>
|
||||||
</assemblyBinding>
|
</assemblyBinding>
|
||||||
</runtime>
|
</runtime>
|
||||||
|
@ -8,8 +8,6 @@ public static class Program
|
|||||||
static void Main()
|
static void Main()
|
||||||
{
|
{
|
||||||
ServiceHelper.Run(@"/i");
|
ServiceHelper.Run(@"/i");
|
||||||
Console.WriteLine("Press any key to continue");
|
|
||||||
Console.ReadLine();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace ServiceUninstall
|
namespace ServiceUninstall
|
||||||
{
|
{
|
||||||
@ -8,8 +7,6 @@ public static class Program
|
|||||||
static void Main()
|
static void Main()
|
||||||
{
|
{
|
||||||
ServiceHelper.Run(@"/u");
|
ServiceHelper.Run(@"/u");
|
||||||
Console.WriteLine("Press any key to continue");
|
|
||||||
Console.ReadLine();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user