summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Test/Messaging/MessagingTestBase.cs
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2013-03-26 11:19:06 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2013-03-26 11:19:06 -0700
commit3d37ff45cab6838d80b22e6b782a0b9b4c2f4aeb (patch)
treec15816c3d7f6e74334553f2ff98605ce1c22c538 /src/DotNetOpenAuth.Test/Messaging/MessagingTestBase.cs
parent5e9014f36b2d53b8e419918675df636540ea24e2 (diff)
parente6f7409f4caceb7bc2a5b4ddbcb1a4097af340f2 (diff)
downloadDotNetOpenAuth-3d37ff45cab6838d80b22e6b782a0b9b4c2f4aeb.zip
DotNetOpenAuth-3d37ff45cab6838d80b22e6b782a0b9b4c2f4aeb.tar.gz
DotNetOpenAuth-3d37ff45cab6838d80b22e6b782a0b9b4c2f4aeb.tar.bz2
Move to HttpClient throughout library.
Diffstat (limited to 'src/DotNetOpenAuth.Test/Messaging/MessagingTestBase.cs')
-rw-r--r--src/DotNetOpenAuth.Test/Messaging/MessagingTestBase.cs38
1 files changed, 20 insertions, 18 deletions
diff --git a/src/DotNetOpenAuth.Test/Messaging/MessagingTestBase.cs b/src/DotNetOpenAuth.Test/Messaging/MessagingTestBase.cs
index b7c0980..7903e89 100644
--- a/src/DotNetOpenAuth.Test/Messaging/MessagingTestBase.cs
+++ b/src/DotNetOpenAuth.Test/Messaging/MessagingTestBase.cs
@@ -10,6 +10,9 @@ namespace DotNetOpenAuth.Test {
using System.Collections.Specialized;
using System.IO;
using System.Net;
+ using System.Net.Http;
+ using System.Threading;
+ using System.Threading.Tasks;
using System.Xml;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.Messaging.Bindings;
@@ -52,30 +55,29 @@ namespace DotNetOpenAuth.Test {
public override void SetUp() {
base.SetUp();
- this.Channel = new TestChannel();
+ this.Channel = new TestChannel(this.HostFactories);
}
- internal static HttpRequestInfo CreateHttpRequestInfo(string method, IDictionary<string, string> fields) {
+ internal static HttpRequestMessage CreateHttpRequestInfo(HttpMethod method, IDictionary<string, string> fields) {
+ var result = new HttpRequestMessage() { Method = method };
var requestUri = new UriBuilder(DefaultUrlForHttpRequestInfo);
- var headers = new NameValueCollection();
- NameValueCollection form = null;
- if (method == "POST") {
- form = fields.ToNameValueCollection();
- headers.Add(HttpRequestHeaders.ContentType, Channel.HttpFormUrlEncoded);
- } else if (method == "GET") {
- requestUri.Query = MessagingUtilities.CreateQueryString(fields);
+ if (method == HttpMethod.Post) {
+ result.Content = new FormUrlEncodedContent(fields);
+ } else if (method == HttpMethod.Get) {
+ requestUri.AppendQueryArgs(fields);
} else {
throw new ArgumentOutOfRangeException("method", method, "Expected POST or GET");
}
- return new HttpRequestInfo(method, requestUri.Uri, form: form, headers: headers);
+ result.RequestUri = requestUri.Uri;
+ return result;
}
- internal static Channel CreateChannel(MessageProtections capabilityAndRecognition) {
- return CreateChannel(capabilityAndRecognition, capabilityAndRecognition);
+ internal Channel CreateChannel(MessageProtections capabilityAndRecognition) {
+ return this.CreateChannel(capabilityAndRecognition, capabilityAndRecognition);
}
- internal static Channel CreateChannel(MessageProtections capability, MessageProtections recognition) {
+ internal Channel CreateChannel(MessageProtections capability, MessageProtections recognition) {
var bindingElements = new List<IChannelBindingElement>();
if (capability >= MessageProtections.TamperProtection) {
bindingElements.Add(new MockSigningBindingElement());
@@ -99,7 +101,7 @@ namespace DotNetOpenAuth.Test {
}
var typeProvider = new TestMessageFactory(signing, expiration, replay);
- return new TestChannel(typeProvider, bindingElements.ToArray());
+ return new TestChannel(typeProvider, bindingElements.ToArray(), this.HostFactories);
}
internal static IDictionary<string, string> GetStandardTestFields(FieldFill fill) {
@@ -143,11 +145,11 @@ namespace DotNetOpenAuth.Test {
}
}
- internal void ParameterizedReceiveTest(string method) {
+ internal async Task ParameterizedReceiveTestAsync(HttpMethod method) {
var fields = GetStandardTestFields(FieldFill.CompleteBeforeBindings);
TestMessage expectedMessage = GetStandardTestMessage(FieldFill.CompleteBeforeBindings);
- IDirectedProtocolMessage requestMessage = this.Channel.ReadFromRequest(CreateHttpRequestInfo(method, fields));
+ IDirectedProtocolMessage requestMessage = await this.Channel.ReadFromRequestAsync(CreateHttpRequestInfo(method, fields), CancellationToken.None);
Assert.IsNotNull(requestMessage);
Assert.IsInstanceOf<TestMessage>(requestMessage);
TestMessage actualMessage = (TestMessage)requestMessage;
@@ -156,7 +158,7 @@ namespace DotNetOpenAuth.Test {
Assert.AreEqual(expectedMessage.Location, actualMessage.Location);
}
- internal void ParameterizedReceiveProtectedTest(DateTime? utcCreatedDate, bool invalidSignature) {
+ internal async Task ParameterizedReceiveProtectedTestAsync(DateTime? utcCreatedDate, bool invalidSignature) {
TestMessage expectedMessage = GetStandardTestMessage(FieldFill.CompleteBeforeBindings);
var fields = GetStandardTestFields(FieldFill.CompleteBeforeBindings);
fields.Add("Signature", invalidSignature ? "badsig" : MockSigningBindingElement.MessageSignature);
@@ -165,7 +167,7 @@ namespace DotNetOpenAuth.Test {
utcCreatedDate = DateTime.Parse(utcCreatedDate.Value.ToUniversalTime().ToString()); // round off the milliseconds so comparisons work later
fields.Add("created_on", XmlConvert.ToString(utcCreatedDate.Value, XmlDateTimeSerializationMode.Utc));
}
- IProtocolMessage requestMessage = this.Channel.ReadFromRequest(CreateHttpRequestInfo("GET", fields));
+ IProtocolMessage requestMessage = await this.Channel.ReadFromRequestAsync(CreateHttpRequestInfo(HttpMethod.Get, fields), CancellationToken.None);
Assert.IsNotNull(requestMessage);
Assert.IsInstanceOf<TestSignedDirectedMessage>(requestMessage);
TestSignedDirectedMessage actualMessage = (TestSignedDirectedMessage)requestMessage;