diff options
Diffstat (limited to 'src/DotNetOAuth.Test')
-rw-r--r-- | src/DotNetOAuth.Test/DotNetOAuth.Test.csproj | 3 | ||||
-rw-r--r-- | src/DotNetOAuth.Test/Mocks/InMemoryTokenManager.cs | 37 | ||||
-rw-r--r-- | src/DotNetOAuth.Test/Scenarios/AppendixScenarios.cs | 27 | ||||
-rw-r--r-- | src/DotNetOAuth.Test/Scenarios/CoordinatingOAuthChannel.cs | 5 | ||||
-rw-r--r-- | src/DotNetOAuth.Test/ServiceProviderEndpointsTests.cs (renamed from src/DotNetOAuth.Test/ServiceProviderTests.cs) | 14 |
5 files changed, 66 insertions, 20 deletions
diff --git a/src/DotNetOAuth.Test/DotNetOAuth.Test.csproj b/src/DotNetOAuth.Test/DotNetOAuth.Test.csproj index 6551281..8771050 100644 --- a/src/DotNetOAuth.Test/DotNetOAuth.Test.csproj +++ b/src/DotNetOAuth.Test/DotNetOAuth.Test.csproj @@ -70,6 +70,7 @@ <Compile Include="Messaging\Bindings\StandardExpirationBindingElementTests.cs" />
<Compile Include="Messaging\Reflection\MessagePartTests.cs" />
<Compile Include="Messaging\Reflection\ValueMappingTests.cs" />
+ <Compile Include="Mocks\InMemoryTokenManager.cs" />
<Compile Include="Mocks\MockTransformationBindingElement.cs" />
<Compile Include="Mocks\MockReplayProtectionBindingElement.cs" />
<Compile Include="Mocks\TestBaseMessage.cs" />
@@ -91,7 +92,7 @@ <Compile Include="Scenarios\AppendixScenarios.cs" />
<Compile Include="Scenarios\CoordinatingOAuthChannel.cs" />
<Compile Include="Scenarios\Coordinator.cs" />
- <Compile Include="ServiceProviderTests.cs" />
+ <Compile Include="ServiceProviderEndpointsTests.cs" />
<Compile Include="TestBase.cs" />
<Compile Include="UriUtilTests.cs" />
</ItemGroup>
diff --git a/src/DotNetOAuth.Test/Mocks/InMemoryTokenManager.cs b/src/DotNetOAuth.Test/Mocks/InMemoryTokenManager.cs new file mode 100644 index 0000000..002eee1 --- /dev/null +++ b/src/DotNetOAuth.Test/Mocks/InMemoryTokenManager.cs @@ -0,0 +1,37 @@ +namespace DotNetOAuth.Test.Mocks {
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
+ using DotNetOAuth.ChannelElements;
+
+ internal class InMemoryTokenManager : ITokenManager {
+ Dictionary<string, string> consumersAndSecrets = new Dictionary<string, string>();
+ Dictionary<string, string> tokensAndSecrets = new Dictionary<string, string>();
+
+ #region ITokenManager Members
+
+ public string GetConsumerSecret(string consumerKey) {
+ return consumersAndSecrets[consumerKey];
+ }
+
+ public string GetTokenSecret(string token) {
+ return tokensAndSecrets[token];
+ }
+
+ public void StoreNewRequestToken(string consumerKey, string requestToken, string requestTokenSecret, IDictionary<string, string> parameters) {
+ tokensAndSecrets[requestToken] = requestTokenSecret;
+ }
+
+ public void ExpireRequestTokenAndStoreNewAccessToken(string consumerKey, string requestToken, string accessToken, string accessTokenSecret) {
+ tokensAndSecrets.Remove(requestToken);
+ tokensAndSecrets[accessToken] = accessTokenSecret;
+ }
+
+ #endregion
+
+ internal void AddConsumer(string key, string secret) {
+ consumersAndSecrets.Add(key, secret);
+ }
+ }
+}
diff --git a/src/DotNetOAuth.Test/Scenarios/AppendixScenarios.cs b/src/DotNetOAuth.Test/Scenarios/AppendixScenarios.cs index 86d5d43..563fac3 100644 --- a/src/DotNetOAuth.Test/Scenarios/AppendixScenarios.cs +++ b/src/DotNetOAuth.Test/Scenarios/AppendixScenarios.cs @@ -8,45 +8,50 @@ namespace DotNetOAuth.Test { using System;
using System.Collections.Specialized;
using System.IO;
+ using System.Linq;
using System.Net;
using System.Web;
using DotNetOAuth.Messaging;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DotNetOAuth.Test.Scenarios;
using DotNetOAuth.ChannelElements;
+ using System.Collections.Generic;
+ using DotNetOAuth.Test.Mocks;
[TestClass]
public class AppendixScenarios : TestBase {
[TestMethod]
public void SpecAppendixAExample() {
- ServiceProvider sp = new ServiceProvider {
+ ServiceProviderEndpoints spEndpoints = new ServiceProviderEndpoints() {
RequestTokenEndpoint = new ServiceProviderEndpoint("https://photos.example.net/request_token", HttpDeliveryMethod.PostRequest),
UserAuthorizationEndpoint = new ServiceProviderEndpoint("http://photos.example.net/authorize", HttpDeliveryMethod.GetRequest),
AccessTokenEndpoint = new ServiceProviderEndpoint("https://photos.example.net/access_token", HttpDeliveryMethod.PostRequest),
};
+ var tokenManager = new InMemoryTokenManager();
+ var sp = new ServiceProvider(spEndpoints, tokenManager);
+ Consumer consumer = new Consumer {
+ ConsumerKey = "dpf43f3p2l4k3l03",
+ ConsumerSecret = "kd94hf93k423kf44",
+ ServiceProvider = spEndpoints,
+ };
Coordinator coordinator = new Coordinator(
channel => {
- Consumer consumer = new Consumer {
- Channel = channel,
- ConsumerKey = "dpf43f3p2l4k3l03",
- ConsumerSecret = "kd94hf93k423kf44",
- ServiceProvider = sp,
- };
-
+ consumer.Channel = channel;
string requestTokenSecret = consumer.RequestUserAuthorization(new Uri("http://printer.example.com/request_token_ready"));
var accessTokenMessage = consumer.ProcessUserAuthorization(requestTokenSecret);
},
channel => {
+ tokenManager.AddConsumer(consumer.ConsumerKey, consumer.ConsumerSecret);
sp.Channel = channel;
var requestTokenMessage = sp.ReadTokenRequest();
- sp.SendUnauthorizedTokenResponse("hh5s93j4hdidpola", "hdhd0244k9j7ao03");
+ sp.SendUnauthorizedTokenResponse(requestTokenMessage);
var authRequest = sp.ReadAuthorizationRequest();
sp.SendAuthorizationResponse(authRequest);
var accessRequest = sp.ReadAccessTokenRequest();
- sp.SendAccessToken("nnch734d00sl2jdk", "pfkkdhi9sl3r4s00");
+ sp.SendAccessToken(accessRequest);
});
- coordinator.SigningElement = new PlainTextSigningBindingElement();
+ coordinator.SigningElement = (SigningBindingElementBase)sp.Channel.BindingElements.Single(el => el is SigningBindingElementBase);
coordinator.Start();
}
}
diff --git a/src/DotNetOAuth.Test/Scenarios/CoordinatingOAuthChannel.cs b/src/DotNetOAuth.Test/Scenarios/CoordinatingOAuthChannel.cs index 1de449a..2a42983 100644 --- a/src/DotNetOAuth.Test/Scenarios/CoordinatingOAuthChannel.cs +++ b/src/DotNetOAuth.Test/Scenarios/CoordinatingOAuthChannel.cs @@ -16,6 +16,7 @@ namespace DotNetOAuth.Test.Scenarios { using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DotNetOAuth.Messaging.Reflection;
+ using DotNetOAuth.Messages;
/// <summary>
/// A special channel used in test simulations to pass messages directly between two parties.
@@ -92,8 +93,10 @@ namespace DotNetOAuth.Test.Scenarios { directedMessage.Recipient,
directedMessage.HttpMethods);
cloned = (T)ctor.Invoke(new object[] { endpoint });
+ } else if ((ctor = message.GetType().GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[0], null)) != null) {
+ cloned = (T)ctor.Invoke(new object[0]);
} else {
- throw new InvalidOperationException("Unrecognized constructor signature.");
+ throw new InvalidOperationException("Unrecognized constructor signature on type " + message.GetType());
}
} else {
cloned = (T)Activator.CreateInstance(message.GetType(), true);
diff --git a/src/DotNetOAuth.Test/ServiceProviderTests.cs b/src/DotNetOAuth.Test/ServiceProviderEndpointsTests.cs index 001bacf..513f880 100644 --- a/src/DotNetOAuth.Test/ServiceProviderTests.cs +++ b/src/DotNetOAuth.Test/ServiceProviderEndpointsTests.cs @@ -1,5 +1,5 @@ //-----------------------------------------------------------------------
-// <copyright file="ServiceProviderTests.cs" company="Andrew Arnott">
+// <copyright file="ServiceProviderEndpointsTests.cs" company="Andrew Arnott">
// Copyright (c) Andrew Arnott. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
@@ -10,16 +10,16 @@ namespace DotNetOAuth.Test { using Microsoft.VisualStudio.TestTools.UnitTesting;
/// <summary>
- /// Tests for the <see cref="ServiceProvider"/> class.
+ /// Tests for the <see cref="ServiceProviderEndpoints"/> class.
/// </summary>
[TestClass]
- public class ServiceProviderTests : TestBase {
+ public class ServiceProviderEndpointsTests : TestBase {
/// <summary>
/// A test for UserAuthorizationUri
/// </summary>
[TestMethod]
public void UserAuthorizationUriTest() {
- ServiceProvider target = new ServiceProvider();
+ ServiceProviderEndpoints target = new ServiceProviderEndpoints();
ServiceProviderEndpoint expected = new ServiceProviderEndpoint("http://localhost/authorization", HttpDeliveryMethod.GetRequest);
ServiceProviderEndpoint actual;
target.UserAuthorizationEndpoint = expected;
@@ -35,7 +35,7 @@ namespace DotNetOAuth.Test { /// </summary>
[TestMethod]
public void RequestTokenUriTest() {
- ServiceProvider target = new ServiceProvider();
+ var target = new ServiceProviderEndpoints();
ServiceProviderEndpoint expected = new ServiceProviderEndpoint("http://localhost/requesttoken", HttpDeliveryMethod.GetRequest);
ServiceProviderEndpoint actual;
target.RequestTokenEndpoint = expected;
@@ -52,7 +52,7 @@ namespace DotNetOAuth.Test { /// </summary>
[TestMethod, ExpectedException(typeof(ArgumentException))]
public void RequestTokenUriWithOAuthParametersTest() {
- ServiceProvider target = new ServiceProvider();
+ var target = new ServiceProviderEndpoints();
target.RequestTokenEndpoint = new ServiceProviderEndpoint("http://localhost/requesttoken?oauth_token=something", HttpDeliveryMethod.GetRequest);
}
@@ -61,7 +61,7 @@ namespace DotNetOAuth.Test { /// </summary>
[TestMethod]
public void AccessTokenUriTest() {
- ServiceProvider target = new ServiceProvider();
+ var target = new ServiceProviderEndpoints();
ServiceProviderEndpoint expected = new ServiceProviderEndpoint("http://localhost/accesstoken", HttpDeliveryMethod.GetRequest);
ServiceProviderEndpoint actual;
target.AccessTokenEndpoint = expected;
|