mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 11:44:58 +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 Orchard.Specs.Hosting;
|
||||
using TechTalk.SpecFlow;
|
||||
using Path = Bleroy.FluentPath.Path;
|
||||
|
||||
namespace Orchard.Specs.Bindings {
|
||||
[Binding]
|
||||
@@ -17,9 +18,7 @@ namespace Orchard.Specs.Bindings {
|
||||
private RequestDetails _details;
|
||||
private HtmlDocument _doc;
|
||||
private MessageSink _messages;
|
||||
|
||||
public WebAppHosting() {
|
||||
}
|
||||
private static readonly Path _orchardTemp = Path.Get(System.IO.Path.GetTempPath()).Combine("Orchard.Specs");
|
||||
|
||||
public WebHost Host {
|
||||
get { return _webHost; }
|
||||
@@ -30,6 +29,16 @@ namespace Orchard.Specs.Bindings {
|
||||
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]
|
||||
public void AfterScenario() {
|
||||
if (_webHost != null) {
|
||||
@@ -46,7 +55,7 @@ namespace Orchard.Specs.Bindings {
|
||||
|
||||
[Given(@"I have a clean site based on (.*)")]
|
||||
public void GivenIHaveACleanSiteBasedOn(string siteFolder) {
|
||||
_webHost = new WebHost();
|
||||
_webHost = new WebHost(_orchardTemp);
|
||||
Host.Initialize(siteFolder, "/");
|
||||
var shuttle = new Shuttle();
|
||||
Host.Execute(() => {
|
||||
|
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Web.Hosting;
|
||||
using Orchard.Specs.Util;
|
||||
@@ -7,15 +6,25 @@ using Path = Bleroy.FluentPath.Path;
|
||||
|
||||
namespace Orchard.Specs.Hosting {
|
||||
public class WebHost {
|
||||
private readonly Path _orchardTemp;
|
||||
private WebHostAgent _webHostAgent;
|
||||
private Path _tempSite;
|
||||
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) {
|
||||
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.
|
||||
// The second one is for the target "spec" in orchard.proj.
|
||||
@@ -62,6 +71,10 @@ namespace Orchard.Specs.Hosting {
|
||||
_webHostAgent.Shutdown();
|
||||
_webHostAgent = null;
|
||||
}
|
||||
try {
|
||||
_tempSite.Delete(true); // <- progressively clean as much as possible
|
||||
}
|
||||
catch {}
|
||||
}
|
||||
|
||||
public void CopyExtension(string extensionFolder, string extensionName) {
|
||||
|
@@ -1,14 +1,9 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Web;
|
||||
using System.Web.Hosting;
|
||||
using Orchard.Specs.Hosting.Orchard.Web;
|
||||
|
||||
namespace Orchard.Specs.Hosting {
|
||||
public class WebHostAgent : MarshalByRefObject
|
||||
{
|
||||
public SerializableDelegate<Action> Execute(SerializableDelegate<Action> shuttle)
|
||||
{
|
||||
public class WebHostAgent : MarshalByRefObject {
|
||||
public SerializableDelegate<Action> Execute(SerializableDelegate<Action> shuttle) {
|
||||
shuttle.Delegate();
|
||||
return shuttle;
|
||||
}
|
||||
@@ -17,4 +12,4 @@ namespace Orchard.Specs.Hosting {
|
||||
HostingEnvironment.InitiateShutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user