1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

Automation ;)

This commit is contained in:
kay.one 2011-12-18 21:08:36 -08:00
parent 1ee2ae8210
commit b8def06782
20 changed files with 13853 additions and 11 deletions

View File

@ -11,19 +11,13 @@ public class EnviromentProvider
public const string NZBDRONE_PID = "NZBDRONE_PID";
public const string ROOT_MARKER = "NzbDrone.Web";
#if DEBUG
private static readonly bool isInDebug = true;
#else
private static readonly bool isInDebug = false;
#endif
private static readonly string processName = Process.GetCurrentProcess().ProcessName.ToLower();
public static bool IsProduction
{
get
{
if (isInDebug || Debugger.IsAttached) return false;
if (IsDebug || Debugger.IsAttached) return false;
if (processName.Contains("nunit")) return false;
if (processName.Contains("jetbrain")) return false;
@ -33,6 +27,19 @@ public static bool IsProduction
}
}
public static bool IsDebug
{
get
{
#if DEBUG
return true;
#else
return false;
#endif
}
}
public virtual bool IsUserInteractive
{
get { return Environment.UserInteractive; }

View File

@ -0,0 +1,163 @@
using System;
using System.Diagnostics;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using NUnit.Framework;
using NzbDrone.Common;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Remote;
namespace NzbDrone.Web.UI.Automation
{
public abstract class AutomationTestBase
{
static readonly EnviromentProvider enviromentProvider = new EnviromentProvider();
private static readonly string testFolder;
public string AppUrl
{
get
{
return "http://localhost:8989";
}
}
public RemoteWebDriver Driver { get; private set; }
static AutomationTestBase()
{
CleanBinFolder();
testFolder = CreatePackage();
StartNzbDrone();
}
[SetUp]
public void AutomationSetup()
{
Driver = new FirefoxDriver();
}
[TearDown]
public void AutomationTearDown()
{
Driver.Close();
if (!Directory.Exists(Directory.GetCurrentDirectory() + "\\Screenshots"))
{
Directory.CreateDirectory(Directory.GetCurrentDirectory() + "\\Screenshots");
}
foreach (var file in Directory.GetFiles(Directory.GetCurrentDirectory(), "*__*.png").Select(c => new FileInfo(c)))
{
File.Copy(file.FullName, Directory.GetCurrentDirectory() + "\\Screenshots\\" + file.Name, true);
file.Delete();
}
}
[TestFixtureSetUp]
public void AutomationTestFixtureSetup()
{
StopNzbDrone();
ResetUserData();
StartNzbDrone();
}
[TestFixtureTearDown]
public void AutomationTestFixtureTearDown()
{
StopNzbDrone();
}
protected void CaptureScreen()
{
var method = new StackFrame(1).GetMethod().Name;
var fileName = String.Format("{0}__{1}.png", this.GetType().Name, method);
((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 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()
{
Process.Start(Path.Combine(testFolder, "nzbdrone.exe"));
}
public static void StopNzbDrone()
{
foreach (var process in Process.GetProcessesByName("nzbdrone"))
{
process.Kill();
process.WaitForExit();
}
}
private static string CreatePackage()
{
Console.WriteLine("Creating NzbDrone Package");
StopNzbDrone();
var rootDirectory = new DirectoryInfo(enviromentProvider.ApplicationPath);
if (rootDirectory.GetDirectories("_rawPackage").Any())
{
rootDirectory.GetDirectories("_rawPackage").ToList().ForEach(c => c.Delete(true));
}
var startInfo = new ProcessStartInfo
{
FileName = Path.Combine(rootDirectory.FullName, "package.bat"),
WorkingDirectory = rootDirectory.FullName
};
Process.Start(startInfo).WaitForExit();
var testFolder = Path.Combine(enviromentProvider.SystemTemp, "NzbDroneAutomation");
if (Directory.Exists(testFolder))
{
Directory.Delete(testFolder, true);
}
Directory.Move(Path.Combine(rootDirectory.FullName, "_rawPackage", "nzbdrone"), testFolder);
return testFolder;
}
}
}

View File

@ -0,0 +1,43 @@
using System.Linq;
using NUnit.Framework;
using NzbDrone.Web.UI.Automation.Fluent;
namespace NzbDrone.Web.UI.Automation
{
[TestFixture]
public class BasicPageFixture : AutomationTestBase
{
[Test]
public void HomePage()
{
Driver.GivenHomePage().Should().BeNzbDronePage();
CaptureScreen();
}
[Test]
public void HistoryPage()
{
Driver.GivenHistoryPage().Should().BeNzbDronePage();
CaptureScreen();
}
[Test]
public void MissingPage()
{
Driver.GivenMissingPage().Should().BeNzbDronePage();
CaptureScreen();
}
[Test]
public void SettingsPage()
{
Driver.GivenSettingsPage().Should().BeNzbDronePage();
CaptureScreen();
}
}
}

Binary file not shown.

View File

@ -0,0 +1,13 @@
using System.Linq;
using OpenQA.Selenium.Remote;
namespace NzbDrone.Web.UI.Automation.Fluent
{
public static class AssertionExtention
{
public static DriverAssertion Should(this RemoteWebDriver actualValue)
{
return new DriverAssertion(actualValue);
}
}
}

View File

@ -0,0 +1,21 @@
using System.Linq;
using FluentAssertions;
using OpenQA.Selenium.Remote;
namespace NzbDrone.Web.UI.Automation.Fluent
{
public class DriverAssertion
{
private readonly RemoteWebDriver _driver;
public DriverAssertion(RemoteWebDriver driver)
{
_driver = driver;
}
public void BeNzbDronePage()
{
_driver.Title.Should().EndWith("NzbDrone");
}
}
}

View File

@ -0,0 +1,41 @@
using System.Linq;
using OpenQA.Selenium.Remote;
namespace NzbDrone.Web.UI.Automation.Fluent
{
public static class NavigationExtention
{
private const string baseUrl = "http://localhost:8989/";
public static RemoteWebDriver GivenHomePage(this RemoteWebDriver driver)
{
driver.Navigate().GoToUrl(baseUrl);
return driver;
}
public static RemoteWebDriver GivenSettingsPage(this RemoteWebDriver driver)
{
driver.Navigate().GoToUrl(baseUrl + "settings");
return driver;
}
public static RemoteWebDriver GivenUpcomingPage(this RemoteWebDriver driver)
{
driver.Navigate().GoToUrl(baseUrl + "Upcoming");
return driver;
}
public static RemoteWebDriver GivenHistoryPage(this RemoteWebDriver driver)
{
driver.Navigate().GoToUrl(baseUrl + "History");
return driver;
}
public static RemoteWebDriver GivenMissingPage(this RemoteWebDriver driver)
{
driver.Navigate().GoToUrl(baseUrl + "Missing");
return driver;
}
}
}

View File

@ -0,0 +1,97 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{3CCD64E1-84DA-4853-B7EF-98B02FD4E39E}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>NzbDrone.Web.UI.Automation</RootNamespace>
<AssemblyName>NzbDrone.Web.UI.Automation</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="FluentAssertions">
<HintPath>..\packages\FluentAssertions.1.6.0\Lib\net40\FluentAssertions.dll</HintPath>
</Reference>
<Reference Include="Ionic.Zip">
<HintPath>..\packages\DotNetZip.1.9.1.8\lib\net20\Ionic.Zip.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.4.0.4\lib\net40\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit.2.5.10.11092\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="WebDriver">
<HintPath>..\packages\Selenium.WebDriver.2.15.0\lib\net40\WebDriver.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="BasicPageFixture.cs" />
<Compile Include="Fluent\AssertionExtention.cs" />
<Compile Include="Fluent\DriverAssertion.cs" />
<Compile Include="Fluent\NavigationExtention.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="AutomationTestBase.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="Drivers\chromedriver.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NzbDrone.Common\NzbDrone.Common.csproj">
<Project>{F2BE0FDF-6E47-4827-A420-DD4EF82407F8}</Project>
<Name>NzbDrone.Common</Name>
</ProjectReference>
<ProjectReference Include="..\NzbDrone.Web\NzbDrone.Web.csproj">
<Project>{43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}</Project>
<Name>NzbDrone.Web</Name>
</ProjectReference>
<ProjectReference Include="..\NzbDrone\NzbDrone.csproj">
<Project>{D12F7F2F-8A3C-415F-88FA-6DD061A84869}</Project>
<Name>NzbDrone</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("NzbDrone.Web.UI.Test")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NzbDrone.Web.UI.Test")]
[assembly: AssemblyCopyright("Copyright © 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("8fa28d95-f018-482c-a834-139d0d9f44f2")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="DotNetZip" version="1.9.1.8" />
<package id="Newtonsoft.Json" version="4.0.4" />
<package id="Selenium.WebDriver" version="2.15.0" />
</packages>

View File

@ -37,6 +37,8 @@ public ActionResult Jobs()
});
var jobs = _jobProvider.All();
return View(jobs);
}

View File

@ -1,4 +1,4 @@
@using NzbDrone.Web.Models
@using NzbDrone.Web.Models
@using NzbDrone.Web.Helpers
@model IEnumerable<NzbDrone.Core.Repository.JobDefinition>
@{ViewBag.Title = "Jobs";}

View File

@ -27,6 +27,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Test.Common", "Nzb
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Test.Common", "Test.Common", "{47697CDB-27B6-4B05-B4F8-0CBE6F6EDF97}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Web.UI.Automation", "NzbDrone.Web.UI.Test\NzbDrone.Web.UI.Automation.csproj", "{3CCD64E1-84DA-4853-B7EF-98B02FD4E39E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -177,6 +179,18 @@ Global
{CADDFCE0-7509-4430-8364-2074E1EEFCA2}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{CADDFCE0-7509-4430-8364-2074E1EEFCA2}.Release|x64.ActiveCfg = Release|Any CPU
{CADDFCE0-7509-4430-8364-2074E1EEFCA2}.Release|x86.ActiveCfg = Release|Any CPU
{3CCD64E1-84DA-4853-B7EF-98B02FD4E39E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3CCD64E1-84DA-4853-B7EF-98B02FD4E39E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3CCD64E1-84DA-4853-B7EF-98B02FD4E39E}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{3CCD64E1-84DA-4853-B7EF-98B02FD4E39E}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{3CCD64E1-84DA-4853-B7EF-98B02FD4E39E}.Debug|x64.ActiveCfg = Debug|Any CPU
{3CCD64E1-84DA-4853-B7EF-98B02FD4E39E}.Debug|x86.ActiveCfg = Debug|Any CPU
{3CCD64E1-84DA-4853-B7EF-98B02FD4E39E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3CCD64E1-84DA-4853-B7EF-98B02FD4E39E}.Release|Any CPU.Build.0 = Release|Any CPU
{3CCD64E1-84DA-4853-B7EF-98B02FD4E39E}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{3CCD64E1-84DA-4853-B7EF-98B02FD4E39E}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{3CCD64E1-84DA-4853-B7EF-98B02FD4E39E}.Release|x64.ActiveCfg = Release|Any CPU
{3CCD64E1-84DA-4853-B7EF-98B02FD4E39E}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -184,9 +198,10 @@ Global
GlobalSection(NestedProjects) = preSolution
{193ADD3B-792B-4173-8E4C-5A3F8F0237F0} = {57A04B72-8088-4F75-A582-1158CF8291F7}
{C0EA1A40-91AD-4EEB-BD16-2DDDEBD20AE5} = {57A04B72-8088-4F75-A582-1158CF8291F7}
{47697CDB-27B6-4B05-B4F8-0CBE6F6EDF97} = {57A04B72-8088-4F75-A582-1158CF8291F7}
{35388E8E-0CDB-4A84-AD16-E4B6EFDA5D97} = {57A04B72-8088-4F75-A582-1158CF8291F7}
{BEC74619-DDBB-4FBA-B517-D3E20AFC9997} = {57A04B72-8088-4F75-A582-1158CF8291F7}
{47697CDB-27B6-4B05-B4F8-0CBE6F6EDF97} = {57A04B72-8088-4F75-A582-1158CF8291F7}
{3CCD64E1-84DA-4853-B7EF-98B02FD4E39E} = {57A04B72-8088-4F75-A582-1158CF8291F7}
{CADDFCE0-7509-4430-8364-2074E1EEFCA2} = {47697CDB-27B6-4B05-B4F8-0CBE6F6EDF97}
{FAFB5948-A222-4CF6-AD14-026BE7564802} = {47697CDB-27B6-4B05-B4F8-0CBE6F6EDF97}
EndGlobalSection

View File

@ -7,8 +7,12 @@ del nzbdrone*.zip /Q /F
xcopy IISExpress %TARGET%\IISExpress /E /V /I /Y
xcopy NzbDrone\bin\Debug\*.* %TARGET%\ /E /V /I /Y
xcopy NzbDrone\bin\Release\*.* %TARGET%\ /E /V /I /Y
xcopy NzbDrone.Update\bin\Debug\*.* %TARGET%\NzbDrone.Update\ /E /V /I /Y
xcopy NzbDrone.Update\bin\Release\*.* %TARGET%\NzbDrone.Update\ /E /V /I /Y
xcopy NzbDrone.Web\bin\*.* %TARGET%\NzbDrone.Web\bin\ /E /V /I /Y
@ -40,4 +44,3 @@ del Mvc*.pdb /Q /F /S
..\Libraries\7zip\7za.exe a -tzip ..\NzbDrone.zip *
CD ..
Pause

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -10,4 +10,5 @@
<repository path="..\NzbDrone.Common\packages.config" />
<repository path="..\NzbDrone.Common.Test\packages.config" />
<repository path="..\NzbDrone.Test.Common\packages.config" />
<repository path="..\NzbDrone.Web.UI.Test\packages.config" />
</repositories>