summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Test/Messaging
diff options
context:
space:
mode:
Diffstat (limited to 'src/DotNetOpenAuth.Test/Messaging')
-rw-r--r--src/DotNetOpenAuth.Test/Messaging/HttpRequestInfoTests.cs39
-rw-r--r--src/DotNetOpenAuth.Test/Messaging/MessagingTestBase.cs27
2 files changed, 15 insertions, 51 deletions
diff --git a/src/DotNetOpenAuth.Test/Messaging/HttpRequestInfoTests.cs b/src/DotNetOpenAuth.Test/Messaging/HttpRequestInfoTests.cs
index b2f2b14..fbe1d6b 100644
--- a/src/DotNetOpenAuth.Test/Messaging/HttpRequestInfoTests.cs
+++ b/src/DotNetOpenAuth.Test/Messaging/HttpRequestInfoTests.cs
@@ -13,25 +13,6 @@ namespace DotNetOpenAuth.Test.Messaging {
[TestFixture]
public class HttpRequestInfoTests : TestBase {
- [Test]
- public void CtorDefault() {
- HttpRequestInfo info = new HttpRequestInfo();
- Assert.AreEqual("GET", info.HttpMethod);
- }
-
- [Test]
- public void CtorRequest() {
- HttpRequest request = new HttpRequest("file", "http://someserver?a=b", "a=b");
- ////request.Headers["headername"] = "headervalue"; // PlatformNotSupportedException prevents us mocking this up
- HttpRequestInfo info = new HttpRequestInfo(request);
- Assert.AreEqual(request.Headers["headername"], info.Headers["headername"]);
- Assert.AreEqual(request.Url.Query, info.Query);
- Assert.AreEqual(request.QueryString["a"], info.QueryString["a"]);
- Assert.AreEqual(request.Url, info.Url);
- Assert.AreEqual(request.Url, info.UrlBeforeRewriting);
- Assert.AreEqual(request.HttpMethod, info.HttpMethod);
- }
-
// All these tests are ineffective because ServerVariables[] cannot be set.
////[Test]
////public void CtorRequestWithDifferentPublicHttpHost() {
@@ -77,21 +58,11 @@ namespace DotNetOpenAuth.Test.Messaging {
////}
/// <summary>
- /// Checks that a property dependent on another null property
- /// doesn't generate a NullReferenceException.
- /// </summary>
- [Test]
- public void QueryBeforeSettingUrl() {
- HttpRequestInfo info = new HttpRequestInfo();
- Assert.IsNull(info.Query);
- }
-
- /// <summary>
/// Verifies that looking up a querystring variable is gracefully handled without a query in the URL.
/// </summary>
[Test]
public void QueryStringLookupWithoutQuery() {
- HttpRequestInfo info = new HttpRequestInfo();
+ var info = new HttpRequestInfo("GET", new Uri("http://somehost/somepath"));
Assert.IsNull(info.QueryString["hi"]);
}
@@ -104,7 +75,7 @@ namespace DotNetOpenAuth.Test.Messaging {
var serverVariables = new NameValueCollection();
serverVariables["HTTP_X_FORWARDED_PROTO"] = "https";
serverVariables["HTTP_HOST"] = "somehost";
- Uri actual = HttpRequestInfo.GetPublicFacingUrl(req, serverVariables);
+ Uri actual = new HttpRequestWrapper(req).GetPublicFacingUrl(serverVariables);
Uri expected = new Uri("https://somehost/a.aspx?a=b");
Assert.AreEqual(expected, actual);
}
@@ -118,7 +89,7 @@ namespace DotNetOpenAuth.Test.Messaging {
var serverVariables = new NameValueCollection();
serverVariables["HTTP_X_FORWARDED_PROTO"] = "https";
serverVariables["HTTP_HOST"] = "somehost:999";
- Uri actual = HttpRequestInfo.GetPublicFacingUrl(req, serverVariables);
+ Uri actual = new HttpRequestWrapper(req).GetPublicFacingUrl(serverVariables);
Uri expected = new Uri("https://somehost:999/a.aspx?a=b");
Assert.AreEqual(expected, actual);
}
@@ -131,7 +102,7 @@ namespace DotNetOpenAuth.Test.Messaging {
HttpRequest req = new HttpRequest("a.aspx", "http://someinternalhost/a.aspx?a=b", "a=b");
var serverVariables = new NameValueCollection();
serverVariables["HTTP_HOST"] = "somehost";
- Uri actual = HttpRequestInfo.GetPublicFacingUrl(req, serverVariables);
+ Uri actual = new HttpRequestWrapper(req).GetPublicFacingUrl(serverVariables);
Uri expected = new Uri("http://somehost/a.aspx?a=b");
Assert.AreEqual(expected, actual);
}
@@ -144,7 +115,7 @@ namespace DotNetOpenAuth.Test.Messaging {
HttpRequest req = new HttpRequest("a.aspx", "http://someinternalhost/a.aspx?a=b", "a=b");
var serverVariables = new NameValueCollection();
serverVariables["HTTP_HOST"] = "somehost:79";
- Uri actual = HttpRequestInfo.GetPublicFacingUrl(req, serverVariables);
+ Uri actual = new HttpRequestWrapper(req).GetPublicFacingUrl(serverVariables);
Uri expected = new Uri("http://somehost:79/a.aspx?a=b");
Assert.AreEqual(expected, actual);
}
diff --git a/src/DotNetOpenAuth.Test/Messaging/MessagingTestBase.cs b/src/DotNetOpenAuth.Test/Messaging/MessagingTestBase.cs
index e3700b8..b7c0980 100644
--- a/src/DotNetOpenAuth.Test/Messaging/MessagingTestBase.cs
+++ b/src/DotNetOpenAuth.Test/Messaging/MessagingTestBase.cs
@@ -7,6 +7,7 @@
namespace DotNetOpenAuth.Test {
using System;
using System.Collections.Generic;
+ using System.Collections.Specialized;
using System.IO;
using System.Net;
using System.Xml;
@@ -19,6 +20,8 @@ namespace DotNetOpenAuth.Test {
/// The base class that all messaging test classes inherit from.
/// </summary>
public class MessagingTestBase : TestBase {
+ protected internal const string DefaultUrlForHttpRequestInfo = "http://localhost/path";
+
internal enum FieldFill {
/// <summary>
/// An empty dictionary is returned.
@@ -53,29 +56,19 @@ namespace DotNetOpenAuth.Test {
}
internal static HttpRequestInfo CreateHttpRequestInfo(string method, IDictionary<string, string> fields) {
- string query = MessagingUtilities.CreateQueryString(fields);
- UriBuilder requestUri = new UriBuilder("http://localhost/path");
- WebHeaderCollection headers = new WebHeaderCollection();
- MemoryStream ms = new MemoryStream();
+ var requestUri = new UriBuilder(DefaultUrlForHttpRequestInfo);
+ var headers = new NameValueCollection();
+ NameValueCollection form = null;
if (method == "POST") {
- headers.Add(HttpRequestHeader.ContentType, "application/x-www-form-urlencoded");
- StreamWriter sw = new StreamWriter(ms);
- sw.Write(query);
- sw.Flush();
- ms.Position = 0;
+ form = fields.ToNameValueCollection();
+ headers.Add(HttpRequestHeaders.ContentType, Channel.HttpFormUrlEncoded);
} else if (method == "GET") {
- requestUri.Query = query;
+ requestUri.Query = MessagingUtilities.CreateQueryString(fields);
} else {
throw new ArgumentOutOfRangeException("method", method, "Expected POST or GET");
}
- HttpRequestInfo request = new HttpRequestInfo {
- HttpMethod = method,
- UrlBeforeRewriting = requestUri.Uri,
- Headers = headers,
- InputStream = ms,
- };
- return request;
+ return new HttpRequestInfo(method, requestUri.Uri, form: form, headers: headers);
}
internal static Channel CreateChannel(MessageProtections capabilityAndRecognition) {