mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-22 03:57:14 +08:00
Updating Orchard.Spec testing to manage temporary resources a little better
--HG-- branch : dev
This commit is contained in:
@@ -9,6 +9,7 @@ using log4net.Core;
|
|||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using Orchard.Specs.Hosting;
|
using Orchard.Specs.Hosting;
|
||||||
using TechTalk.SpecFlow;
|
using TechTalk.SpecFlow;
|
||||||
|
using Path = Bleroy.FluentPath.Path;
|
||||||
|
|
||||||
namespace Orchard.Specs.Bindings {
|
namespace Orchard.Specs.Bindings {
|
||||||
[Binding]
|
[Binding]
|
||||||
@@ -17,9 +18,7 @@ namespace Orchard.Specs.Bindings {
|
|||||||
private RequestDetails _details;
|
private RequestDetails _details;
|
||||||
private HtmlDocument _doc;
|
private HtmlDocument _doc;
|
||||||
private MessageSink _messages;
|
private MessageSink _messages;
|
||||||
|
private static readonly Path _orchardTemp = Path.Get(System.IO.Path.GetTempPath()).Combine("Orchard.Specs");
|
||||||
public WebAppHosting() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public WebHost Host {
|
public WebHost Host {
|
||||||
get { return _webHost; }
|
get { return _webHost; }
|
||||||
@@ -30,6 +29,16 @@ namespace Orchard.Specs.Bindings {
|
|||||||
set { _details = value; }
|
set { _details = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[BeforeTestRun]
|
||||||
|
public static void BeforeTestRun() {
|
||||||
|
_orchardTemp.Delete(true).CreateDirectory();
|
||||||
|
}
|
||||||
|
|
||||||
|
[AfterTestRun]
|
||||||
|
public static void AfterTestRun() {
|
||||||
|
_orchardTemp.Delete(true); // <- try to clear any stragglers on the way out
|
||||||
|
}
|
||||||
|
|
||||||
[AfterScenario]
|
[AfterScenario]
|
||||||
public void AfterScenario() {
|
public void AfterScenario() {
|
||||||
if (_webHost != null) {
|
if (_webHost != null) {
|
||||||
@@ -46,7 +55,7 @@ namespace Orchard.Specs.Bindings {
|
|||||||
|
|
||||||
[Given(@"I have a clean site based on (.*)")]
|
[Given(@"I have a clean site based on (.*)")]
|
||||||
public void GivenIHaveACleanSiteBasedOn(string siteFolder) {
|
public void GivenIHaveACleanSiteBasedOn(string siteFolder) {
|
||||||
_webHost = new WebHost();
|
_webHost = new WebHost(_orchardTemp);
|
||||||
Host.Initialize(siteFolder, "/");
|
Host.Initialize(siteFolder, "/");
|
||||||
var shuttle = new Shuttle();
|
var shuttle = new Shuttle();
|
||||||
Host.Execute(() => {
|
Host.Execute(() => {
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Web.Hosting;
|
using System.Web.Hosting;
|
||||||
using Orchard.Specs.Util;
|
using Orchard.Specs.Util;
|
||||||
@@ -7,15 +6,25 @@ using Path = Bleroy.FluentPath.Path;
|
|||||||
|
|
||||||
namespace Orchard.Specs.Hosting {
|
namespace Orchard.Specs.Hosting {
|
||||||
public class WebHost {
|
public class WebHost {
|
||||||
|
private readonly Path _orchardTemp;
|
||||||
private WebHostAgent _webHostAgent;
|
private WebHostAgent _webHostAgent;
|
||||||
private Path _tempSite;
|
private Path _tempSite;
|
||||||
private Path _orchardWebPath;
|
private Path _orchardWebPath;
|
||||||
|
|
||||||
|
public WebHost(Path orchardTemp) {
|
||||||
|
_orchardTemp = orchardTemp;
|
||||||
|
AppDomain.CurrentDomain.DomainUnload += WebHostCleanup;
|
||||||
|
AppDomain.CurrentDomain.ProcessExit += WebHostCleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebHostCleanup(object sender, EventArgs e) {
|
||||||
|
_tempSite.Delete(true); // <- try to clean up after the appdomain unloads (still not guaranteed to get everything - probably overkill - might go away)
|
||||||
|
}
|
||||||
|
|
||||||
public void Initialize(string templateName, string virtualDirectory) {
|
public void Initialize(string templateName, string virtualDirectory) {
|
||||||
var baseDir = Path.Get(AppDomain.CurrentDomain.BaseDirectory);
|
var baseDir = Path.Get(AppDomain.CurrentDomain.BaseDirectory);
|
||||||
|
|
||||||
_tempSite = Path.Get(System.IO.Path.GetTempFileName()).Delete().CreateDirectory();
|
_tempSite = Path.Get(_orchardTemp).Combine(System.IO.Path.GetRandomFileName()).Delete().CreateDirectory();
|
||||||
|
|
||||||
// Trying the two known relative paths to the Orchard.Web directory.
|
// Trying the two known relative paths to the Orchard.Web directory.
|
||||||
// The second one is for the target "spec" in orchard.proj.
|
// The second one is for the target "spec" in orchard.proj.
|
||||||
@@ -62,6 +71,10 @@ namespace Orchard.Specs.Hosting {
|
|||||||
_webHostAgent.Shutdown();
|
_webHostAgent.Shutdown();
|
||||||
_webHostAgent = null;
|
_webHostAgent = null;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
_tempSite.Delete(true); // <- progressively clean as much as possible
|
||||||
|
}
|
||||||
|
catch {}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CopyExtension(string extensionFolder, string extensionName) {
|
public void CopyExtension(string extensionFolder, string extensionName) {
|
||||||
|
|||||||
@@ -1,14 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Threading;
|
|
||||||
using System.Web;
|
|
||||||
using System.Web.Hosting;
|
using System.Web.Hosting;
|
||||||
using Orchard.Specs.Hosting.Orchard.Web;
|
|
||||||
|
|
||||||
namespace Orchard.Specs.Hosting {
|
namespace Orchard.Specs.Hosting {
|
||||||
public class WebHostAgent : MarshalByRefObject
|
public class WebHostAgent : MarshalByRefObject {
|
||||||
{
|
public SerializableDelegate<Action> Execute(SerializableDelegate<Action> shuttle) {
|
||||||
public SerializableDelegate<Action> Execute(SerializableDelegate<Action> shuttle)
|
|
||||||
{
|
|
||||||
shuttle.Delegate();
|
shuttle.Delegate();
|
||||||
return shuttle;
|
return shuttle;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user