summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2008-11-20 06:54:14 -0800
committerAndrew <andrewarnott@gmail.com>2008-11-20 06:54:14 -0800
commit1a882368e2e99e9360cfd1f4f23f5acb70306436 (patch)
treeab0d370a8b8b9d5b638524f189a39991970834bb /src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs
parentd51be63270463542a308a9a2cef992b7d55baaa6 (diff)
downloadDotNetOpenAuth-1a882368e2e99e9360cfd1f4f23f5acb70306436.zip
DotNetOpenAuth-1a882368e2e99e9360cfd1f4f23f5acb70306436.tar.gz
DotNetOpenAuth-1a882368e2e99e9360cfd1f4f23f5acb70306436.tar.bz2
Reworked the way messages are instantiated and deserialized.
This was a whole lot of work to just get multi-version capability added to message types so that OpenID could handle its few versions.
Diffstat (limited to 'src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs')
-rw-r--r--src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs35
1 files changed, 24 insertions, 11 deletions
diff --git a/src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs b/src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs
index bb094af..2f82c06 100644
--- a/src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs
+++ b/src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs
@@ -21,7 +21,7 @@ namespace DotNetOpenAuth.Test.Mocks {
private Action<IProtocolMessage> outgoingMessageFilter;
internal CoordinatingChannel(Channel wrappedChannel, Action<IProtocolMessage> incomingMessageFilter, Action<IProtocolMessage> outgoingMessageFilter)
- : base(GetMessageTypeProvider(wrappedChannel), wrappedChannel.BindingElements.ToArray()) {
+ : base(GetMessageFactory(wrappedChannel), wrappedChannel.BindingElements.ToArray()) {
ErrorUtilities.VerifyArgumentNotNull(wrappedChannel, "wrappedChannel");
this.wrappedChannel = wrappedChannel;
@@ -87,25 +87,38 @@ namespace DotNetOpenAuth.Test.Mocks {
}
protected virtual T CloneSerializedParts<T>(T message, HttpRequestInfo requestInfo) where T : class, IProtocolMessage {
- if (message == null) {
- throw new ArgumentNullException("message");
- }
+ ErrorUtilities.VerifyArgumentNotNull(message, "message");
+
+ IProtocolMessage clonedMessage;
+ MessageSerializer serializer = MessageSerializer.Get(message.GetType());
+ var fields = serializer.Serialize(message);
MessageReceivingEndpoint recipient = null;
- IDirectedProtocolMessage directedMessage = message as IDirectedProtocolMessage;
- if (directedMessage != null && directedMessage.Recipient != null) {
- recipient = new MessageReceivingEndpoint(directedMessage.Recipient, directedMessage.HttpMethods);
+ var directedMessage = message as IDirectedProtocolMessage;
+ var directResponse = message as IDirectResponseProtocolMessage;
+ if (directedMessage != null && directedMessage.IsRequest()) {
+ if (directedMessage.Recipient != null) {
+ recipient = new MessageReceivingEndpoint(directedMessage.Recipient, directedMessage.HttpMethods);
+ }
+
+ clonedMessage = this.RemoteChannel.MessageFactory.GetNewRequestMessage(recipient, fields);
+ } else if (directResponse != null && directResponse.IsDirectResponse()) {
+ clonedMessage = this.RemoteChannel.MessageFactory.GetNewResponseMessage(directResponse.OriginatingRequest, fields);
+ } else {
+ throw new InvalidOperationException("Totally expected a message to implement one of the two derived interface types.");
}
- MessageSerializer serializer = MessageSerializer.Get(message.GetType());
- return (T)serializer.Deserialize(serializer.Serialize(message), recipient);
+ // Fill the cloned message with data.
+ serializer.Deserialize(fields, clonedMessage);
+
+ return (T)clonedMessage;
}
- private static IMessageTypeProvider GetMessageTypeProvider(Channel channel) {
+ private static IMessageFactory GetMessageFactory(Channel channel) {
ErrorUtilities.VerifyArgumentNotNull(channel, "channel");
Channel_Accessor accessor = Channel_Accessor.AttachShadow(channel);
- return accessor.MessageTypeProvider;
+ return accessor.MessageFactory;
}
private IProtocolMessage AwaitIncomingMessage() {