summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2008-10-08 16:28:02 -0700
committerAndrew <andrewarnott@gmail.com>2008-10-08 16:28:02 -0700
commit3efc61b2de33ec9b6c5d3b0b2e42f0eb74bc7327 (patch)
tree3820d7c44bc409042f0d3aabc3092b0b082309ec /src
parent1e707db5f5551a545ad0bbcc71df9d19f2a79029 (diff)
downloadDotNetOpenAuth-3efc61b2de33ec9b6c5d3b0b2e42f0eb74bc7327.zip
DotNetOpenAuth-3efc61b2de33ec9b6c5d3b0b2e42f0eb74bc7327.tar.gz
DotNetOpenAuth-3efc61b2de33ec9b6c5d3b0b2e42f0eb74bc7327.tar.bz2
Moved more code into the scenario coordinator and out of the individual scenario.
Diffstat (limited to 'src')
-rw-r--r--src/DotNetOAuth.Test/ConsumerDescription.cs35
-rw-r--r--src/DotNetOAuth.Test/DotNetOAuth.Test.csproj1
-rw-r--r--src/DotNetOAuth.Test/Scenarios/AppendixScenarios.cs7
-rw-r--r--src/DotNetOAuth.Test/Scenarios/CoordinatingOAuthChannel.cs13
-rw-r--r--src/DotNetOAuth.Test/Scenarios/Coordinator.cs23
5 files changed, 57 insertions, 22 deletions
diff --git a/src/DotNetOAuth.Test/ConsumerDescription.cs b/src/DotNetOAuth.Test/ConsumerDescription.cs
new file mode 100644
index 0000000..2c73a72
--- /dev/null
+++ b/src/DotNetOAuth.Test/ConsumerDescription.cs
@@ -0,0 +1,35 @@
+//-----------------------------------------------------------------------
+// <copyright file="ConsumerDescription.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOAuth.Test {
+ /// <summary>
+ /// Information necessary to initialize a <see cref="Consumer"/>,
+ /// and to tell a <see cref="ServiceProvider"/> about it.
+ /// </summary>
+ internal class ConsumerDescription {
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ConsumerDescription"/> class.
+ /// </summary>
+ /// <param name="key">The consumer key.</param>
+ /// <param name="secret">The consumer secret.</param>
+ internal ConsumerDescription(string key, string secret) {
+ this.ConsumerKey = key;
+ this.ConsumerSecret = secret;
+ }
+
+ /// <summary>
+ /// Gets or sets the consumer key.
+ /// </summary>
+ /// <value>The consumer key.</value>
+ internal string ConsumerKey { get; set; }
+
+ /// <summary>
+ /// Gets or sets the consumer secret.
+ /// </summary>
+ /// <value>The consumer secret.</value>
+ internal string ConsumerSecret { get; set; }
+ }
+}
diff --git a/src/DotNetOAuth.Test/DotNetOAuth.Test.csproj b/src/DotNetOAuth.Test/DotNetOAuth.Test.csproj
index 19917ea..35af966 100644
--- a/src/DotNetOAuth.Test/DotNetOAuth.Test.csproj
+++ b/src/DotNetOAuth.Test/DotNetOAuth.Test.csproj
@@ -60,6 +60,7 @@
<ItemGroup>
<Compile Include="ChannelElements\SigningBindingElementBaseTests.cs" />
<Compile Include="ChannelElements\HmacSha1SigningBindingElementTests.cs" />
+ <Compile Include="ConsumerDescription.cs" />
<Compile Include="Messaging\CollectionAssert.cs" />
<Compile Include="Messaging\MessageSerializerTests.cs" />
<Compile Include="Messaging\Reflection\MessageDescriptionTests.cs" />
diff --git a/src/DotNetOAuth.Test/Scenarios/AppendixScenarios.cs b/src/DotNetOAuth.Test/Scenarios/AppendixScenarios.cs
index 46d7950..dfc7b8a 100644
--- a/src/DotNetOAuth.Test/Scenarios/AppendixScenarios.cs
+++ b/src/DotNetOAuth.Test/Scenarios/AppendixScenarios.cs
@@ -29,14 +29,12 @@ namespace DotNetOAuth.Test {
},
};
MessageReceivingEndpoint accessPhotoEndpoint = new MessageReceivingEndpoint("http://photos.example.net/photos?file=vacation.jpg&size=original", HttpDeliveryMethod.AuthorizationHeaderRequest | HttpDeliveryMethod.GetRequest);
- string consumerKey = "dpf43f3p2l4k3l03";
- string consumerSecret = "kd94hf93k423kf44";
+ ConsumerDescription consumerDescription = new ConsumerDescription("dpf43f3p2l4k3l03", "kd94hf93k423kf44");
Coordinator coordinator = new Coordinator(
+ consumerDescription,
serviceDescription,
consumer => {
- consumer.ConsumerKey = consumerKey;
- consumer.ConsumerSecret = consumerSecret;
consumer.RequestUserAuthorization(new Uri("http://printer.example.com/request_token_ready"), null, null);
string accessToken = consumer.ProcessUserAuthorization().AccessToken;
var photoRequest = consumer.CreateAuthorizedRequestInternal(accessPhotoEndpoint, accessToken);
@@ -47,7 +45,6 @@ namespace DotNetOAuth.Test {
Assert.AreNotEqual(0, protectedPhoto.ResponseStream.Length);
},
sp => {
- ((InMemoryTokenManager)sp.TokenManager).AddConsumer(consumerKey, consumerSecret);
var requestTokenMessage = sp.ReadTokenRequest();
sp.SendUnauthorizedTokenResponse(requestTokenMessage, null);
var authRequest = sp.ReadAuthorizationRequest();
diff --git a/src/DotNetOAuth.Test/Scenarios/CoordinatingOAuthChannel.cs b/src/DotNetOAuth.Test/Scenarios/CoordinatingOAuthChannel.cs
index 06cdf87..4aa85f5 100644
--- a/src/DotNetOAuth.Test/Scenarios/CoordinatingOAuthChannel.cs
+++ b/src/DotNetOAuth.Test/Scenarios/CoordinatingOAuthChannel.cs
@@ -30,19 +30,8 @@ namespace DotNetOAuth.Test.Scenarios {
/// The signing element for the Consumer to use. Null for the Service Provider.
/// </param>
/// <param name="isConsumer">True if this channel is constructed for a Consumer.</param>
- internal CoordinatingOAuthChannel(ITamperProtectionChannelBindingElement signingBindingElement, bool isConsumer)
- : this(signingBindingElement, isConsumer, new InMemoryTokenManager()) {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="CoordinatingOAuthChannel"/> class for Consumers.
- /// </summary>
- /// <param name="signingBindingElement">
- /// The signing element for the Consumer to use. Null for the Service Provider.
- /// </param>
- /// <param name="isConsumer">True if this channel is constructed for a Consumer.</param>
/// <param name="tokenManager">The token manager to use.</param>
- private CoordinatingOAuthChannel(ITamperProtectionChannelBindingElement signingBindingElement, bool isConsumer, ITokenManager tokenManager)
+ internal CoordinatingOAuthChannel(ITamperProtectionChannelBindingElement signingBindingElement, bool isConsumer, ITokenManager tokenManager)
: base(
signingBindingElement,
new NonceMemoryStore(StandardExpirationBindingElement.DefaultMaximumMessageAge),
diff --git a/src/DotNetOAuth.Test/Scenarios/Coordinator.cs b/src/DotNetOAuth.Test/Scenarios/Coordinator.cs
index 67b4257..a529653 100644
--- a/src/DotNetOAuth.Test/Scenarios/Coordinator.cs
+++ b/src/DotNetOAuth.Test/Scenarios/Coordinator.cs
@@ -16,15 +16,20 @@ namespace DotNetOAuth.Test.Scenarios {
/// Runs a Consumer and Service Provider simultaneously so they can interact in a full simulation.
/// </summary>
internal class Coordinator {
+ private ConsumerDescription consumerDescription;
private ServiceProviderDescription serviceDescription;
private Action<Consumer> consumerAction;
private Action<ServiceProvider> serviceProviderAction;
/// <summary>Initializes a new instance of the <see cref="Coordinator"/> class.</summary>
+ /// <param name="consumerDescription">The description of the consumer.</param>
/// <param name="serviceDescription">The service description that will be used to construct the Consumer and ServiceProvider objects.</param>
/// <param name="consumerAction">The code path of the Consumer.</param>
/// <param name="serviceProviderAction">The code path of the Service Provider.</param>
- internal Coordinator(ServiceProviderDescription serviceDescription, Action<Consumer> consumerAction, Action<ServiceProvider> serviceProviderAction) {
+ internal Coordinator(ConsumerDescription consumerDescription, ServiceProviderDescription serviceDescription, Action<Consumer> consumerAction, Action<ServiceProvider> serviceProviderAction) {
+ if (consumerDescription == null) {
+ throw new ArgumentNullException("consumerDescription");
+ }
if (serviceDescription == null) {
throw new ArgumentNullException("serviceDescription");
}
@@ -35,6 +40,7 @@ namespace DotNetOAuth.Test.Scenarios {
throw new ArgumentNullException("serviceProviderAction");
}
+ this.consumerDescription = consumerDescription;
this.serviceDescription = serviceDescription;
this.consumerAction = consumerAction;
this.serviceProviderAction = serviceProviderAction;
@@ -49,17 +55,24 @@ namespace DotNetOAuth.Test.Scenarios {
var consumerSigningElement = signingElement.Clone();
var spSigningElement = signingElement.Clone();
+ // Prepare token managers
+ InMemoryTokenManager consumerTokenManager = new InMemoryTokenManager();
+ InMemoryTokenManager serviceTokenManager = new InMemoryTokenManager();
+ serviceTokenManager.AddConsumer(this.consumerDescription.ConsumerKey, this.consumerDescription.ConsumerSecret);
+
// Prepare channels that will pass messages directly back and forth.
- CoordinatingOAuthChannel consumerChannel = new CoordinatingOAuthChannel(consumerSigningElement, true);
- CoordinatingOAuthChannel serviceProviderChannel = new CoordinatingOAuthChannel(spSigningElement, false);
+ CoordinatingOAuthChannel consumerChannel = new CoordinatingOAuthChannel(consumerSigningElement, true, consumerTokenManager);
+ CoordinatingOAuthChannel serviceProviderChannel = new CoordinatingOAuthChannel(spSigningElement, false, serviceTokenManager);
consumerChannel.RemoteChannel = serviceProviderChannel;
serviceProviderChannel.RemoteChannel = consumerChannel;
// Prepare the Consumer and Service Provider objects
- Consumer consumer = new Consumer(this.serviceDescription, new InMemoryTokenManager()) {
+ Consumer consumer = new Consumer(this.serviceDescription, consumerTokenManager) {
Channel = consumerChannel,
+ ConsumerKey = this.consumerDescription.ConsumerKey,
+ ConsumerSecret = this.consumerDescription.ConsumerSecret,
};
- ServiceProvider serviceProvider = new ServiceProvider(this.serviceDescription, new InMemoryTokenManager()) {
+ ServiceProvider serviceProvider = new ServiceProvider(this.serviceDescription, serviceTokenManager) {
Channel = serviceProviderChannel,
};