diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2008-11-07 00:05:58 -0800 |
---|---|---|
committer | Andrew <andrewarnott@gmail.com> | 2008-11-07 00:05:58 -0800 |
commit | eed78917e2f8b9a0598ae1b41ade201a420a9ccc (patch) | |
tree | 1cacf53884b9ccc661f08bb9615ffaa20cea830c /src/DotNetOpenAuth.Test | |
parent | 1e22342d9cbd2d76468a3c5fdb9e56c1a485034d (diff) | |
download | DotNetOpenAuth-eed78917e2f8b9a0598ae1b41ade201a420a9ccc.zip DotNetOpenAuth-eed78917e2f8b9a0598ae1b41ade201a420a9ccc.tar.gz DotNetOpenAuth-eed78917e2f8b9a0598ae1b41ade201a420a9ccc.tar.bz2 |
Refactored the Channel extensibility to better suit OpenID.
Diffstat (limited to 'src/DotNetOpenAuth.Test')
4 files changed, 17 insertions, 39 deletions
diff --git a/src/DotNetOpenAuth.Test/Mocks/TestBadChannel.cs b/src/DotNetOpenAuth.Test/Mocks/TestBadChannel.cs index 8fbfaf9..9d4712c 100644 --- a/src/DotNetOpenAuth.Test/Mocks/TestBadChannel.cs +++ b/src/DotNetOpenAuth.Test/Mocks/TestBadChannel.cs @@ -7,8 +7,6 @@ namespace DotNetOpenAuth.Test.Mocks { using System; using System.Collections.Generic; - using System.Linq; - using System.Text; using DotNetOpenAuth.Messaging; /// <summary> @@ -39,11 +37,7 @@ namespace DotNetOpenAuth.Test.Mocks { return base.ReadFromRequest(request); } - protected override IProtocolMessage RequestInternal(IDirectedProtocolMessage request) { - throw new NotImplementedException(); - } - - protected override IProtocolMessage ReadFromResponseInternal(System.IO.Stream responseStream) { + protected override IDictionary<string, string> ReadFromResponseInternal(Response response) { throw new NotImplementedException(); } diff --git a/src/DotNetOpenAuth.Test/Mocks/TestChannel.cs b/src/DotNetOpenAuth.Test/Mocks/TestChannel.cs index ebb5858..9c11589 100644 --- a/src/DotNetOpenAuth.Test/Mocks/TestChannel.cs +++ b/src/DotNetOpenAuth.Test/Mocks/TestChannel.cs @@ -7,8 +7,7 @@ namespace DotNetOpenAuth.Test.Mocks { using System; using System.Collections.Generic; - using System.Linq; - using System.Text; + using System.Net; using DotNetOpenAuth.Messaging; internal class TestChannel : Channel { @@ -20,12 +19,12 @@ namespace DotNetOpenAuth.Test.Mocks { : base(messageTypeProvider, bindingElements) { } - protected override IProtocolMessage RequestInternal(IDirectedProtocolMessage request) { - throw new NotImplementedException("Request"); + protected override IDictionary<string, string> ReadFromResponseInternal(Response response) { + throw new NotImplementedException("ReadFromResponseInternal"); } - protected override IProtocolMessage ReadFromResponseInternal(System.IO.Stream responseStream) { - throw new NotImplementedException("ReadFromResponse"); + protected override HttpWebRequest CreateHttpRequest(IDirectedProtocolMessage request) { + throw new NotImplementedException("CreateHttpRequest"); } protected override Response SendDirectMessageResponse(IProtocolMessage response) { diff --git a/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs b/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs index c5d3b14..fbbd6a6 100644 --- a/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs +++ b/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs @@ -33,27 +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.webRequestHandler); - } - - [TestMethod, ExpectedException(typeof(ArgumentNullException))] - public void CtorNullHandler() { - new OAuthChannel(new RsaSha1SigningBindingElement(), this.nonceStore, new InMemoryTokenManager(), new TestMessageTypeProvider(), null); + this.channel = new OAuthChannel(this.signingElement, this.nonceStore, new InMemoryTokenManager(), new TestMessageTypeProvider()); + this.channel.WebRequestHandler = this.webRequestHandler; } [TestMethod, ExpectedException(typeof(ArgumentException))] public void CtorNullSigner() { - new OAuthChannel(null, this.nonceStore, new InMemoryTokenManager(), new TestMessageTypeProvider(), this.webRequestHandler); + new OAuthChannel(null, this.nonceStore, new InMemoryTokenManager(), new TestMessageTypeProvider()); } [TestMethod, ExpectedException(typeof(ArgumentNullException))] public void CtorNullStore() { - new OAuthChannel(new RsaSha1SigningBindingElement(), null, new InMemoryTokenManager(), new TestMessageTypeProvider(), this.webRequestHandler); + new OAuthChannel(new RsaSha1SigningBindingElement(), null, new InMemoryTokenManager(), new TestMessageTypeProvider()); } [TestMethod, ExpectedException(typeof(ArgumentNullException))] public void CtorNullTokenManager() { - new OAuthChannel(new RsaSha1SigningBindingElement(), this.nonceStore, null, new TestMessageTypeProvider(), this.webRequestHandler); + new OAuthChannel(new RsaSha1SigningBindingElement(), this.nonceStore, null, new TestMessageTypeProvider()); } [TestMethod] @@ -100,12 +96,6 @@ namespace DotNetOpenAuth.Test.ChannelElements { Assert.AreEqual("http://hostb/pathB", body["Location"]); } - [TestMethod, ExpectedException(typeof(ArgumentNullException))] - public void ReadFromResponseNull() { - Channel_Accessor accessor = Channel_Accessor.AttachShadow(this.channel); - accessor.ReadFromResponse(null); - } - [TestMethod] public void ReadFromResponse() { var fields = new Dictionary<string, string> { @@ -121,14 +111,11 @@ namespace DotNetOpenAuth.Test.ChannelElements { writer.Flush(); ms.Seek(0, SeekOrigin.Begin); Channel_Accessor channelAccessor = Channel_Accessor.AttachShadow(this.channel); - IProtocolMessage message = channelAccessor.ReadFromResponse(ms); - Assert.IsNotNull(message); - Assert.IsInstanceOfType(message, typeof(TestMessage)); - TestMessage testMessage = (TestMessage)message; - Assert.AreEqual(15, testMessage.Age); - Assert.AreEqual("Andrew", testMessage.Name); - Assert.AreEqual("http://hostb/pathB", testMessage.Location.AbsoluteUri); - Assert.IsNull(testMessage.EmptyMember); + IDictionary<string, string> deserializedFields = channelAccessor.ReadFromResponseInternal(new Response { ResponseStream = ms }); + Assert.AreEqual(fields.Count, deserializedFields.Count); + foreach (string key in fields.Keys) { + Assert.AreEqual(fields[key], deserializedFields[key]); + } } [TestMethod, ExpectedException(typeof(ArgumentNullException))] diff --git a/src/DotNetOpenAuth.Test/Scenarios/CoordinatingOAuthChannel.cs b/src/DotNetOpenAuth.Test/Scenarios/CoordinatingOAuthChannel.cs index 9fae4a9..0fa474e 100644 --- a/src/DotNetOpenAuth.Test/Scenarios/CoordinatingOAuthChannel.cs +++ b/src/DotNetOpenAuth.Test/Scenarios/CoordinatingOAuthChannel.cs @@ -11,7 +11,6 @@ namespace DotNetOpenAuth.Test.Scenarios { using DotNetOpenAuth.Messaging.Bindings; using DotNetOpenAuth.OAuth.ChannelElements; using DotNetOpenAuth.OAuth.Messages; - using DotNetOpenAuth.Test.Mocks; /// <summary> /// A special channel used in test simulations to pass messages directly between two parties. @@ -34,8 +33,7 @@ namespace DotNetOpenAuth.Test.Scenarios { signingBindingElement, new NonceMemoryStore(StandardExpirationBindingElement.DefaultMaximumMessageAge), tokenManager, - isConsumer ? (IMessageTypeProvider)new OAuthConsumerMessageTypeProvider() : new OAuthServiceProviderMessageTypeProvider(tokenManager), - new TestWebRequestHandler()) { + isConsumer ? (IMessageTypeProvider)new OAuthConsumerMessageTypeProvider() : new OAuthServiceProviderMessageTypeProvider(tokenManager)) { } /// <summary> |