summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Test/Mocks/CoordinatingHttpRequestInfo.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/DotNetOpenAuth.Test/Mocks/CoordinatingHttpRequestInfo.cs')
-rw-r--r--src/DotNetOpenAuth.Test/Mocks/CoordinatingHttpRequestInfo.cs75
1 files changed, 53 insertions, 22 deletions
diff --git a/src/DotNetOpenAuth.Test/Mocks/CoordinatingHttpRequestInfo.cs b/src/DotNetOpenAuth.Test/Mocks/CoordinatingHttpRequestInfo.cs
index bfb9017..9f139f3 100644
--- a/src/DotNetOpenAuth.Test/Mocks/CoordinatingHttpRequestInfo.cs
+++ b/src/DotNetOpenAuth.Test/Mocks/CoordinatingHttpRequestInfo.cs
@@ -5,15 +5,21 @@
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.Test.Mocks {
+ using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using DotNetOpenAuth.Messaging;
internal class CoordinatingHttpRequestInfo : HttpRequestInfo {
- private IDictionary<string, string> messageData;
- private IMessageFactory messageFactory;
- private MessageReceivingEndpoint recipient;
- private Channel channel;
+ private readonly Channel channel;
+
+ private readonly IDictionary<string, string> messageData;
+
+ private readonly IMessageFactory messageFactory;
+
+ private readonly MessageReceivingEndpoint recipient;
+
+ private IDirectedProtocolMessage message;
/// <summary>
/// Initializes a new instance of the <see cref="CoordinatingHttpRequestInfo"/> class
@@ -23,14 +29,18 @@ namespace DotNetOpenAuth.Test.Mocks {
/// <param name="messageFactory">The message factory.</param>
/// <param name="messageData">The message data.</param>
/// <param name="recipient">The recipient.</param>
- internal CoordinatingHttpRequestInfo(Channel channel, IMessageFactory messageFactory, IDictionary<string, string> messageData, MessageReceivingEndpoint recipient)
+ internal CoordinatingHttpRequestInfo(
+ Channel channel,
+ IMessageFactory messageFactory,
+ IDictionary<string, string> messageData,
+ MessageReceivingEndpoint recipient)
: this(recipient) {
Contract.Requires(channel != null);
Contract.Requires(messageFactory != null);
Contract.Requires(messageData != null);
this.channel = channel;
- this.messageFactory = messageFactory;
this.messageData = messageData;
+ this.messageFactory = messageFactory;
}
/// <summary>
@@ -38,35 +48,56 @@ namespace DotNetOpenAuth.Test.Mocks {
/// that will not generate any message.
/// </summary>
/// <param name="recipient">The recipient.</param>
- internal CoordinatingHttpRequestInfo(MessageReceivingEndpoint recipient) {
+ internal CoordinatingHttpRequestInfo(MessageReceivingEndpoint recipient)
+ : base(GetHttpVerb(recipient), recipient != null ? recipient.Location : new Uri("http://host/path")) {
this.recipient = recipient;
- if (recipient != null) {
- this.UrlBeforeRewriting = recipient.Location;
- }
+ }
- if (recipient == null || (recipient.AllowedMethods & HttpDeliveryMethods.GetRequest) != 0) {
- this.HttpMethod = "GET";
- } else if ((recipient.AllowedMethods & HttpDeliveryMethods.PostRequest) != 0) {
- this.HttpMethod = "POST";
- }
+ /// <summary>
+ /// Initializes a new instance of the <see cref="CoordinatingHttpRequestInfo"/> class.
+ /// </summary>
+ /// <param name="message">The message being passed in through a mock transport. May be null.</param>
+ /// <param name="httpMethod">The HTTP method that the incoming request came in on, whether or not <paramref name="message"/> is null.</param>
+ internal CoordinatingHttpRequestInfo(IDirectedProtocolMessage message, HttpDeliveryMethods httpMethod)
+ : base(GetHttpVerb(httpMethod), message.Recipient) {
+ this.message = message;
}
- internal override IDirectedProtocolMessage Message {
+ /// <summary>
+ /// Gets the message deserialized from the remote channel.
+ /// </summary>
+ internal IDirectedProtocolMessage Message {
get {
- if (base.Message == null && this.messageData != null) {
- IDirectedProtocolMessage message = this.messageFactory.GetNewRequestMessage(this.recipient, this.messageData);
+ if (this.message == null && this.messageData != null) {
+ var message = this.messageFactory.GetNewRequestMessage(this.recipient, this.messageData);
if (message != null) {
this.channel.MessageDescriptions.GetAccessor(message).Deserialize(this.messageData);
+ this.message = message;
}
- base.Message = message;
}
- return base.Message;
+ return this.message;
+ }
+ }
+
+ private static string GetHttpVerb(MessageReceivingEndpoint recipient) {
+ if (recipient == null) {
+ return "GET";
}
- set {
- base.Message = value;
+ return GetHttpVerb(recipient.AllowedMethods);
+ }
+
+ private static string GetHttpVerb(HttpDeliveryMethods httpMethod) {
+ if ((httpMethod & HttpDeliveryMethods.GetRequest) != 0) {
+ return "GET";
}
+
+ if ((httpMethod & HttpDeliveryMethods.PostRequest) != 0) {
+ return "POST";
+ }
+
+ throw new ArgumentOutOfRangeException();
}
}
}