summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/DotNetOAuth.Test/Messaging/ChannelTests.cs60
-rw-r--r--src/DotNetOAuth.Test/OAuthChannelTests.cs33
-rw-r--r--src/DotNetOAuth/Protocol.cs2
3 files changed, 54 insertions, 41 deletions
diff --git a/src/DotNetOAuth.Test/Messaging/ChannelTests.cs b/src/DotNetOAuth.Test/Messaging/ChannelTests.cs
index b4eb810..3282788 100644
--- a/src/DotNetOAuth.Test/Messaging/ChannelTests.cs
+++ b/src/DotNetOAuth.Test/Messaging/ChannelTests.cs
@@ -37,48 +37,13 @@ namespace DotNetOAuth.Test.Messaging {
}
[TestMethod]
- public void ReceiveFromQueryString() {
- Uri requestUri = new Uri("http://localhost/path?age=15&Name=Andrew&Location=http%3A%2F%2Fhostb%2FpathB");
- WebHeaderCollection headers = new WebHeaderCollection();
- HttpRequestInfo request = new HttpRequestInfo {
- HttpMethod = "GET",
- Url = requestUri,
- Headers = headers,
- InputStream = new MemoryStream(),
- };
- IProtocolMessage requestMessage = this.channel.ReadFromRequest(request);
- Assert.IsNotNull(requestMessage);
- Assert.IsInstanceOfType(requestMessage, typeof(TestMessage));
- TestMessage testMessage = (TestMessage)requestMessage;
- Assert.AreEqual(15, testMessage.Age);
- Assert.AreEqual("Andrew", testMessage.Name);
- Assert.AreEqual("http://hostb/pathB", testMessage.Location.AbsoluteUri);
+ public void ReadFromRequestQueryString() {
+ ParameterizedReceiveTest("GET");
}
[TestMethod]
- public void ReceiveFromForm() {
- Uri requestUri = new Uri("http://localhost/path");
- WebHeaderCollection headers = new WebHeaderCollection();
- headers.Add(HttpRequestHeader.ContentType, "application/x-www-form-urlencoded");
- MemoryStream ms = new MemoryStream();
- StreamWriter sw = new StreamWriter(ms);
- sw.Write("age=15&Name=Andrew&Location=http%3A%2F%2Fhostb%2FpathB");
- sw.Flush();
- ms.Position = 0;
- HttpRequestInfo request = new HttpRequestInfo {
- HttpMethod = "POST",
- Url = requestUri,
- Headers = headers,
- InputStream = ms,
- };
-
- IProtocolMessage requestMessage = this.channel.ReadFromRequest(request);
- Assert.IsNotNull(requestMessage);
- Assert.IsInstanceOfType(requestMessage, typeof(TestMessage));
- TestMessage testMessage = (TestMessage)requestMessage;
- Assert.AreEqual(15, testMessage.Age);
- Assert.AreEqual("Andrew", testMessage.Name);
- Assert.AreEqual("http://hostb/pathB", testMessage.Location.AbsoluteUri);
+ public void ReadFromRequestForm() {
+ ParameterizedReceiveTest("POST");
}
private static HttpRequestInfo CreateHttpRequest(string method, IDictionary<string, string> fields) {
@@ -94,6 +59,8 @@ namespace DotNetOAuth.Test.Messaging {
ms.Position = 0;
} else if (method == "GET") {
requestUri.Query = query;
+ } else {
+ throw new ArgumentOutOfRangeException("method", method, "Expected POST or GET");
}
HttpRequestInfo request = new HttpRequestInfo {
HttpMethod = method,
@@ -104,5 +71,20 @@ namespace DotNetOAuth.Test.Messaging {
return request;
}
+
+ private void ParameterizedReceiveTest(string method) {
+ var fields = new Dictionary<string, string> {
+ { "age", "15" },
+ { "Name", "Andrew" },
+ { "Location", "http://hostb/pathB" },
+ };
+ IProtocolMessage requestMessage = this.channel.ReadFromRequest(CreateHttpRequest(method, fields));
+ Assert.IsNotNull(requestMessage);
+ Assert.IsInstanceOfType(requestMessage, typeof(TestMessage));
+ TestMessage testMessage = (TestMessage)requestMessage;
+ Assert.AreEqual(15, testMessage.Age);
+ Assert.AreEqual("Andrew", testMessage.Name);
+ Assert.AreEqual("http://hostb/pathB", testMessage.Location.AbsoluteUri);
+ }
}
}
diff --git a/src/DotNetOAuth.Test/OAuthChannelTests.cs b/src/DotNetOAuth.Test/OAuthChannelTests.cs
index 1e41832..1099dc6 100644
--- a/src/DotNetOAuth.Test/OAuthChannelTests.cs
+++ b/src/DotNetOAuth.Test/OAuthChannelTests.cs
@@ -7,12 +7,43 @@
namespace DotNetOAuth.Test {
using System;
using System.Collections.Generic;
- using System.Linq;
using System.Text;
using DotNetOAuth.Messaging;
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public class OAuthChannelTests : TestBase {
+ private Channel channel;
+
+ [TestInitialize]
+ public override void SetUp() {
+ base.SetUp();
+
+ this.channel = new OAuthChannel();
+ }
+
+ [TestMethod, Ignore]
+ public void ReadFromRequestAuthorization() {
+ }
+
+ internal static string CreateAuthorizationHeader(IDictionary<string, string> fields) {
+ if (fields == null) {
+ throw new ArgumentNullException("fields");
+ }
+
+ StringBuilder authorization = new StringBuilder();
+ authorization.Append("OAuth ");
+ foreach (var pair in fields) {
+ string key = Uri.EscapeDataString(pair.Key);
+ string value = Uri.EscapeDataString(pair.Value);
+ authorization.Append(key);
+ authorization.Append("=\"");
+ authorization.Append(value);
+ authorization.Append("\",");
+ }
+ authorization.Length--; // remove trailing comma
+
+ return authorization.ToString();
+ }
}
}
diff --git a/src/DotNetOAuth/Protocol.cs b/src/DotNetOAuth/Protocol.cs
index db26a9f..be76e2a 100644
--- a/src/DotNetOAuth/Protocol.cs
+++ b/src/DotNetOAuth/Protocol.cs
@@ -22,7 +22,7 @@ namespace DotNetOAuth {
/// <summary>
/// Gets the default <see cref="Protocol"/> instance.
/// </summary>
- internal static readonly Protocol Default = V10;
+ internal static Protocol Default { get { return V10; } }
/// <summary>
/// The namespace to use for V1.0 of the protocol.