summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Test/Mocks
diff options
context:
space:
mode:
Diffstat (limited to 'src/DotNetOpenAuth.Test/Mocks')
-rw-r--r--src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs13
-rw-r--r--src/DotNetOpenAuth.Test/Mocks/CoordinatingHttpRequestInfo.cs75
-rw-r--r--src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthConsumerChannel.cs28
-rw-r--r--src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthServiceProviderChannel.cs42
-rw-r--r--src/DotNetOpenAuth.Test/Mocks/TestBadChannel.cs3
5 files changed, 97 insertions, 64 deletions
diff --git a/src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs b/src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs
index 8d5295b..10bd59a 100644
--- a/src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs
+++ b/src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs
@@ -11,6 +11,8 @@ namespace DotNetOpenAuth.Test.Mocks {
using System.Linq;
using System.Text;
using System.Threading;
+ using System.Web;
+
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.Messaging.Reflection;
using DotNetOpenAuth.Test.OpenId;
@@ -146,7 +148,7 @@ namespace DotNetOpenAuth.Test.Mocks {
this.incomingMessageSignal.Set();
}
- protected internal override HttpRequestInfo GetRequestFromContext() {
+ protected internal override HttpRequestBase GetRequestFromContext() {
MessageReceivingEndpoint recipient;
var messageData = this.AwaitIncomingMessage(out recipient);
if (messageData != null) {
@@ -191,12 +193,13 @@ namespace DotNetOpenAuth.Test.Mocks {
return this.PrepareDirectResponse(message);
}
- protected override IDirectedProtocolMessage ReadFromRequestCore(HttpRequestInfo request) {
- if (request.Message != null) {
- this.ProcessMessageFilter(request.Message, false);
+ protected override IDirectedProtocolMessage ReadFromRequestCore(HttpRequestBase request) {
+ var mockRequest = (CoordinatingHttpRequestInfo)request;
+ if (mockRequest.Message != null) {
+ this.ProcessMessageFilter(mockRequest.Message, false);
}
- return request.Message;
+ return mockRequest.Message;
}
protected override IDictionary<string, string> ReadFromResponseCore(IncomingWebResponse response) {
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();
}
}
}
diff --git a/src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthConsumerChannel.cs b/src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthConsumerChannel.cs
index 6cc5819..e145952 100644
--- a/src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthConsumerChannel.cs
+++ b/src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthConsumerChannel.cs
@@ -8,6 +8,8 @@ namespace DotNetOpenAuth.Test.Mocks {
using System;
using System.Diagnostics.Contracts;
using System.Threading;
+ using System.Web;
+
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.Messaging.Bindings;
using DotNetOpenAuth.OAuth.ChannelElements;
@@ -49,7 +51,7 @@ namespace DotNetOpenAuth.Test.Mocks {
internal OutgoingWebResponse RequestProtectedResource(AccessProtectedResourceRequest request) {
((ITamperResistantOAuthMessage)request).HttpMethod = this.GetHttpMethod(((ITamperResistantOAuthMessage)request).HttpMethods);
this.ProcessOutgoingMessage(request);
- HttpRequestInfo requestInfo = this.SpoofHttpMethod(request);
+ var requestInfo = this.SpoofHttpMethod(request);
TestBase.TestLogger.InfoFormat("Sending protected resource request: {0}", requestInfo.Message);
// Drop the outgoing message in the other channel's in-slot and let them know it's there.
this.RemoteChannel.IncomingMessage = requestInfo.Message;
@@ -57,13 +59,13 @@ namespace DotNetOpenAuth.Test.Mocks {
return this.AwaitIncomingRawResponse();
}
- protected internal override HttpRequestInfo GetRequestFromContext() {
+ protected internal override HttpRequestBase GetRequestFromContext() {
var directedMessage = (IDirectedProtocolMessage)this.AwaitIncomingMessage();
- return new HttpRequestInfo(directedMessage, directedMessage.HttpMethods);
+ return new CoordinatingHttpRequestInfo(directedMessage, directedMessage.HttpMethods);
}
protected override IProtocolMessage RequestCore(IDirectedProtocolMessage request) {
- HttpRequestInfo requestInfo = this.SpoofHttpMethod(request);
+ var requestInfo = this.SpoofHttpMethod(request);
// Drop the outgoing message in the other channel's in-slot and let them know it's there.
this.RemoteChannel.IncomingMessage = requestInfo.Message;
this.RemoteChannel.IncomingMessageSignal.Set();
@@ -72,7 +74,7 @@ namespace DotNetOpenAuth.Test.Mocks {
}
protected override OutgoingWebResponse PrepareDirectResponse(IProtocolMessage response) {
- this.RemoteChannel.IncomingMessage = CloneSerializedParts(response, null);
+ this.RemoteChannel.IncomingMessage = this.CloneSerializedParts(response);
this.RemoteChannel.IncomingMessageSignal.Set();
return new OutgoingWebResponse(); // not used, but returning null is not allowed
}
@@ -82,8 +84,9 @@ namespace DotNetOpenAuth.Test.Mocks {
return this.PrepareDirectResponse(message);
}
- protected override IDirectedProtocolMessage ReadFromRequestCore(HttpRequestInfo request) {
- return request.Message;
+ protected override IDirectedProtocolMessage ReadFromRequestCore(HttpRequestBase request) {
+ var mockRequest = (CoordinatingHttpRequestInfo)request;
+ return mockRequest.Message;
}
/// <summary>
@@ -91,19 +94,14 @@ namespace DotNetOpenAuth.Test.Mocks {
/// </summary>
/// <param name="message">The message to add a pretend HTTP method to.</param>
/// <returns>A spoofed HttpRequestInfo that wraps the new message.</returns>
- private HttpRequestInfo SpoofHttpMethod(IDirectedProtocolMessage message) {
- HttpRequestInfo requestInfo = new HttpRequestInfo(message, message.HttpMethods);
-
+ private CoordinatingHttpRequestInfo SpoofHttpMethod(IDirectedProtocolMessage message) {
var signedMessage = message as ITamperResistantOAuthMessage;
if (signedMessage != null) {
string httpMethod = this.GetHttpMethod(signedMessage.HttpMethods);
- requestInfo.HttpMethod = httpMethod;
- requestInfo.UrlBeforeRewriting = message.Recipient;
signedMessage.HttpMethod = httpMethod;
}
- requestInfo.Message = this.CloneSerializedParts(message, requestInfo);
-
+ var requestInfo = new CoordinatingHttpRequestInfo(this.CloneSerializedParts(message), message.HttpMethods);
return requestInfo;
}
@@ -121,7 +119,7 @@ namespace DotNetOpenAuth.Test.Mocks {
return response;
}
- private T CloneSerializedParts<T>(T message, HttpRequestInfo requestInfo) where T : class, IProtocolMessage {
+ private T CloneSerializedParts<T>(T message) where T : class, IProtocolMessage {
Requires.NotNull(message, "message");
IProtocolMessage clonedMessage;
diff --git a/src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthServiceProviderChannel.cs b/src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthServiceProviderChannel.cs
index ad5c695..012173c 100644
--- a/src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthServiceProviderChannel.cs
+++ b/src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthServiceProviderChannel.cs
@@ -8,10 +8,13 @@ namespace DotNetOpenAuth.Test.Mocks {
using System;
using System.Diagnostics.Contracts;
using System.Threading;
+ using System.Web;
+
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.Messaging.Bindings;
using DotNetOpenAuth.OAuth.ChannelElements;
using DotNetOpenAuth.OAuth.Messages;
+ using NUnit.Framework;
/// <summary>
/// A special channel used in test simulations to pass messages directly between two parties.
@@ -48,9 +51,9 @@ namespace DotNetOpenAuth.Test.Mocks {
internal CoordinatingOAuthConsumerChannel RemoteChannel { get; set; }
internal OutgoingWebResponse RequestProtectedResource(AccessProtectedResourceRequest request) {
- ((ITamperResistantOAuthMessage)request).HttpMethod = this.GetHttpMethod(((ITamperResistantOAuthMessage)request).HttpMethods);
+ ((ITamperResistantOAuthMessage)request).HttpMethod = GetHttpMethod(((ITamperResistantOAuthMessage)request).HttpMethods);
this.ProcessOutgoingMessage(request);
- HttpRequestInfo requestInfo = this.SpoofHttpMethod(request);
+ var requestInfo = this.SpoofHttpMethod(request);
TestBase.TestLogger.InfoFormat("Sending protected resource request: {0}", requestInfo.Message);
// Drop the outgoing message in the other channel's in-slot and let them know it's there.
this.RemoteChannel.IncomingMessage = requestInfo.Message;
@@ -63,13 +66,13 @@ namespace DotNetOpenAuth.Test.Mocks {
this.RemoteChannel.IncomingMessageSignal.Set();
}
- protected internal override HttpRequestInfo GetRequestFromContext() {
+ protected internal override HttpRequestBase GetRequestFromContext() {
var directedMessage = (IDirectedProtocolMessage)this.AwaitIncomingMessage();
- return new HttpRequestInfo(directedMessage, directedMessage.HttpMethods);
+ return new CoordinatingHttpRequestInfo(directedMessage, directedMessage.HttpMethods);
}
protected override IProtocolMessage RequestCore(IDirectedProtocolMessage request) {
- HttpRequestInfo requestInfo = this.SpoofHttpMethod(request);
+ var requestInfo = this.SpoofHttpMethod(request);
// Drop the outgoing message in the other channel's in-slot and let them know it's there.
this.RemoteChannel.IncomingMessage = requestInfo.Message;
this.RemoteChannel.IncomingMessageSignal.Set();
@@ -78,7 +81,7 @@ namespace DotNetOpenAuth.Test.Mocks {
}
protected override OutgoingWebResponse PrepareDirectResponse(IProtocolMessage response) {
- this.RemoteChannel.IncomingMessage = CloneSerializedParts(response, null);
+ this.RemoteChannel.IncomingMessage = this.CloneSerializedParts(response);
this.RemoteChannel.IncomingMessageSignal.Set();
return new OutgoingWebResponse(); // not used, but returning null is not allowed
}
@@ -88,8 +91,13 @@ namespace DotNetOpenAuth.Test.Mocks {
return this.PrepareDirectResponse(message);
}
- protected override IDirectedProtocolMessage ReadFromRequestCore(HttpRequestInfo request) {
- return request.Message;
+ protected override IDirectedProtocolMessage ReadFromRequestCore(HttpRequestBase request) {
+ var mockRequest = (CoordinatingHttpRequestInfo)request;
+ return mockRequest.Message;
+ }
+
+ private static string GetHttpMethod(HttpDeliveryMethods methods) {
+ return (methods & HttpDeliveryMethods.PostRequest) != 0 ? "POST" : "GET";
}
/// <summary>
@@ -97,24 +105,20 @@ namespace DotNetOpenAuth.Test.Mocks {
/// </summary>
/// <param name="message">The message to add a pretend HTTP method to.</param>
/// <returns>A spoofed HttpRequestInfo that wraps the new message.</returns>
- private HttpRequestInfo SpoofHttpMethod(IDirectedProtocolMessage message) {
- HttpRequestInfo requestInfo = new HttpRequestInfo(message, message.HttpMethods);
-
+ private CoordinatingHttpRequestInfo SpoofHttpMethod(IDirectedProtocolMessage message) {
var signedMessage = message as ITamperResistantOAuthMessage;
if (signedMessage != null) {
- string httpMethod = this.GetHttpMethod(signedMessage.HttpMethods);
- requestInfo.HttpMethod = httpMethod;
- requestInfo.UrlBeforeRewriting = message.Recipient;
+ string httpMethod = GetHttpMethod(signedMessage.HttpMethods);
signedMessage.HttpMethod = httpMethod;
}
- requestInfo.Message = this.CloneSerializedParts(message, requestInfo);
-
+ var requestInfo = new CoordinatingHttpRequestInfo(this.CloneSerializedParts(message), message.HttpMethods);
return requestInfo;
}
private IProtocolMessage AwaitIncomingMessage() {
this.IncomingMessageSignal.WaitOne();
+ Assert.That(this.IncomingMessage, Is.Not.Null, "Incoming message signaled, but none supplied.");
IProtocolMessage response = this.IncomingMessage;
this.IncomingMessage = null;
return response;
@@ -127,7 +131,7 @@ namespace DotNetOpenAuth.Test.Mocks {
return response;
}
- private T CloneSerializedParts<T>(T message, HttpRequestInfo requestInfo) where T : class, IProtocolMessage {
+ private T CloneSerializedParts<T>(T message) where T : class, IProtocolMessage {
Requires.NotNull(message, "message");
IProtocolMessage clonedMessage;
@@ -155,9 +159,5 @@ namespace DotNetOpenAuth.Test.Mocks {
return (T)clonedMessage;
}
-
- private string GetHttpMethod(HttpDeliveryMethods methods) {
- return (methods & HttpDeliveryMethods.PostRequest) != 0 ? "POST" : "GET";
- }
}
}
diff --git a/src/DotNetOpenAuth.Test/Mocks/TestBadChannel.cs b/src/DotNetOpenAuth.Test/Mocks/TestBadChannel.cs
index 5344304..263f0fd 100644
--- a/src/DotNetOpenAuth.Test/Mocks/TestBadChannel.cs
+++ b/src/DotNetOpenAuth.Test/Mocks/TestBadChannel.cs
@@ -7,6 +7,7 @@
namespace DotNetOpenAuth.Test.Mocks {
using System;
using System.Collections.Generic;
+ using System.Web;
using DotNetOpenAuth.Messaging;
/// <summary>
@@ -33,7 +34,7 @@ namespace DotNetOpenAuth.Test.Mocks {
return base.Receive(fields, recipient);
}
- internal new IProtocolMessage ReadFromRequest(HttpRequestInfo request) {
+ internal new IProtocolMessage ReadFromRequest(HttpRequestBase request) {
return base.ReadFromRequest(request);
}