mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Setup integration test working
Added (very bad) cookie support to integration test lib Workaround to resolving collections appears to have worked --HG-- branch : dev
This commit is contained in:
@@ -7,6 +7,11 @@ using HtmlAgilityPack;
|
||||
namespace Orchard.Specs.Hosting {
|
||||
[Serializable]
|
||||
public class RequestDetails {
|
||||
public RequestDetails() {
|
||||
RequestHeaders = new Dictionary<string, string>();
|
||||
ResponseHeaders = new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
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<string, string> RequestHeaders { get; set; }
|
||||
public IDictionary<string, string> ResponseHeaders { get; set; }
|
||||
}
|
||||
}
|
||||
|
@@ -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<string, IEnumerable<string>> 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));
|
||||
}
|
||||
|
@@ -0,0 +1,3 @@
|
||||
<%@ Page %>
|
||||
|
||||
<% Response.Cookies.Add(new HttpCookie("foo", "bar")); %>
|
@@ -0,0 +1,8 @@
|
||||
<%@ Page %>
|
||||
|
||||
<ul>
|
||||
<% foreach(string name in Request.Cookies) {%>
|
||||
<li>
|
||||
<%=name %>:<%=Request.Cookies[name].Value %></li>
|
||||
<%}%>
|
||||
</ul>
|
@@ -1,5 +1,17 @@
|
||||
<%@ Page %>
|
||||
|
||||
<p>Hello again</p>
|
||||
<p>RawUrl: <%=Page.Request.RawUrl%></p>
|
||||
<p>Moving along to <a href="/hello-world">next page</a></p>
|
||||
<p>
|
||||
Hello again</p>
|
||||
<p>
|
||||
RawUrl:
|
||||
<%=Page.Request.RawUrl%></p>
|
||||
<p>
|
||||
Moving along to <a href="/hello-world">next page</a></p>
|
||||
<p>
|
||||
<form action="<%=ResolveUrl("~/Simple/Results.aspx") %>" method="post">
|
||||
<input type="text" name="passthrough1" value="alpha" />
|
||||
<input type="hidden" name="passthrough2" value="beta" />
|
||||
<input type="hidden" name="input1" />
|
||||
<input type="submit" value="Go!" />
|
||||
</form>
|
||||
</p>
|
||||
|
7
src/Orchard.Specs/Hosting/Simple.Web/Simple/Results.aspx
Normal file
7
src/Orchard.Specs/Hosting/Simple.Web/Simple/Results.aspx
Normal file
@@ -0,0 +1,7 @@
|
||||
<%@ Page %>
|
||||
|
||||
<ul>
|
||||
<li>passthrough1:<%=Server.HtmlEncode(Request.Form.Get("passthrough1")) %></li>
|
||||
<li>passthrough2:<%=Server.HtmlEncode(Request.Form.Get("passthrough2")) %></li>
|
||||
<li>input1:<%=Server.HtmlEncode(Request.Form.Get("input1")) %></li>
|
||||
</ul>
|
@@ -42,7 +42,7 @@
|
||||
affects performance, set this value to true only
|
||||
during development.
|
||||
-->
|
||||
<compilation debug="true">
|
||||
<compilation debug="true" defaultLanguage="cs">
|
||||
<assemblies>
|
||||
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
|
||||
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
|
||||
|
@@ -47,6 +47,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>(action);
|
||||
var shuttleRecv = _webHostAgent.Execute(shuttleSend);
|
||||
|
@@ -222,6 +222,15 @@
|
||||
<Content Include="Hosting\Simple.Web\Global.asax">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Hosting\Simple.Web\Simple\Cookie-Show.aspx">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Hosting\Simple.Web\Simple\Cookie-Set.aspx">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Hosting\Simple.Web\Simple\Results.aspx">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Hosting\Simple.Web\Simple\Page.aspx">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
|
@@ -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 "<h1>My Site</h1>"
|
||||
And I should see "Welcome, <strong>admin</strong>!"
|
||||
And I should see "you've successfully set-up your Orchard site"
|
||||
|
8
src/Orchard.Specs/Setup.feature.cs
generated
8
src/Orchard.Specs/Setup.feature.cs
generated
@@ -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 \"<h1>My Site</h1>\"");
|
||||
#line 47
|
||||
testRunner.And("I should see \"Welcome, <strong>admin</strong>!\"");
|
||||
#line 48
|
||||
testRunner.And("I should see \"you\'ve successfully set-up your Orchard site\"");
|
||||
#line hidden
|
||||
testRunner.CollectScenarioErrors();
|
||||
}
|
||||
|
@@ -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"
|
||||
|
51
src/Orchard.Specs/WebHosting.feature.cs
generated
51
src/Orchard.Specs/WebHosting.feature.cs
generated
@@ -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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user