diff options
Diffstat (limited to 'src/DotNetOAuth.Test/Messaging/ChannelTests.cs')
-rw-r--r-- | src/DotNetOAuth.Test/Messaging/ChannelTests.cs | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/src/DotNetOAuth.Test/Messaging/ChannelTests.cs b/src/DotNetOAuth.Test/Messaging/ChannelTests.cs index 5ffd1d6..e8c4514 100644 --- a/src/DotNetOAuth.Test/Messaging/ChannelTests.cs +++ b/src/DotNetOAuth.Test/Messaging/ChannelTests.cs @@ -14,6 +14,7 @@ namespace DotNetOAuth.Test.Messaging { using DotNetOAuth.Messaging.Bindings;
using DotNetOAuth.Test.Mocks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
+ using System.Xml;
[TestClass]
public class ChannelTests : MessagingTestBase {
@@ -64,19 +65,21 @@ namespace DotNetOAuth.Test.Messaging { [TestMethod]
public void SendIndirectMessage301Get() {
- IProtocolMessage message = new TestDirectedMessage(MessageTransport.Indirect) {
- Age = 15,
- Name = "Andrew",
- Location = new Uri("http://host/path"),
- Recipient = new Uri("http://provider/path"),
- };
+ TestDirectedMessage message = new TestDirectedMessage(MessageTransport.Indirect);
+ GetStandardTestMessage(FieldFill.CompleteBeforeBindings, message);
+ message.Recipient = new Uri("http://provider/path");
+ var expected = GetStandardTestFields(FieldFill.CompleteBeforeBindings);
+
this.Channel.Send(message);
Response response = this.Channel.DequeueIndirectOrResponseMessage();
Assert.AreEqual(HttpStatusCode.Redirect, response.Status);
StringAssert.StartsWith(response.Headers[HttpResponseHeader.Location], "http://provider/path");
- StringAssert.Contains(response.Headers[HttpResponseHeader.Location], "age=15");
- StringAssert.Contains(response.Headers[HttpResponseHeader.Location], "Name=Andrew");
- StringAssert.Contains(response.Headers[HttpResponseHeader.Location], "Location=http%3a%2f%2fhost%2fpath");
+ foreach (var pair in expected) {
+ string key = HttpUtility.UrlEncode(pair.Key);
+ string value = HttpUtility.UrlEncode(pair.Value);
+ string substring = string.Format("{0}={1}", key, value);
+ StringAssert.Contains(response.Headers[HttpResponseHeader.Location], substring);
+ }
}
[TestMethod, ExpectedException(typeof(ArgumentNullException))]
@@ -198,12 +201,14 @@ namespace DotNetOAuth.Test.Messaging { [TestMethod]
public void ReadFromRequestWithContext() {
// TODO: make this a request with a message in it.
- HttpRequest request = new HttpRequest("somefile", "http://someurl", "age=15");
+ var fields = GetStandardTestFields(FieldFill.AllRequired);
+ TestMessage expectedMessage = GetStandardTestMessage(FieldFill.AllRequired);
+ HttpRequest request = new HttpRequest("somefile", "http://someurl", MessagingUtilities.CreateQueryString(fields));
HttpContext.Current = new HttpContext(request, new HttpResponse(new StringWriter()));
IProtocolMessage message = this.Channel.ReadFromRequest();
Assert.IsNotNull(message);
Assert.IsInstanceOfType(message, typeof(TestMessage));
- Assert.AreEqual(15, ((TestMessage)message).Age);
+ Assert.AreEqual(expectedMessage.Age, ((TestMessage)message).Age);
}
[TestMethod, ExpectedException(typeof(InvalidOperationException))]
@@ -298,5 +303,11 @@ namespace DotNetOAuth.Test.Messaging { this.Channel = CreateChannel(MessageProtection.None, MessageProtection.TamperProtection);
this.ParameterizedReceiveProtectedTest(DateTime.Now, false);
}
+
+ [TestMethod, ExpectedException(typeof(ProtocolException))]
+ public void IncomingMessageMissingRequiredParameters() {
+ var fields = GetStandardTestFields(FieldFill.IdentifiableButNotAllRequired);
+ this.Channel.ReadFromRequest(CreateHttpRequestInfo("GET", fields));
+ }
}
}
|