Author: andrews
Date: 2006-06-22 12:37:08 -0400 (Thu, 22 Jun 2006)
New Revision: 61939
Added:
trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/PostableRequest.cs
trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/PostableWorkerRequest.cs
Modified:
trunk/mcs/class/System.Web/System.Web_test.dll.sources
trunk/mcs/class/System.Web/Test/mainsoft/MainsoftWebTest/HtmlCompare.csproj
trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/BaseRequest.cs
trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/BaseWorkerRequest.cs
trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/FormRequest.cs
trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/MyHost.cs
trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/NunitWeb.csproj
trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/Test1/Class1.cs
Log:
support for POST method in test framework and forms
Modified: trunk/mcs/class/System.Web/System.Web_test.dll.sources
===================================================================
--- trunk/mcs/class/System.Web/System.Web_test.dll.sources 2006-06-22
16:23:24 UTC (rev 61938)
+++ trunk/mcs/class/System.Web/System.Web_test.dll.sources 2006-06-22
16:37:08 UTC (rev 61939)
@@ -21,6 +21,8 @@
mainsoft/NunitWeb/NunitWeb/MyHost.cs
mainsoft/NunitWeb/NunitWeb/PageDelegates.cs
mainsoft/NunitWeb/NunitWeb/PageInvoker.cs
+mainsoft/NunitWeb/NunitWeb/PostableRequest.cs
+mainsoft/NunitWeb/NunitWeb/PostableWorkerRequest.cs
mainsoft/NunitWeb/NunitWeb/Response.cs
mainsoft/NunitWeb/NunitWeb/StandardUrl.cs
mainsoft/NunitWeb/NunitWeb/WebTest.cs
Modified:
trunk/mcs/class/System.Web/Test/mainsoft/MainsoftWebTest/HtmlCompare.csproj
===================================================================
--- trunk/mcs/class/System.Web/Test/mainsoft/MainsoftWebTest/HtmlCompare.csproj
2006-06-22 16:23:24 UTC (rev 61938)
+++ trunk/mcs/class/System.Web/Test/mainsoft/MainsoftWebTest/HtmlCompare.csproj
2006-06-22 16:37:08 UTC (rev 61939)
@@ -49,7 +49,9 @@
<Compile Include="XmlComparer.cs" />
</ItemGroup>
<ItemGroup>
+ <EmbeddedResource Include="almost_config.xml" />
<Content Include="HtmlAgilityPack\readme.txt" />
+ <EmbeddedResource Include="nunitweb_config.xml" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
Modified:
trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/BaseRequest.cs
===================================================================
--- trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/BaseRequest.cs
2006-06-22 16:23:24 UTC (rev 61938)
+++ trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/BaseRequest.cs
2006-06-22 16:37:08 UTC (rev 61939)
@@ -39,11 +39,16 @@
public virtual HttpWorkerRequest CreateWorkerRequest ()
{
StringWriter wr = new StringWriter ();
- BaseWorkerRequest br = new BaseWorkerRequest (Url,
GetQueryString (), wr);
+ BaseWorkerRequest br = CreateBaseWorkerRequest (wr);
((IDictionary) br) [GetType ()] = wr;
return br;
}
+ protected virtual BaseWorkerRequest CreateBaseWorkerRequest
(StringWriter wr)
+ {
+ return new BaseWorkerRequest (Url, GetQueryString (),
wr);
+ }
+
protected virtual string GetQueryString ()
{
return "";
@@ -55,7 +60,7 @@
/// <param name="request">this must be the same request that
was returned by
/// CreateWorkerRequest</param>
/// <returns></returns>
- public virtual Response GetRequestResult (HttpWorkerRequest
request)
+ public virtual Response ExtractResponse (HttpWorkerRequest
request)
{
BaseWorkerRequest br = (BaseWorkerRequest) request;
IDictionary d = (IDictionary) br;
Modified:
trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/BaseWorkerRequest.cs
===================================================================
---
trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/BaseWorkerRequest.cs
2006-06-22 16:23:24 UTC (rev 61938)
+++
trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/BaseWorkerRequest.cs
2006-06-22 16:37:08 UTC (rev 61939)
@@ -2,101 +2,101 @@
using System.Web;
using System.Web.Hosting;
using System.IO;
-using System.Collections;
-
-namespace MonoTests.SystemWeb.Framework
-{
- public class BaseWorkerRequest: SimpleWorkerRequest, IDictionary
- {
- public BaseWorkerRequest (string page, string query, TextWriter
writer):
- base (page, query, writer)
- {
- }
-
- Hashtable data = new Hashtable ();
- #region IDictionary Members
-
- void IDictionary.Add (object key, object value)
- {
- data.Add (key, value);
- }
-
- void IDictionary.Clear ()
- {
- data.Clear ();
- }
-
- bool IDictionary.Contains (object key)
- {
- return data.Contains (key);
- }
-
- IDictionaryEnumerator IDictionary.GetEnumerator ()
- {
- return data.GetEnumerator ();
- }
-
- bool IDictionary.IsFixedSize
- {
- get { return data.IsFixedSize; }
- }
-
- bool IDictionary.IsReadOnly
- {
- get { return data.IsReadOnly; }
- }
-
- ICollection IDictionary.Keys
- {
- get { return data.Keys; }
- }
-
- void IDictionary.Remove (object key)
- {
- data.Remove (key);
- }
-
- ICollection IDictionary.Values
- {
- get { return data.Values; }
- }
-
- object IDictionary.this[object key]
- {
- get
- {
- return data[key];
- }
- set
- {
- data[key] = value;
- }
- }
-
- void ICollection.CopyTo (Array array, int index)
- {
- data.CopyTo (array, index);
- }
-
- int ICollection.Count
- {
- get { return data.Count; }
- }
-
- bool ICollection.IsSynchronized
- {
- get { return data.IsSynchronized; }
- }
-
- object ICollection.SyncRoot
- {
- get { return data.SyncRoot; }
- }
-
- IEnumerator IEnumerable.GetEnumerator ()
- {
- return data.GetEnumerator ();
- }
- #endregion
- }
+using System.Collections;
+
+namespace MonoTests.SystemWeb.Framework
+{
+ public class BaseWorkerRequest : SimpleWorkerRequest, IDictionary
+ {
+ public BaseWorkerRequest (string page, string query, TextWriter
writer)
+ : base (page, query, writer)
+ {
+ }
+
+ Hashtable data = new Hashtable ();
+ #region IDictionary Members
+
+ void IDictionary.Add (object key, object value)
+ {
+ data.Add (key, value);
+ }
+
+ void IDictionary.Clear ()
+ {
+ data.Clear ();
+ }
+
+ bool IDictionary.Contains (object key)
+ {
+ return data.Contains (key);
+ }
+
+ IDictionaryEnumerator IDictionary.GetEnumerator ()
+ {
+ return data.GetEnumerator ();
+ }
+
+ bool IDictionary.IsFixedSize
+ {
+ get { return data.IsFixedSize; }
+ }
+
+ bool IDictionary.IsReadOnly
+ {
+ get { return data.IsReadOnly; }
+ }
+
+ ICollection IDictionary.Keys
+ {
+ get { return data.Keys; }
+ }
+
+ void IDictionary.Remove (object key)
+ {
+ data.Remove (key);
+ }
+
+ ICollection IDictionary.Values
+ {
+ get { return data.Values; }
+ }
+
+ object IDictionary.this[object key]
+ {
+ get
+ {
+ return data[key];
+ }
+ set
+ {
+ data[key] = value;
+ }
+ }
+
+ void ICollection.CopyTo (Array array, int index)
+ {
+ data.CopyTo (array, index);
+ }
+
+ int ICollection.Count
+ {
+ get { return data.Count; }
+ }
+
+ bool ICollection.IsSynchronized
+ {
+ get { return data.IsSynchronized; }
+ }
+
+ object ICollection.SyncRoot
+ {
+ get { return data.SyncRoot; }
+ }
+
+ IEnumerator IEnumerable.GetEnumerator ()
+ {
+ return data.GetEnumerator ();
+ }
+ #endregion
+ }
}
Modified:
trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/FormRequest.cs
===================================================================
--- trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/FormRequest.cs
2006-06-22 16:23:24 UTC (rev 61938)
+++ trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/FormRequest.cs
2006-06-22 16:37:08 UTC (rev 61939)
@@ -9,7 +9,7 @@
namespace MonoTests.SystemWeb.Framework
{
[Serializable]
- public class FormRequest : BaseRequest
+ public class FormRequest : PostableRequest
{
public FormRequest (Response response, string formId)
{
@@ -43,6 +43,11 @@
string actionUrl = formNode.Attributes["action"].Value;
if (actionUrl != null && actionUrl != string.Empty)
base.Url = actionUrl;
+ XmlNode method = formNode.Attributes["method"];
+ if (method != null && "POST" == method.Value)
+ base.IsPost = true;
+ else
+ base.IsPost = false;
#if USE_CORRECT_FORMID
foreach (XmlNode inputNode in formNode.SelectNodes
("//html:input", nsmgr))
@@ -71,8 +76,34 @@
set { throw new Exception ("Must not change Url of
FormPostback"); }
}
+ public override bool IsPost
+ {
+ get { return base.IsPost; }
+ set { throw new Exception ("Must not change IsPost of
FormPostback"); }
+ }
+
+ public override string PostContentType
+ {
+ get { return "application/x-www-form-urlencoded"; }
+ set { throw new Exception ("Must not change
PostContentType of FormPostback"); }
+ }
+
+ public override byte[] PostData
+ {
+ get { return Encoding.ASCII.GetBytes (GetParameters
()); }
+ set { throw new Exception ("Must not change PostData of
FormPostback"); }
+ }
+
protected override string GetQueryString ()
{
+ if (IsPost)
+ return "";
+ else
+ return GetParameters ();
+ }
+
+ protected string GetParameters ()
+ {
StringBuilder query = new StringBuilder ();
bool first = true;
foreach (string key in Fields.AllKeys) {
Modified: trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/MyHost.cs
===================================================================
--- trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/MyHost.cs
2006-06-22 16:23:24 UTC (rev 61938)
+++ trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/MyHost.cs
2006-06-22 16:37:08 UTC (rev 61939)
@@ -40,7 +40,7 @@
d[GetType ()] = data;
HttpRuntime.ProcessRequest (wr);
- Response res = request.GetRequestResult (wr);
+ Response res = request.ExtractResponse (wr);
if (data.exception != null)
RethrowException (data.exception);
Modified:
trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/NunitWeb.csproj
===================================================================
--- trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/NunitWeb.csproj
2006-06-22 16:23:24 UTC (rev 61938)
+++ trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/NunitWeb.csproj
2006-06-22 16:37:08 UTC (rev 61939)
@@ -17,7 +17,8 @@
<DefineConstants>TRACE;DEBUG;NET_2_0;VISUAL_STUDIO</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
- <DocumentationFile>bin\Debug\NunitWeb.XML</DocumentationFile>
+ <DocumentationFile>
+ </DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' ==
'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
@@ -29,13 +30,13 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
+ <Reference Include="System.Data" />
<Reference Include="System.Web" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="BaseInvoker.cs" />
<Compile Include="BaseRequest.cs" />
- <Compile Include="FormPostback.cs" />
<Compile Include="FormRequest.cs" />
<Compile Include="HandlerInvoker.cs" />
<Compile Include="MyHandler.cs" />
@@ -47,6 +48,9 @@
</Compile>
<Compile Include="PageDelegates.cs" />
<Compile Include="PageInvoker.cs" />
+ <Compile Include="PostableRequest.cs" />
+ <Compile Include="PostableWorkerRequest.cs" />
+ <Compile Include="Response.cs" />
<Compile Include="StandardUrl.cs" />
<Compile Include="WebTest.cs">
<SubType>Code</SubType>
Added:
trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/PostableRequest.cs
===================================================================
---
trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/PostableRequest.cs
2006-06-22 16:23:24 UTC (rev 61938)
+++
trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/PostableRequest.cs
2006-06-22 16:37:08 UTC (rev 61939)
@@ -0,0 +1,49 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace MonoTests.SystemWeb.Framework
+{
+ [Serializable]
+ public class PostableRequest:BaseRequest
+ {
+ bool _isPost;
+ public virtual bool IsPost
+ {
+ get { return _isPost; }
+ set { _isPost = value; }
+ }
+
+ byte[] postData;
+ public virtual byte[] PostData
+ {
+ get { return postData; }
+ set { postData = value; }
+ }
+
+ string postContentType;
+ public virtual string PostContentType
+ {
+ get { return postContentType; }
+ set { postContentType = value; }
+ }
+
+ public PostableRequest ()
+ :base ()
+ {
+ }
+
+ public PostableRequest (string url)
+ :base (url)
+ {
+ }
+
+ protected override BaseWorkerRequest CreateBaseWorkerRequest
(System.IO.StringWriter wr)
+ {
+ if (PostData == null || !IsPost)
+ return base.CreateBaseWorkerRequest (wr);
+ return new PostableWorkerRequest (Url, GetQueryString
(),
+ wr, PostData, PostContentType);
+ }
+ }
+}
Added:
trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/PostableWorkerRequest.cs
===================================================================
---
trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/PostableWorkerRequest.cs
2006-06-22 16:23:24 UTC (rev 61938)
+++
trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/PostableWorkerRequest.cs
2006-06-22 16:37:08 UTC (rev 61939)
@@ -0,0 +1,48 @@
+using System;
+using System.IO;
+using System.Web;
+
+namespace MonoTests.SystemWeb.Framework
+{
+ public class PostableWorkerRequest:BaseWorkerRequest
+ {
+ byte[] postData;
+ string postContentType;
+
+ public override String GetHttpVerbName ()
+ {
+ if (postData == null)
+ return base.GetHttpVerbName ();
+ return "POST";
+ }
+
+ public override string GetKnownRequestHeader (int index)
+ {
+ if (postData == null)
+ return base.GetKnownRequestHeader (index);
+
+ switch (index) {
+ case HttpWorkerRequest.HeaderContentLength:
+ return postData.Length.ToString ();
+ case HttpWorkerRequest.HeaderContentType:
+ return postContentType;
+ default:
+ return base.GetKnownRequestHeader (index);
+ }
+ }
+
+ public override byte[] GetPreloadedEntityBody ()
+ {
+ if (postData == null)
+ return base.GetPreloadedEntityBody ();
+ return postData;
+ }
+
+ public PostableWorkerRequest (string page, string query,
TextWriter writer, byte[] postData, string postContentType)
+ : base (page, query, writer)
+ {
+ this.postData = postData;
+ this.postContentType = postContentType;
+ }
+ }
+}
Modified: trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/Test1/Class1.cs
===================================================================
--- trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/Test1/Class1.cs
2006-06-22 16:23:24 UTC (rev 61938)
+++ trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/Test1/Class1.cs
2006-06-22 16:37:08 UTC (rev 61939)
@@ -136,7 +136,31 @@
public void PostBack ()
{
WebTest.CopyResource (GetType (),
"Test1.Resources.Postback.aspx", "Postback.aspx");
- string res = new WebTest ("Postback.aspx").Run ();
+ WebTest t = new WebTest ("Postback.aspx");
+ string res1 = t.Run ();
+ FormRequest fr = new FormRequest (t.Response, "form1");
+ fr.Fields["txt1"] = "value";
+ WebTest t1 = new WebTest (fr);
+ string res2 = t1.Run ();
+ FormRequest fr1 = new FormRequest (t1.Response,
"form1");
+ fr.Fields["txt1"] = "value1";
+ string res3 = new WebTest (fr).Run ();
+ Assert.IsTrue (res3.IndexOf ("value1") != -1);
}
+
+ [Test]
+ public void PostRequest ()
+ {
+ WebTest t = new WebTest (PageInvoker.CreateOnLoad
(CheckPostRequest));
+ PostableRequest pr = new PostableRequest ();
+ pr.IsPost = true;
+ t.Request = pr;
+ t.Run ();
+ }
+
+ static public void CheckPostRequest (Page p)
+ {
+ Assert.AreEqual ("POST",
HttpContext.Current.Request.RequestType);
+ }
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches