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 | |
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')
21 files changed, 156 insertions, 84 deletions
diff --git a/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj b/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj index d16b6c4..4469c17 100644 --- a/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj +++ b/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj @@ -88,7 +88,7 @@ <Compile Include="Mocks\TestWebRequestHandler.cs" /> <Compile Include="Mocks\TestChannel.cs" /> <Compile Include="Mocks\TestMessage.cs" /> - <Compile Include="Mocks\TestMessageTypeProvider.cs" /> + <Compile Include="Mocks\TestMessageFactory.cs" /> <Compile Include="OAuth\ChannelElements\HmacSha1SigningBindingElementTests.cs" /> <Compile Include="OAuth\ChannelElements\OAuthChannelTests.cs" /> <Compile Include="OAuth\ChannelElements\PlaintextSigningBindingElementTest.cs" /> diff --git a/src/DotNetOpenAuth.Test/Messaging/ChannelTests.cs b/src/DotNetOpenAuth.Test/Messaging/ChannelTests.cs index 4127b5a..0176164 100644 --- a/src/DotNetOpenAuth.Test/Messaging/ChannelTests.cs +++ b/src/DotNetOpenAuth.Test/Messaging/ChannelTests.cs @@ -41,7 +41,7 @@ namespace DotNetOpenAuth.Test.Messaging { [TestMethod, ExpectedException(typeof(ArgumentException))] public void SendIndirectedUndirectedMessage() { - IProtocolMessage message = new TestMessage(MessageTransport.Indirect); + IProtocolMessage message = new TestDirectedMessage(MessageTransport.Indirect); this.Channel.Send(message); } @@ -150,7 +150,7 @@ namespace DotNetOpenAuth.Test.Messaging { /// </remarks> [TestMethod, ExpectedException(typeof(NotImplementedException), "SendDirectMessageResponse")] public void SendDirectMessageResponse() { - IProtocolMessage message = new TestMessage { + IProtocolMessage message = new TestDirectedMessage { Age = 15, Name = "Andrew", Location = new Uri("http://host/path"), @@ -232,14 +232,14 @@ namespace DotNetOpenAuth.Test.Messaging { [TestMethod, ExpectedException(typeof(ProtocolException))] public void MessageExpirationWithoutTamperResistance() { new TestChannel( - new TestMessageTypeProvider(), + new TestMessageFactory(), new StandardExpirationBindingElement()); } [TestMethod, ExpectedException(typeof(ProtocolException))] public void TooManyBindingElementsProvidingSameProtection() { new TestChannel( - new TestMessageTypeProvider(), + new TestMessageFactory(), new MockSigningBindingElement(), new MockSigningBindingElement()); } @@ -253,7 +253,7 @@ namespace DotNetOpenAuth.Test.Messaging { IChannelBindingElement expire = new StandardExpirationBindingElement(); Channel channel = new TestChannel( - new TestMessageTypeProvider(), + new TestMessageFactory(), sign, replay, expire, diff --git a/src/DotNetOpenAuth.Test/Messaging/MessageSerializerTests.cs b/src/DotNetOpenAuth.Test/Messaging/MessageSerializerTests.cs index 62b6393..3bcca10 100644 --- a/src/DotNetOpenAuth.Test/Messaging/MessageSerializerTests.cs +++ b/src/DotNetOpenAuth.Test/Messaging/MessageSerializerTests.cs @@ -65,7 +65,8 @@ namespace DotNetOpenAuth.Test.Messaging { fields["Name"] = "Andrew"; fields["age"] = "15"; fields["Timestamp"] = "1990-01-01T00:00:00"; - var actual = (Mocks.TestMessage)serializer.Deserialize(fields, null); + var actual = new Mocks.TestDirectedMessage(); + serializer.Deserialize(fields, actual); Assert.AreEqual(15, actual.Age); Assert.AreEqual("Andrew", actual.Name); Assert.AreEqual(DateTime.Parse("1/1/1990"), actual.Timestamp); @@ -94,7 +95,8 @@ namespace DotNetOpenAuth.Test.Messaging { fields["SecondDerivedElement"] = "second"; fields["explicit"] = "explicitValue"; fields["private"] = "privateValue"; - var actual = (Mocks.TestDerivedMessage)serializer.Deserialize(fields, null); + var actual = new Mocks.TestDerivedMessage(); + serializer.Deserialize(fields, actual); Assert.AreEqual(15, actual.Age); Assert.AreEqual("Andrew", actual.Name); Assert.AreEqual("first", actual.TheFirstDerivedElement); @@ -113,7 +115,8 @@ namespace DotNetOpenAuth.Test.Messaging { // Add some field that is not recognized by the class. This simulates a querystring with // more parameters than are actually interesting to the protocol message. fields["someExtraField"] = "asdf"; - var actual = (Mocks.TestMessage)serializer.Deserialize(fields, null); + var actual = new Mocks.TestDirectedMessage(); + serializer.Deserialize(fields, actual); Assert.AreEqual(15, actual.Age); Assert.AreEqual("Andrew", actual.Name); Assert.IsNull(actual.EmptyMember); @@ -121,10 +124,11 @@ namespace DotNetOpenAuth.Test.Messaging { [TestMethod, ExpectedException(typeof(ProtocolException))] public void DeserializeInvalidMessage() { - var serializer = MessageSerializer.Get(typeof(Mocks.TestMessage)); + IProtocolMessage message = new Mocks.TestDirectedMessage(); + var serializer = MessageSerializer.Get(message.GetType()); var fields = GetStandardTestFields(FieldFill.AllRequired); fields["age"] = "-1"; // Set an disallowed value. - serializer.Deserialize(fields, null); + serializer.Deserialize(fields, message); } } } diff --git a/src/DotNetOpenAuth.Test/Messaging/MessagingTestBase.cs b/src/DotNetOpenAuth.Test/Messaging/MessagingTestBase.cs index acaf4a0..0a11a75 100644 --- a/src/DotNetOpenAuth.Test/Messaging/MessagingTestBase.cs +++ b/src/DotNetOpenAuth.Test/Messaging/MessagingTestBase.cs @@ -26,7 +26,7 @@ namespace DotNetOpenAuth.Test { None, /// <summary> - /// Only enough fields for the <see cref="TestMessageTypeProvider"/> + /// Only enough fields for the <see cref="TestMessageFactory"/> /// to identify the message are included. /// </summary> IdentifiableButNotAllRequired, @@ -105,7 +105,7 @@ namespace DotNetOpenAuth.Test { replay = true; } - var typeProvider = new TestMessageTypeProvider(signing, expiration, replay); + var typeProvider = new TestMessageFactory(signing, expiration, replay); return new TestChannel(typeProvider, bindingElements.ToArray()); } @@ -128,7 +128,7 @@ namespace DotNetOpenAuth.Test { } internal static TestMessage GetStandardTestMessage(FieldFill fill) { - TestMessage message = new TestMessage(); + TestMessage message = new TestDirectedMessage(); GetStandardTestMessage(fill, message); return message; } diff --git a/src/DotNetOpenAuth.Test/Messaging/ProtocolExceptionTests.cs b/src/DotNetOpenAuth.Test/Messaging/ProtocolExceptionTests.cs index a2e3eaa..02aea64 100644 --- a/src/DotNetOpenAuth.Test/Messaging/ProtocolExceptionTests.cs +++ b/src/DotNetOpenAuth.Test/Messaging/ProtocolExceptionTests.cs @@ -32,7 +32,7 @@ namespace DotNetOpenAuth.Test.Messaging { [TestMethod] public void CtorWithProtocolMessage() { - IProtocolMessage request = new Mocks.TestMessage(); + IProtocolMessage request = new Mocks.TestDirectedMessage(); Uri receiver = new Uri("http://receiver"); ProtocolException ex = new ProtocolException("some error occurred", request, receiver); IDirectedProtocolMessage msg = (IDirectedProtocolMessage)ex; diff --git a/src/DotNetOpenAuth.Test/Messaging/Reflection/MessageDictionaryTests.cs b/src/DotNetOpenAuth.Test/Messaging/Reflection/MessageDictionaryTests.cs index 039743e..0175173 100644 --- a/src/DotNetOpenAuth.Test/Messaging/Reflection/MessageDictionaryTests.cs +++ b/src/DotNetOpenAuth.Test/Messaging/Reflection/MessageDictionaryTests.cs @@ -22,7 +22,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection { public override void SetUp() { base.SetUp(); - this.message = new Mocks.TestMessage(); + this.message = new Mocks.TestDirectedMessage(); } [TestMethod, ExpectedException(typeof(ArgumentNullException))] 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() { 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) { diff --git a/src/DotNetOpenAuth.Test/Mocks/TestBadChannel.cs b/src/DotNetOpenAuth.Test/Mocks/TestBadChannel.cs index 9d4712c..515766e 100644 --- a/src/DotNetOpenAuth.Test/Mocks/TestBadChannel.cs +++ b/src/DotNetOpenAuth.Test/Mocks/TestBadChannel.cs @@ -14,7 +14,7 @@ namespace DotNetOpenAuth.Test.Mocks { /// </summary> internal class TestBadChannel : Channel { internal TestBadChannel(bool badConstructorParam) - : base(badConstructorParam ? null : new TestMessageTypeProvider()) { + : base(badConstructorParam ? null : new TestMessageFactory()) { } internal new void Create301RedirectResponse(IDirectedProtocolMessage message, IDictionary<string, string> fields) { diff --git a/src/DotNetOpenAuth.Test/Mocks/TestBaseMessage.cs b/src/DotNetOpenAuth.Test/Mocks/TestBaseMessage.cs index bd17dd6..212907f 100644 --- a/src/DotNetOpenAuth.Test/Mocks/TestBaseMessage.cs +++ b/src/DotNetOpenAuth.Test/Mocks/TestBaseMessage.cs @@ -17,6 +17,7 @@ namespace DotNetOpenAuth.Test.Mocks { internal class TestBaseMessage : IProtocolMessage, IBaseMessageExplicitMembers { private Dictionary<string, string> extraData = new Dictionary<string, string>(); + private bool incoming; [MessagePart("age", IsRequired = true)] public int Age { get; set; } @@ -43,7 +44,9 @@ namespace DotNetOpenAuth.Test.Mocks { get { return this.extraData; } } - bool IProtocolMessage.Incoming { get; set; } + bool IProtocolMessage.Incoming { + get { return this.incoming; } + } internal string PrivatePropertyAccessor { get { return this.PrivateProperty; } @@ -54,5 +57,9 @@ namespace DotNetOpenAuth.Test.Mocks { private string PrivateProperty { get; set; } void IProtocolMessage.EnsureValidMessage() { } + + internal void SetAsIncoming() { + this.incoming = true; + } } } diff --git a/src/DotNetOpenAuth.Test/Mocks/TestChannel.cs b/src/DotNetOpenAuth.Test/Mocks/TestChannel.cs index 9c11589..0f7f4b8 100644 --- a/src/DotNetOpenAuth.Test/Mocks/TestChannel.cs +++ b/src/DotNetOpenAuth.Test/Mocks/TestChannel.cs @@ -12,10 +12,10 @@ namespace DotNetOpenAuth.Test.Mocks { internal class TestChannel : Channel { internal TestChannel() - : this(new TestMessageTypeProvider()) { + : this(new TestMessageFactory()) { } - internal TestChannel(IMessageTypeProvider messageTypeProvider, params IChannelBindingElement[] bindingElements) + internal TestChannel(IMessageFactory messageTypeProvider, params IChannelBindingElement[] bindingElements) : base(messageTypeProvider, bindingElements) { } diff --git a/src/DotNetOpenAuth.Test/Mocks/TestMessage.cs b/src/DotNetOpenAuth.Test/Mocks/TestMessage.cs index 55e44ba..4a168a1 100644 --- a/src/DotNetOpenAuth.Test/Mocks/TestMessage.cs +++ b/src/DotNetOpenAuth.Test/Mocks/TestMessage.cs @@ -11,15 +11,16 @@ namespace DotNetOpenAuth.Test.Mocks { using DotNetOpenAuth.Messaging; using DotNetOpenAuth.Messaging.Reflection; - internal class TestMessage : IProtocolMessage { + internal abstract class TestMessage : IDirectResponseProtocolMessage { private MessageTransport transport; private Dictionary<string, string> extraData = new Dictionary<string, string>(); + private bool incoming; - internal TestMessage() + protected TestMessage() : this(MessageTransport.Direct) { } - internal TestMessage(MessageTransport transport) { + protected TestMessage(MessageTransport transport) { this.transport = transport; } @@ -34,7 +35,7 @@ namespace DotNetOpenAuth.Test.Mocks { [MessagePart(IsRequired = true)] public DateTime Timestamp { get; set; } - #region IProtocolMessage Members + #region IProtocolMessage Properties Version IProtocolMessage.ProtocolVersion { get { return new Version(1, 0); } @@ -52,7 +53,19 @@ namespace DotNetOpenAuth.Test.Mocks { get { return this.extraData; } } - bool IProtocolMessage.Incoming { get; set; } + bool IProtocolMessage.Incoming { + get { return this.incoming; } + } + + #endregion + + #region IDirectResponseProtocolMessage Members + + public IDirectedProtocolMessage OriginatingRequest { get; set; } + + #endregion + + #region IProtocolMessage Methods void IProtocolMessage.EnsureValidMessage() { if (this.EmptyMember != null || this.Age < 0) { @@ -61,5 +74,9 @@ namespace DotNetOpenAuth.Test.Mocks { } #endregion + + internal void SetAsIncoming() { + this.incoming = true; + } } } diff --git a/src/DotNetOpenAuth.Test/Mocks/TestMessageTypeProvider.cs b/src/DotNetOpenAuth.Test/Mocks/TestMessageFactory.cs index 8f075f7..7c88898 100644 --- a/src/DotNetOpenAuth.Test/Mocks/TestMessageTypeProvider.cs +++ b/src/DotNetOpenAuth.Test/Mocks/TestMessageFactory.cs @@ -1,5 +1,5 @@ //----------------------------------------------------------------------- -// <copyright file="TestMessageTypeProvider.cs" company="Andrew Arnott"> +// <copyright file="TestMessageFactory.cs" company="Andrew Arnott"> // Copyright (c) Andrew Arnott. All rights reserved. // </copyright> //----------------------------------------------------------------------- @@ -11,16 +11,16 @@ namespace DotNetOpenAuth.Test.Mocks { using System.Text; using DotNetOpenAuth.Messaging; - internal class TestMessageTypeProvider : IMessageTypeProvider { + internal class TestMessageFactory : IMessageFactory { private bool signedMessages; private bool expiringMessages; private bool replayMessages; - internal TestMessageTypeProvider() + internal TestMessageFactory() : this(false, false, false) { } - internal TestMessageTypeProvider(bool signed, bool expiring, bool replay) { + internal TestMessageFactory(bool signed, bool expiring, bool replay) { if ((!signed && expiring) || (!expiring && replay)) { throw new ArgumentException("Invalid combination of protection."); } @@ -29,26 +29,30 @@ namespace DotNetOpenAuth.Test.Mocks { this.replayMessages = replay; } - #region IMessageTypeProvider Members + #region IMessageFactory Members + + public IDirectedProtocolMessage GetNewRequestMessage(MessageReceivingEndpoint recipient, IDictionary<string, string> fields) { + ErrorUtilities.VerifyArgumentNotNull(fields, "fields"); - public Type GetRequestMessageType(IDictionary<string, string> fields) { if (fields.ContainsKey("age")) { if (this.signedMessages) { if (this.expiringMessages) { if (this.replayMessages) { - return typeof(TestReplayProtectedMessage); + return new TestReplayProtectedMessage(); } - return typeof(TestExpiringMessage); + return new TestExpiringMessage(); } - return typeof(TestSignedDirectedMessage); + return new TestSignedDirectedMessage(); } - return typeof(TestDirectedMessage); + return new TestDirectedMessage(); } return null; } - public Type GetResponseMessageType(IProtocolMessage request, IDictionary<string, string> fields) { - return this.GetRequestMessageType(fields); + public IDirectResponseProtocolMessage GetNewResponseMessage(IDirectedProtocolMessage request, IDictionary<string, string> fields) { + TestMessage message = (TestMessage)this.GetNewRequestMessage(null, fields); + message.OriginatingRequest = request; + return message; } #endregion diff --git a/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs b/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs index fbbd6a6..b1fe7c4 100644 --- a/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs +++ b/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs @@ -33,23 +33,23 @@ namespace DotNetOpenAuth.Test.ChannelElements { this.webRequestHandler = new TestWebRequestHandler(); this.signingElement = new RsaSha1SigningBindingElement(); this.nonceStore = new NonceMemoryStore(StandardExpirationBindingElement.DefaultMaximumMessageAge); - this.channel = new OAuthChannel(this.signingElement, this.nonceStore, new InMemoryTokenManager(), new TestMessageTypeProvider()); + this.channel = new OAuthChannel(this.signingElement, this.nonceStore, new InMemoryTokenManager(), new TestMessageFactory()); this.channel.WebRequestHandler = this.webRequestHandler; } [TestMethod, ExpectedException(typeof(ArgumentException))] public void CtorNullSigner() { - new OAuthChannel(null, this.nonceStore, new InMemoryTokenManager(), new TestMessageTypeProvider()); + new OAuthChannel(null, this.nonceStore, new InMemoryTokenManager(), new TestMessageFactory()); } [TestMethod, ExpectedException(typeof(ArgumentNullException))] public void CtorNullStore() { - new OAuthChannel(new RsaSha1SigningBindingElement(), null, new InMemoryTokenManager(), new TestMessageTypeProvider()); + new OAuthChannel(new RsaSha1SigningBindingElement(), null, new InMemoryTokenManager(), new TestMessageFactory()); } [TestMethod, ExpectedException(typeof(ArgumentNullException))] public void CtorNullTokenManager() { - new OAuthChannel(new RsaSha1SigningBindingElement(), this.nonceStore, null, new TestMessageTypeProvider()); + new OAuthChannel(new RsaSha1SigningBindingElement(), this.nonceStore, null, new TestMessageFactory()); } [TestMethod] @@ -79,7 +79,7 @@ namespace DotNetOpenAuth.Test.ChannelElements { [TestMethod] public void SendDirectMessageResponse() { - IProtocolMessage message = new TestMessage { + IProtocolMessage message = new TestDirectedMessage { Age = 15, Name = "Andrew", Location = new Uri("http://hostb/pathB"), diff --git a/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs b/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs index eb0bccc..6209fac 100644 --- a/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs +++ b/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs @@ -20,34 +20,38 @@ namespace DotNetOpenAuth.Test.OpenId { [TestMethod] public void DHv2() { - var opDescription = new ProviderEndpointDescription(new Uri("http://host"), Protocol.V20); + Protocol protocol = Protocol.V20; + var opDescription = new ProviderEndpointDescription(new Uri("http://host"), protocol.Version); this.ParameterizedAssociationTest( opDescription, - Protocol.V20.Args.SignatureAlgorithm.HMAC_SHA256); + protocol.Args.SignatureAlgorithm.HMAC_SHA256); } [TestMethod] public void DHv1() { - var opDescription = new ProviderEndpointDescription(new Uri("http://host"), Protocol.V10); + Protocol protocol = Protocol.V11; + var opDescription = new ProviderEndpointDescription(new Uri("http://host"), protocol.Version); this.ParameterizedAssociationTest( opDescription, - Protocol.V20.Args.SignatureAlgorithm.HMAC_SHA1); + protocol.Args.SignatureAlgorithm.HMAC_SHA1); } [TestMethod] public void PTv2() { - var opDescription = new ProviderEndpointDescription(new Uri("https://host"), Protocol.V20); + Protocol protocol = Protocol.V20; + var opDescription = new ProviderEndpointDescription(new Uri("https://host"), protocol.Version); this.ParameterizedAssociationTest( opDescription, - Protocol.V20.Args.SignatureAlgorithm.HMAC_SHA256); + protocol.Args.SignatureAlgorithm.HMAC_SHA256); } [TestMethod] public void PTv1() { - var opDescription = new ProviderEndpointDescription(new Uri("https://host"), Protocol.V11); + Protocol protocol = Protocol.V11; + var opDescription = new ProviderEndpointDescription(new Uri("https://host"), protocol.Version); this.ParameterizedAssociationTest( opDescription, - Protocol.V20.Args.SignatureAlgorithm.HMAC_SHA1); + protocol.Args.SignatureAlgorithm.HMAC_SHA1); } /// <summary> @@ -64,6 +68,7 @@ namespace DotNetOpenAuth.Test.OpenId { private void ParameterizedAssociationTest( ProviderEndpointDescription opDescription, string expectedAssociationType) { + Protocol protocol = Protocol.Lookup(opDescription.ProtocolVersion); bool expectSuccess = expectedAssociationType != null; bool expectDiffieHellman = !opDescription.Endpoint.IsTransportSecure(); Association rpAssociation = null, opAssociation; @@ -79,7 +84,7 @@ namespace DotNetOpenAuth.Test.OpenId { op.AutoRespond(); }); coordinator.IncomingMessageFilter = message => { - Assert.AreSame(opDescription.Protocol.Version, message.ProtocolVersion, "The message was for version {0} but was expected to be for {1}.", message.ProtocolVersion, opDescription.Protocol.Version); + Assert.AreSame(opDescription.ProtocolVersion, message.ProtocolVersion, "The message was recognized as version {0} but was expected to be {1}.", message.ProtocolVersion, opDescription.ProtocolVersion); var associateSuccess = message as AssociateSuccessfulResponse; var associateFailed = message as AssociateUnsuccessfulResponse; if (associateSuccess != null) { @@ -90,7 +95,7 @@ namespace DotNetOpenAuth.Test.OpenId { } }; coordinator.OutgoingMessageFilter = message => { - Assert.AreSame(opDescription.Protocol.Version, message.ProtocolVersion, "The message was for version {0} but was expected to be for {1}.", message.ProtocolVersion, opDescription.Protocol.Version); + Assert.AreSame(opDescription.ProtocolVersion, message.ProtocolVersion, "The message was for version {0} but was expected to be for {1}.", message.ProtocolVersion, opDescription.ProtocolVersion); }; coordinator.Run(); @@ -101,8 +106,8 @@ namespace DotNetOpenAuth.Test.OpenId { Assert.IsNotNull(opAssociation, "The Provider should have stored the association."); Assert.AreEqual(opAssociation.Handle, rpAssociation.Handle); - Assert.AreEqual(expectedAssociationType, rpAssociation.GetAssociationType(opDescription.Protocol)); - Assert.AreEqual(expectedAssociationType, opAssociation.GetAssociationType(opDescription.Protocol)); + Assert.AreEqual(expectedAssociationType, rpAssociation.GetAssociationType(protocol)); + Assert.AreEqual(expectedAssociationType, opAssociation.GetAssociationType(protocol)); Assert.IsTrue(Math.Abs(opAssociation.SecondsTillExpiration - rpAssociation.SecondsTillExpiration) < 60); Assert.IsTrue(MessagingUtilities.AreEquivalent(opAssociation.SecretKey, rpAssociation.SecretKey)); diff --git a/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateDiffieHellmanRequestTests.cs b/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateDiffieHellmanRequestTests.cs index 81014f2..a8648ac 100644 --- a/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateDiffieHellmanRequestTests.cs +++ b/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateDiffieHellmanRequestTests.cs @@ -6,6 +6,7 @@ namespace DotNetOpenAuth.Test.OpenId.Messages { using System; + using DotNetOpenAuth.OpenId; using DotNetOpenAuth.OpenId.Messages; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -16,7 +17,7 @@ namespace DotNetOpenAuth.Test.OpenId.Messages { [TestInitialize] public void Setup() { - this.request = new AssociateDiffieHellmanRequest(Recipient); + this.request = new AssociateDiffieHellmanRequest(Protocol.V20.Version, Recipient); } [TestMethod] diff --git a/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateRequestTests.cs b/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateRequestTests.cs index ca9b6d6..db73a8c 100644 --- a/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateRequestTests.cs +++ b/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateRequestTests.cs @@ -21,7 +21,7 @@ namespace DotNetOpenAuth.Test.OpenId.Messages { [TestInitialize] public void Setup() { - this.request = new AssociateUnencryptedRequest(this.secureRecipient); + this.request = new AssociateUnencryptedRequest(this.protocol.Version, this.secureRecipient); } [TestMethod] @@ -52,14 +52,14 @@ namespace DotNetOpenAuth.Test.OpenId.Messages { [TestMethod] public void ValidMessageTest() { - this.request = new AssociateUnencryptedRequest(this.secureRecipient); + this.request = new AssociateUnencryptedRequest(Protocol.V20.Version, this.secureRecipient); this.request.AssociationType = this.protocol.Args.SignatureAlgorithm.HMAC_SHA1; this.request.EnsureValidMessage(); } [TestMethod, ExpectedException(typeof(ProtocolException))] public void InvalidMessageTest() { - this.request = new AssociateUnencryptedRequest(this.insecureRecipient); + this.request = new AssociateUnencryptedRequest(Protocol.V20.Version, this.insecureRecipient); this.request.AssociationType = this.protocol.Args.SignatureAlgorithm.HMAC_SHA1; this.request.EnsureValidMessage(); // no-encryption only allowed for secure channels. } diff --git a/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateUnencryptedResponseTests.cs b/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateUnencryptedResponseTests.cs index 7455cce..16f76cf 100644 --- a/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateUnencryptedResponseTests.cs +++ b/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateUnencryptedResponseTests.cs @@ -5,6 +5,7 @@ //----------------------------------------------------------------------- namespace DotNetOpenAuth.Test.OpenId.Messages { + using System; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OpenId; using DotNetOpenAuth.OpenId.Messages; @@ -16,7 +17,8 @@ namespace DotNetOpenAuth.Test.OpenId.Messages { [TestInitialize] public void Setup() { - this.response = new AssociateUnencryptedResponse(); + var request = new AssociateUnencryptedRequest(Protocol.V20.Version, new Uri("http://host")); + this.response = new AssociateUnencryptedResponse(request); } [TestMethod] diff --git a/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateUnsuccessfulResponseTests.cs b/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateUnsuccessfulResponseTests.cs index 588ea76..b6f6914 100644 --- a/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateUnsuccessfulResponseTests.cs +++ b/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateUnsuccessfulResponseTests.cs @@ -5,6 +5,7 @@ //----------------------------------------------------------------------- namespace DotNetOpenAuth.Test.OpenId.Messages { + using System; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OpenId; using DotNetOpenAuth.OpenId.Messages; @@ -16,7 +17,8 @@ namespace DotNetOpenAuth.Test.OpenId.Messages { [TestInitialize] public void Setup() { - this.response = new AssociateUnsuccessfulResponse(); + var request = new AssociateUnencryptedRequest(Protocol.V20.Version, new Uri("http://host")); + this.response = new AssociateUnsuccessfulResponse(request); } [TestMethod] diff --git a/src/DotNetOpenAuth.Test/OpenId/Messages/DirectErrorResponseTests.cs b/src/DotNetOpenAuth.Test/OpenId/Messages/DirectErrorResponseTests.cs index 0cdc3aa..6fd5602 100644 --- a/src/DotNetOpenAuth.Test/OpenId/Messages/DirectErrorResponseTests.cs +++ b/src/DotNetOpenAuth.Test/OpenId/Messages/DirectErrorResponseTests.cs @@ -5,18 +5,22 @@ //----------------------------------------------------------------------- namespace DotNetOpenAuth.Test.OpenId.Messages { + using System; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OpenId; using DotNetOpenAuth.OpenId.Messages; using Microsoft.VisualStudio.TestTools.UnitTesting; [TestClass] - public class DirectErrorResponseTests { + public class DirectErrorResponseTests : OpenIdTestBase { private DirectErrorResponse response; [TestInitialize] - public void Setup() { - this.response = new DirectErrorResponse(); + public override void SetUp() { + base.SetUp(); + + var request = new AssociateUnencryptedRequest(Protocol.V20.Version, new Uri("http://host")); + this.response = new DirectErrorResponse(request); } [TestMethod] diff --git a/src/DotNetOpenAuth.Test/OpenId/Messages/IndirectErrorResponseTests.cs b/src/DotNetOpenAuth.Test/OpenId/Messages/IndirectErrorResponseTests.cs index a899d89..7794970 100644 --- a/src/DotNetOpenAuth.Test/OpenId/Messages/IndirectErrorResponseTests.cs +++ b/src/DotNetOpenAuth.Test/OpenId/Messages/IndirectErrorResponseTests.cs @@ -18,7 +18,7 @@ namespace DotNetOpenAuth.Test.OpenId.Messages { [TestInitialize] public void Setup() { - this.response = new IndirectErrorResponse(this.recipient); + this.response = new IndirectErrorResponse(Protocol.V20.Version, this.recipient); } [TestMethod] |