diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2008-11-20 06:54:14 -0800 |
---|---|---|
committer | Andrew <andrewarnott@gmail.com> | 2008-11-20 06:54:14 -0800 |
commit | 1a882368e2e99e9360cfd1f4f23f5acb70306436 (patch) | |
tree | ab0d370a8b8b9d5b638524f189a39991970834bb /src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthChannel.cs | |
parent | d51be63270463542a308a9a2cef992b7d55baaa6 (diff) | |
download | DotNetOpenAuth-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/CoordinatingOAuthChannel.cs')
-rw-r--r-- | src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthChannel.cs | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthChannel.cs b/src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthChannel.cs index 148d2da..10a8d7e 100644 --- a/src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthChannel.cs +++ b/src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthChannel.cs @@ -33,7 +33,7 @@ namespace DotNetOpenAuth.Test.Mocks { signingBindingElement, new NonceMemoryStore(StandardExpirationBindingElement.DefaultMaximumMessageAge), tokenManager, - isConsumer ? (IMessageTypeProvider)new OAuthConsumerMessageTypeProvider() : new OAuthServiceProviderMessageTypeProvider(tokenManager)) { + isConsumer ? (IMessageFactory)new OAuthConsumerMessageFactory() : new OAuthServiceProviderMessageFactory(tokenManager)) { } /// <summary> @@ -121,18 +121,31 @@ namespace DotNetOpenAuth.Test.Mocks { } private 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 string GetHttpMethod(HttpDeliveryMethods methods) { |