summaryrefslogtreecommitdiffstats
path: root/src/DotNetOAuth.Test
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2008-09-25 16:57:17 -0700
committerAndrew <andrewarnott@gmail.com>2008-09-25 16:57:17 -0700
commit50e34bfe7224576e901efa6748598d31c36df3a5 (patch)
tree4c9f820f54bb5578addbf064136f712dcf35c5c7 /src/DotNetOAuth.Test
parenta9fb696c40441e06ef817d7e28bae74c6a6cb6e4 (diff)
downloadDotNetOpenAuth-50e34bfe7224576e901efa6748598d31c36df3a5.zip
DotNetOpenAuth-50e34bfe7224576e901efa6748598d31c36df3a5.tar.gz
DotNetOpenAuth-50e34bfe7224576e901efa6748598d31c36df3a5.tar.bz2
Fixed lots of StyleCop issues and refacted Consumer/Service Provider a bit.
Diffstat (limited to 'src/DotNetOAuth.Test')
-rw-r--r--src/DotNetOAuth.Test/Mocks/InMemoryTokenManager.cs24
-rw-r--r--src/DotNetOAuth.Test/Scenarios/AppendixScenarios.cs24
-rw-r--r--src/DotNetOAuth.Test/Scenarios/CoordinatingOAuthChannel.cs29
-rw-r--r--src/DotNetOAuth.Test/Scenarios/Coordinator.cs18
4 files changed, 43 insertions, 52 deletions
diff --git a/src/DotNetOAuth.Test/Mocks/InMemoryTokenManager.cs b/src/DotNetOAuth.Test/Mocks/InMemoryTokenManager.cs
index 002eee1..0454fb8 100644
--- a/src/DotNetOAuth.Test/Mocks/InMemoryTokenManager.cs
+++ b/src/DotNetOAuth.Test/Mocks/InMemoryTokenManager.cs
@@ -1,4 +1,10 @@
-namespace DotNetOAuth.Test.Mocks {
+//-----------------------------------------------------------------------
+// <copyright file="InMemoryTokenManager.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOAuth.Test.Mocks {
using System;
using System.Collections.Generic;
using System.Linq;
@@ -6,32 +12,32 @@
using DotNetOAuth.ChannelElements;
internal class InMemoryTokenManager : ITokenManager {
- Dictionary<string, string> consumersAndSecrets = new Dictionary<string, string>();
- Dictionary<string, string> tokensAndSecrets = new Dictionary<string, string>();
+ private Dictionary<string, string> consumersAndSecrets = new Dictionary<string, string>();
+ private Dictionary<string, string> tokensAndSecrets = new Dictionary<string, string>();
#region ITokenManager Members
public string GetConsumerSecret(string consumerKey) {
- return consumersAndSecrets[consumerKey];
+ return this.consumersAndSecrets[consumerKey];
}
public string GetTokenSecret(string token) {
- return tokensAndSecrets[token];
+ return this.tokensAndSecrets[token];
}
public void StoreNewRequestToken(string consumerKey, string requestToken, string requestTokenSecret, IDictionary<string, string> parameters) {
- tokensAndSecrets[requestToken] = requestTokenSecret;
+ this.tokensAndSecrets[requestToken] = requestTokenSecret;
}
public void ExpireRequestTokenAndStoreNewAccessToken(string consumerKey, string requestToken, string accessToken, string accessTokenSecret) {
- tokensAndSecrets.Remove(requestToken);
- tokensAndSecrets[accessToken] = accessTokenSecret;
+ this.tokensAndSecrets.Remove(requestToken);
+ this.tokensAndSecrets[accessToken] = accessTokenSecret;
}
#endregion
internal void AddConsumer(string key, string secret) {
- consumersAndSecrets.Add(key, secret);
+ this.consumersAndSecrets.Add(key, secret);
}
}
}
diff --git a/src/DotNetOAuth.Test/Scenarios/AppendixScenarios.cs b/src/DotNetOAuth.Test/Scenarios/AppendixScenarios.cs
index 563fac3..aefa0ea 100644
--- a/src/DotNetOAuth.Test/Scenarios/AppendixScenarios.cs
+++ b/src/DotNetOAuth.Test/Scenarios/AppendixScenarios.cs
@@ -1,45 +1,39 @@
//-----------------------------------------------------------------------
-// <copyright file="Scenarios.cs" company="Andrew Arnott">
+// <copyright file="AppendixScenarios.cs" company="Andrew Arnott">
// Copyright (c) Andrew Arnott. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
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.Messaging;
using DotNetOAuth.Test.Mocks;
+ using DotNetOAuth.Test.Scenarios;
+ using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public class AppendixScenarios : TestBase {
[TestMethod]
public void SpecAppendixAExample() {
- ServiceProviderEndpoints spEndpoints = new ServiceProviderEndpoints() {
+ ServiceProviderEndpoints endpoints = 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 {
+ var sp = new ServiceProvider(endpoints, tokenManager);
+ Consumer consumer = new Consumer(endpoints, new InMemoryTokenManager()) {
ConsumerKey = "dpf43f3p2l4k3l03",
ConsumerSecret = "kd94hf93k423kf44",
- ServiceProvider = spEndpoints,
};
Coordinator coordinator = new Coordinator(
channel => {
consumer.Channel = channel;
- string requestTokenSecret = consumer.RequestUserAuthorization(new Uri("http://printer.example.com/request_token_ready"));
- var accessTokenMessage = consumer.ProcessUserAuthorization(requestTokenSecret);
+ consumer.RequestUserAuthorization(new Uri("http://printer.example.com/request_token_ready"));
+ var accessTokenMessage = consumer.ProcessUserAuthorization();
},
channel => {
tokenManager.AddConsumer(consumer.ConsumerKey, consumer.ConsumerSecret);
diff --git a/src/DotNetOAuth.Test/Scenarios/CoordinatingOAuthChannel.cs b/src/DotNetOAuth.Test/Scenarios/CoordinatingOAuthChannel.cs
index 2a42983..65254e2 100644
--- a/src/DotNetOAuth.Test/Scenarios/CoordinatingOAuthChannel.cs
+++ b/src/DotNetOAuth.Test/Scenarios/CoordinatingOAuthChannel.cs
@@ -6,22 +6,20 @@
namespace DotNetOAuth.Test.Scenarios {
using System;
- using System.Collections.Generic;
- using System.Linq;
using System.Reflection;
- using System.Text;
+ using System.Threading;
using DotNetOAuth.ChannelElements;
- using DotNetOAuth.Messaging.Bindings;
using DotNetOAuth.Messaging;
- using System.Threading;
- using Microsoft.VisualStudio.TestTools.UnitTesting;
+ using DotNetOAuth.Messaging.Bindings;
using DotNetOAuth.Messaging.Reflection;
- using DotNetOAuth.Messages;
/// <summary>
/// A special channel used in test simulations to pass messages directly between two parties.
/// </summary>
internal class CoordinatingOAuthChannel : OAuthChannel {
+ private EventWaitHandle incomingMessageSignal = new AutoResetEvent(false);
+ private IProtocolMessage incomingMessage;
+
/// <summary>
/// Initializes a new instance of the <see cref="CoordinatingOAuthChannel"/> class for Consumers.
/// </summary>
@@ -37,32 +35,29 @@ namespace DotNetOAuth.Test.Scenarios {
/// </summary>
internal CoordinatingOAuthChannel RemoteChannel { get; set; }
- private EventWaitHandle incomingMessageSignal = new AutoResetEvent(false);
- private IProtocolMessage incomingMessage;
-
protected override IProtocolMessage RequestInternal(IDirectedProtocolMessage request) {
TestBase.TestLogger.InfoFormat("Sending request: {0}", request);
// Drop the outgoing message in the other channel's in-slot and let them know it's there.
- RemoteChannel.incomingMessage = CloneSerializedParts(request);
- RemoteChannel.incomingMessageSignal.Set();
+ this.RemoteChannel.incomingMessage = CloneSerializedParts(request);
+ this.RemoteChannel.incomingMessageSignal.Set();
// Now wait for a response...
- return AwaitIncomingMessage();
+ return this.AwaitIncomingMessage();
}
protected override void SendDirectMessageResponse(IProtocolMessage response) {
TestBase.TestLogger.InfoFormat("Sending response: {0}", response);
- RemoteChannel.incomingMessage = CloneSerializedParts(response);
- RemoteChannel.incomingMessageSignal.Set();
+ this.RemoteChannel.incomingMessage = CloneSerializedParts(response);
+ this.RemoteChannel.incomingMessageSignal.Set();
}
protected override void SendIndirectMessage(IDirectedProtocolMessage message) {
TestBase.TestLogger.Info("Next response is an indirect message...");
// In this mock transport, direct and indirect messages are the same.
- SendDirectMessageResponse(message);
+ this.SendDirectMessageResponse(message);
}
protected override HttpRequestInfo GetRequestFromContext() {
- return new HttpRequestInfo(AwaitIncomingMessage());
+ return new HttpRequestInfo(this.AwaitIncomingMessage());
}
protected override IProtocolMessage ReadFromRequestInternal(HttpRequestInfo request) {
diff --git a/src/DotNetOAuth.Test/Scenarios/Coordinator.cs b/src/DotNetOAuth.Test/Scenarios/Coordinator.cs
index 45518a2..c3eaad6 100644
--- a/src/DotNetOAuth.Test/Scenarios/Coordinator.cs
+++ b/src/DotNetOAuth.Test/Scenarios/Coordinator.cs
@@ -6,11 +6,7 @@
namespace DotNetOAuth.Test.Scenarios {
using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
using System.Threading;
- using DotNetOAuth.Messaging;
using DotNetOAuth.ChannelElements;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -18,8 +14,8 @@ namespace DotNetOAuth.Test.Scenarios {
/// Runs a Consumer and Service Provider simultaneously so they can interact in a full simulation.
/// </summary>
internal class Coordinator {
- Actor consumerAction;
- Actor serviceProviderAction;
+ private Actor consumerAction;
+ private Actor serviceProviderAction;
/// <summary>Initializes a new instance of the <see cref="Coordinator"/> class.</summary>
/// <param name="consumerAction">The code path of the Consumer.</param>
@@ -36,6 +32,8 @@ namespace DotNetOAuth.Test.Scenarios {
this.serviceProviderAction = serviceProviderAction;
}
+ internal delegate void Actor(OAuthChannel channel);
+
/// <summary>
/// Gets or sets the signing element the Consumer channel should use.
/// </summary>
@@ -44,19 +42,17 @@ namespace DotNetOAuth.Test.Scenarios {
/// </remarks>
internal SigningBindingElementBase SigningElement { get; set; }
- internal delegate void Actor(OAuthChannel channel);
-
/// <summary>
/// Starts the simulation.
/// </summary>
internal void Start() {
- if (SigningElement == null) {
+ if (this.SigningElement == null) {
throw new InvalidOperationException("SigningElement must be set first.");
}
// Prepare channels that will pass messages directly back and forth.
- CoordinatingOAuthChannel consumerChannel = new CoordinatingOAuthChannel(SigningElement);
- CoordinatingOAuthChannel serviceProviderChannel = new CoordinatingOAuthChannel(SigningElement);
+ CoordinatingOAuthChannel consumerChannel = new CoordinatingOAuthChannel(this.SigningElement);
+ CoordinatingOAuthChannel serviceProviderChannel = new CoordinatingOAuthChannel(this.SigningElement);
consumerChannel.RemoteChannel = serviceProviderChannel;
serviceProviderChannel.RemoteChannel = consumerChannel;