summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Test/Hosting
diff options
context:
space:
mode:
Diffstat (limited to 'src/DotNetOpenAuth.Test/Hosting')
-rw-r--r--src/DotNetOpenAuth.Test/Hosting/AspNetHost.cs10
-rw-r--r--src/DotNetOpenAuth.Test/Hosting/HttpHost.cs26
-rw-r--r--src/DotNetOpenAuth.Test/Hosting/TestingWorkerRequest.cs24
3 files changed, 41 insertions, 19 deletions
diff --git a/src/DotNetOpenAuth.Test/Hosting/AspNetHost.cs b/src/DotNetOpenAuth.Test/Hosting/AspNetHost.cs
index 015a00b..94bf480 100644
--- a/src/DotNetOpenAuth.Test/Hosting/AspNetHost.cs
+++ b/src/DotNetOpenAuth.Test/Hosting/AspNetHost.cs
@@ -22,13 +22,13 @@ namespace DotNetOpenAuth.Test.Hosting {
private HttpHost httpHost;
public AspNetHost() {
- httpHost = HttpHost.CreateHost(this);
+ this.httpHost = HttpHost.CreateHost(this);
////if (!UntrustedWebRequestHandler.WhitelistHosts.Contains("localhost"))
//// UntrustedWebRequestHandler.WhitelistHosts.Add("localhost");
}
public Uri BaseUri {
- get { return httpHost.BaseUri; }
+ get { return this.httpHost.BaseUri; }
}
public static AspNetHost CreateHost(string webDirectory) {
@@ -38,11 +38,11 @@ namespace DotNetOpenAuth.Test.Hosting {
}
public string ProcessRequest(string url) {
- return httpHost.ProcessRequest(url);
+ return this.httpHost.ProcessRequest(url);
}
public string ProcessRequest(string url, string body) {
- return httpHost.ProcessRequest(url, body);
+ return this.httpHost.ProcessRequest(url, body);
}
public void BeginProcessRequest(HttpListenerContext context) {
@@ -61,7 +61,7 @@ namespace DotNetOpenAuth.Test.Hosting {
}
public void CloseHttp() {
- httpHost.Dispose();
+ this.httpHost.Dispose();
}
}
}
diff --git a/src/DotNetOpenAuth.Test/Hosting/HttpHost.cs b/src/DotNetOpenAuth.Test/Hosting/HttpHost.cs
index 06001ce..3ccd8bc 100644
--- a/src/DotNetOpenAuth.Test/Hosting/HttpHost.cs
+++ b/src/DotNetOpenAuth.Test/Hosting/HttpHost.cs
@@ -11,7 +11,7 @@ namespace DotNetOpenAuth.Test.Hosting {
using System.Net;
using System.Threading;
- class HttpHost : IDisposable {
+ internal class HttpHost : IDisposable {
private HttpListener listener;
private Thread listenerThread;
private AspNetHost aspNetHost;
@@ -33,12 +33,16 @@ namespace DotNetOpenAuth.Test.Hosting {
}
throw;
}
- this.listenerThread = new Thread(ProcessRequests);
+ this.listenerThread = new Thread(this.ProcessRequests);
this.listenerThread.Start();
}
public int Port { get; private set; }
+ public Uri BaseUri {
+ get { return new Uri("http://localhost:" + this.Port.ToString() + "/"); }
+ }
+
public static HttpHost CreateHost(AspNetHost aspNetHost) {
return new HttpHost(aspNetHost);
}
@@ -46,17 +50,13 @@ namespace DotNetOpenAuth.Test.Hosting {
public static HttpHost CreateHost(string webDirectory) {
return new HttpHost(AspNetHost.CreateHost(webDirectory));
}
-
- public Uri BaseUri {
- get { return new Uri("http://localhost:" + this.Port.ToString() + "/"); }
- }
-
+
public string ProcessRequest(string url) {
- return ProcessRequest(url, null);
+ return this.ProcessRequest(url, null);
}
-
+
public string ProcessRequest(string url, string body) {
- WebRequest request = WebRequest.Create(new Uri(BaseUri, url));
+ WebRequest request = WebRequest.Create(new Uri(this.BaseUri, url));
if (body != null) {
request.Method = "POST";
request.ContentLength = body.Length;
@@ -81,9 +81,9 @@ namespace DotNetOpenAuth.Test.Hosting {
#region IDisposable Members
public void Dispose() {
- listener.Close();
- listenerThread.Join(1000);
- listenerThread.Abort();
+ this.listener.Close();
+ this.listenerThread.Join(1000);
+ this.listenerThread.Abort();
}
#endregion
diff --git a/src/DotNetOpenAuth.Test/Hosting/TestingWorkerRequest.cs b/src/DotNetOpenAuth.Test/Hosting/TestingWorkerRequest.cs
index 6d1ee8d..d059c36 100644
--- a/src/DotNetOpenAuth.Test/Hosting/TestingWorkerRequest.cs
+++ b/src/DotNetOpenAuth.Test/Hosting/TestingWorkerRequest.cs
@@ -12,7 +12,9 @@ namespace DotNetOpenAuth.Test.Hosting {
internal class TestingWorkerRequest : SimpleWorkerRequest {
private Stream entityStream;
+
private HttpListenerContext context;
+
private TextWriter writer;
public TestingWorkerRequest(string page, string query, Stream entityStream, TextWriter writer)
@@ -20,6 +22,7 @@ namespace DotNetOpenAuth.Test.Hosting {
this.entityStream = entityStream;
this.writer = writer;
}
+
public TestingWorkerRequest(HttpListenerContext context, TextWriter output)
: base(context.Request.Url.LocalPath.TrimStart('/'), context.Request.Url.Query, output) {
this.entityStream = context.Request.InputStream;
@@ -29,66 +32,85 @@ namespace DotNetOpenAuth.Test.Hosting {
public override string GetFilePath() {
string filePath = this.context.Request.Url.LocalPath.Replace("/", "\\");
- if (filePath.EndsWith("\\", StringComparison.Ordinal))
+ if (filePath.EndsWith("\\", StringComparison.Ordinal)) {
filePath += "default.aspx";
+ }
return filePath;
}
+
public override int GetLocalPort() {
return this.context.Request.Url.Port;
}
+
public override string GetServerName() {
return this.context.Request.Url.Host;
}
+
public override string GetQueryString() {
return this.context.Request.Url.Query.TrimStart('?');
}
+
public override string GetHttpVerbName() {
return this.context.Request.HttpMethod;
}
+
public override string GetLocalAddress() {
return this.context.Request.LocalEndPoint.Address.ToString();
}
+
public override string GetHttpVersion() {
return "HTTP/1.1";
}
+
public override string GetProtocol() {
return this.context.Request.Url.Scheme;
}
+
public override string GetRawUrl() {
return this.context.Request.RawUrl;
}
+
public override int GetTotalEntityBodyLength() {
return (int)this.context.Request.ContentLength64;
}
+
public override string GetKnownRequestHeader(int index) {
return this.context.Request.Headers[GetKnownRequestHeaderName(index)];
}
+
public override string GetUnknownRequestHeader(string name) {
return this.context.Request.Headers[name];
}
+
public override bool IsEntireEntityBodyIsPreloaded() {
return false;
}
+
public override int ReadEntityBody(byte[] buffer, int size) {
return this.entityStream.Read(buffer, 0, size);
}
+
public override int ReadEntityBody(byte[] buffer, int offset, int size) {
return this.entityStream.Read(buffer, offset, size);
}
+
public override void SendCalculatedContentLength(int contentLength) {
this.context.Response.ContentLength64 = contentLength;
}
+
public override void SendStatus(int statusCode, string statusDescription) {
if (this.context != null) {
this.context.Response.StatusCode = statusCode;
this.context.Response.StatusDescription = statusDescription;
}
}
+
public override void SendKnownResponseHeader(int index, string value) {
if (this.context != null) {
this.context.Response.Headers[(HttpResponseHeader)index] = value;
}
}
+
public override void SendUnknownResponseHeader(string name, string value) {
if (this.context != null) {
this.context.Response.Headers[name] = value;