From 19e694834dade33000c5acdad2e2dd994f4b67df Mon Sep 17 00:00:00 2001
From: Louis DeJardin
Date: Wed, 21 Apr 2010 15:01:01 -0700
Subject: [PATCH] Setup integration test working
Added (very bad) cookie support to integration test lib
Workaround to resolving collections appears to have worked
--HG--
branch : dev
---
src/Orchard.Specs/Hosting/RequestDetails.cs | 8 +++
.../Hosting/RequestExtensions.cs | 39 ++++++++++++--
.../Hosting/Simple.Web/Simple/Cookie-Set.aspx | 3 ++
.../Simple.Web/Simple/Cookie-Show.aspx | 8 +++
.../Hosting/Simple.Web/Simple/Page.aspx | 18 +++++--
.../Hosting/Simple.Web/Simple/Results.aspx | 7 +++
.../Hosting/Simple.Web/Web.config | 2 +-
src/Orchard.Specs/Hosting/WebHost.cs | 3 ++
src/Orchard.Specs/Orchard.Specs.csproj | 9 ++++
src/Orchard.Specs/Setup.feature | 5 +-
src/Orchard.Specs/Setup.feature.cs | 8 ++-
src/Orchard.Specs/WebHosting.feature | 18 +++++++
src/Orchard.Specs/WebHosting.feature.cs | 51 +++++++++++++++++++
13 files changed, 170 insertions(+), 9 deletions(-)
create mode 100644 src/Orchard.Specs/Hosting/Simple.Web/Simple/Cookie-Set.aspx
create mode 100644 src/Orchard.Specs/Hosting/Simple.Web/Simple/Cookie-Show.aspx
create mode 100644 src/Orchard.Specs/Hosting/Simple.Web/Simple/Results.aspx
diff --git a/src/Orchard.Specs/Hosting/RequestDetails.cs b/src/Orchard.Specs/Hosting/RequestDetails.cs
index 9071a5122..7309cf8e2 100644
--- a/src/Orchard.Specs/Hosting/RequestDetails.cs
+++ b/src/Orchard.Specs/Hosting/RequestDetails.cs
@@ -7,6 +7,11 @@ using HtmlAgilityPack;
namespace Orchard.Specs.Hosting {
[Serializable]
public class RequestDetails {
+ public RequestDetails() {
+ RequestHeaders = new Dictionary();
+ ResponseHeaders = new Dictionary();
+ }
+
public string UrlPath { get; set; }
public string Page { get; set; }
public string Query { get; set; }
@@ -15,5 +20,8 @@ namespace Orchard.Specs.Hosting {
public int StatusCode { get; set; }
public string StatusDescription { get; set; }
public string ResponseText { get; set; }
+
+ public IDictionary RequestHeaders { get; set; }
+ public IDictionary ResponseHeaders { get; set; }
}
}
diff --git a/src/Orchard.Specs/Hosting/RequestExtensions.cs b/src/Orchard.Specs/Hosting/RequestExtensions.cs
index 7e8142dba..714295fe1 100644
--- a/src/Orchard.Specs/Hosting/RequestExtensions.cs
+++ b/src/Orchard.Specs/Hosting/RequestExtensions.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
@@ -11,6 +12,7 @@ using Orchard.Specs.Util;
namespace Orchard.Specs.Hosting {
public static class RequestExtensions {
public static RequestDetails SendRequest(this WebHost webHost, string urlPath, IDictionary> postData) {
+
var physicalPath = Bleroy.FluentPath.Path.Get(webHost.PhysicalDirectory);
var details = new RequestDetails {
@@ -20,20 +22,31 @@ namespace Orchard.Specs.Hosting {
.GetRelativePath(physicalPath),
};
+ if (!string.IsNullOrEmpty(webHost.Cookies)) {
+ details.RequestHeaders.Add("Cookie", webHost.Cookies);
+ }
+
if (postData != null) {
var requestBodyText = postData
- .SelectMany(kv=>kv.Value.Select(v=>new{k=kv.Key, v}))
- .Select((kv, n) => new {p = HttpUtility.UrlEncode(kv.k) + "=" + HttpUtility.UrlEncode(kv.v), n})
+ .SelectMany(kv => kv.Value.Select(v => new { k = kv.Key, v }))
+ .Select((kv, n) => new { p = HttpUtility.UrlEncode(kv.k) + "=" + HttpUtility.UrlEncode(kv.v), n })
.Aggregate("", (a, x) => a + (x.n == 0 ? "" : "&") + x.p);
details.PostData = Encoding.Default.GetBytes(requestBodyText);
}
webHost.Execute(() => {
var output = new StringWriter();
- HttpRuntime.ProcessRequest(new Worker(details, output));
+ var worker = new Worker(details, output);
+ HttpRuntime.ProcessRequest(worker);
details.ResponseText = output.ToString();
});
+ string setCookie;
+ if (details.ResponseHeaders.TryGetValue("Set-Cookie", out setCookie)) {
+ Trace.WriteLine(string.Format("Set-Cookie: {0}", setCookie));
+ webHost.Cookies = (webHost.Cookies + ';' + setCookie.Split(';').FirstOrDefault()).Trim(';');
+ }
+
return details;
}
@@ -71,6 +84,11 @@ namespace Orchard.Specs.Hosting {
if (_details.PostData != null)
return PostContentType;
}
+ else if (index == HeaderCookie) {
+ string value;
+ if (_details.RequestHeaders.TryGetValue("Cookie", out value))
+ return value;
+ }
return base.GetKnownRequestHeader(index);
}
@@ -89,6 +107,21 @@ namespace Orchard.Specs.Hosting {
base.SendStatus(statusCode, statusDescription);
}
+ public override void SendKnownResponseHeader(int index, string value) {
+ if (index == HeaderSetCookie) {
+ _details.ResponseHeaders.Add("Set-Cookie", value);
+ }
+ else {
+ _details.ResponseHeaders.Add("known header #" + index, value);
+ }
+ base.SendKnownResponseHeader(index, value);
+ }
+ public override void SendUnknownResponseHeader(string name, string value) {
+ _details.ResponseHeaders.Add(name, value);
+
+ base.SendUnknownResponseHeader(name, value);
+ }
+
public override void SendResponseFromFile(string filename, long offset, long length) {
_output.Write(File.ReadAllText(filename));
}
diff --git a/src/Orchard.Specs/Hosting/Simple.Web/Simple/Cookie-Set.aspx b/src/Orchard.Specs/Hosting/Simple.Web/Simple/Cookie-Set.aspx
new file mode 100644
index 000000000..8c447aef5
--- /dev/null
+++ b/src/Orchard.Specs/Hosting/Simple.Web/Simple/Cookie-Set.aspx
@@ -0,0 +1,3 @@
+<%@ Page %>
+
+<% Response.Cookies.Add(new HttpCookie("foo", "bar")); %>
diff --git a/src/Orchard.Specs/Hosting/Simple.Web/Simple/Cookie-Show.aspx b/src/Orchard.Specs/Hosting/Simple.Web/Simple/Cookie-Show.aspx
new file mode 100644
index 000000000..82c486b47
--- /dev/null
+++ b/src/Orchard.Specs/Hosting/Simple.Web/Simple/Cookie-Show.aspx
@@ -0,0 +1,8 @@
+<%@ Page %>
+
+
+ <% foreach(string name in Request.Cookies) {%>
+ -
+ <%=name %>:<%=Request.Cookies[name].Value %>
+ <%}%>
+
diff --git a/src/Orchard.Specs/Hosting/Simple.Web/Simple/Page.aspx b/src/Orchard.Specs/Hosting/Simple.Web/Simple/Page.aspx
index 43b3e5058..e823f1d4a 100644
--- a/src/Orchard.Specs/Hosting/Simple.Web/Simple/Page.aspx
+++ b/src/Orchard.Specs/Hosting/Simple.Web/Simple/Page.aspx
@@ -1,5 +1,17 @@
<%@ Page %>
-Hello again
-RawUrl: <%=Page.Request.RawUrl%>
-Moving along to next page
+
+ Hello again
+
+ RawUrl:
+ <%=Page.Request.RawUrl%>
+
+ Moving along to next page
+
+
+
diff --git a/src/Orchard.Specs/Hosting/Simple.Web/Simple/Results.aspx b/src/Orchard.Specs/Hosting/Simple.Web/Simple/Results.aspx
new file mode 100644
index 000000000..1eef63ee1
--- /dev/null
+++ b/src/Orchard.Specs/Hosting/Simple.Web/Simple/Results.aspx
@@ -0,0 +1,7 @@
+<%@ Page %>
+
+
+- passthrough1:<%=Server.HtmlEncode(Request.Form.Get("passthrough1")) %>
+- passthrough2:<%=Server.HtmlEncode(Request.Form.Get("passthrough2")) %>
+- input1:<%=Server.HtmlEncode(Request.Form.Get("input1")) %>
+
diff --git a/src/Orchard.Specs/Hosting/Simple.Web/Web.config b/src/Orchard.Specs/Hosting/Simple.Web/Web.config
index 11178f5a8..a42a156c3 100644
--- a/src/Orchard.Specs/Hosting/Simple.Web/Web.config
+++ b/src/Orchard.Specs/Hosting/Simple.Web/Web.config
@@ -42,7 +42,7 @@
affects performance, set this value to true only
during development.
-->
-
+
diff --git a/src/Orchard.Specs/Hosting/WebHost.cs b/src/Orchard.Specs/Hosting/WebHost.cs
index f395bfb18..97c95657c 100644
--- a/src/Orchard.Specs/Hosting/WebHost.cs
+++ b/src/Orchard.Specs/Hosting/WebHost.cs
@@ -46,6 +46,9 @@ namespace Orchard.Specs.Hosting {
public string PhysicalDirectory { get; private set; }
public string VirtualDirectory { get; private set; }
+
+ public string Cookies { get; set; }
+
public void Execute(Action action) {
var shuttleSend = new SerializableDelegate(action);
diff --git a/src/Orchard.Specs/Orchard.Specs.csproj b/src/Orchard.Specs/Orchard.Specs.csproj
index 11b38351b..f3e6ed61d 100644
--- a/src/Orchard.Specs/Orchard.Specs.csproj
+++ b/src/Orchard.Specs/Orchard.Specs.csproj
@@ -222,6 +222,15 @@
Always
+
+ Always
+
+
+ Always
+
+
+ Always
+
Always
diff --git a/src/Orchard.Specs/Setup.feature b/src/Orchard.Specs/Setup.feature
index a02372e1c..4f9d9b47a 100644
--- a/src/Orchard.Specs/Setup.feature
+++ b/src/Orchard.Specs/Setup.feature
@@ -42,4 +42,7 @@ Scenario: Calling setup on a brand new install
| SiteName | My Site |
| AdminPassword | 6655321 |
And I hit "Finish Setup"
- Then the status should be 302 Found
+ And I go to "/Default.aspx"
+ Then I should see "My Site
"
+ And I should see "Welcome, admin!"
+ And I should see "you've successfully set-up your Orchard site"
diff --git a/src/Orchard.Specs/Setup.feature.cs b/src/Orchard.Specs/Setup.feature.cs
index 57b64f911..fefa4b60a 100644
--- a/src/Orchard.Specs/Setup.feature.cs
+++ b/src/Orchard.Specs/Setup.feature.cs
@@ -166,7 +166,13 @@ this.ScenarioSetup(scenarioInfo);
#line 44
testRunner.And("I hit \"Finish Setup\"");
#line 45
- testRunner.Then("the status should be 302 Found");
+ testRunner.And("I go to \"/Default.aspx\"");
+#line 46
+ testRunner.Then("I should see \"My Site
\"");
+#line 47
+ testRunner.And("I should see \"Welcome, admin!\"");
+#line 48
+ testRunner.And("I should see \"you\'ve successfully set-up your Orchard site\"");
#line hidden
testRunner.CollectScenarioErrors();
}
diff --git a/src/Orchard.Specs/WebHosting.feature b/src/Orchard.Specs/WebHosting.feature
index d91c53252..2b2b1641c 100644
--- a/src/Orchard.Specs/WebHosting.feature
+++ b/src/Orchard.Specs/WebHosting.feature
@@ -51,3 +51,21 @@ Scenario: Following a link
And I follow "next page"
Then the status should be 200 OK
And I should see "Hello yet again"
+
+Scenario: Submitting a form with input, default, and hidden fields
+ Given I have a clean site based on Simple.Web
+ And I am on "/simple/page.aspx"
+ When I fill in
+ | name | value |
+ | input1 | gamma |
+ And I hit "Go!"
+ Then I should see "passthrough1:alpha"
+ And I should see "passthrough2:beta"
+ And I should see "input1:gamma"
+
+
+Scenario: Cookies follow along your request
+ Given I have a clean site based on Simple.Web
+ When I go to "/simple/cookie-set.aspx"
+ And I go to "/simple/cookie-show.aspx"
+ Then I should see "foo:bar"
diff --git a/src/Orchard.Specs/WebHosting.feature.cs b/src/Orchard.Specs/WebHosting.feature.cs
index e099421b6..e459c2657 100644
--- a/src/Orchard.Specs/WebHosting.feature.cs
+++ b/src/Orchard.Specs/WebHosting.feature.cs
@@ -200,6 +200,57 @@ this.ScenarioSetup(scenarioInfo);
testRunner.Then("the status should be 200 OK");
#line 53
testRunner.And("I should see \"Hello yet again\"");
+#line hidden
+ testRunner.CollectScenarioErrors();
+ }
+
+ [NUnit.Framework.TestAttribute()]
+ [NUnit.Framework.DescriptionAttribute("Submitting a form with input, default, and hidden fields")]
+ public virtual void SubmittingAFormWithInputDefaultAndHiddenFields()
+ {
+ TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Submitting a form with input, default, and hidden fields", ((string[])(null)));
+#line 55
+this.ScenarioSetup(scenarioInfo);
+#line 56
+ testRunner.Given("I have a clean site based on Simple.Web");
+#line 57
+ testRunner.And("I am on \"/simple/page.aspx\"");
+#line hidden
+ TechTalk.SpecFlow.Table table1 = new TechTalk.SpecFlow.Table(new string[] {
+ "name",
+ "value"});
+ table1.AddRow(new string[] {
+ "input1",
+ "gamma"});
+#line 58
+ testRunner.When("I fill in", ((string)(null)), table1);
+#line 61
+ testRunner.And("I hit \"Go!\"");
+#line 62
+ testRunner.Then("I should see \"passthrough1:alpha\"");
+#line 63
+ testRunner.And("I should see \"passthrough2:beta\"");
+#line 64
+ testRunner.And("I should see \"input1:gamma\"");
+#line hidden
+ testRunner.CollectScenarioErrors();
+ }
+
+ [NUnit.Framework.TestAttribute()]
+ [NUnit.Framework.DescriptionAttribute("Cookies follow along your request")]
+ public virtual void CookiesFollowAlongYourRequest()
+ {
+ TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Cookies follow along your request", ((string[])(null)));
+#line 67
+this.ScenarioSetup(scenarioInfo);
+#line 68
+ testRunner.Given("I have a clean site based on Simple.Web");
+#line 69
+ testRunner.When("I go to \"/simple/cookie-set.aspx\"");
+#line 70
+ testRunner.And("I go to \"/simple/cookie-show.aspx\"");
+#line 71
+ testRunner.Then("I should see \"foo:bar\"");
#line hidden
testRunner.CollectScenarioErrors();
}