summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2009-06-25 21:15:29 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2009-06-25 21:15:29 -0700
commite5dca302cd99fd8b5ba65194892edfb33c7bac1c (patch)
tree2a6c6556aee59f13bff6b903410d51c80a705015
parent3b2fe4819cf449d1ab88178d055239c64b3cfd5e (diff)
downloadDotNetOpenAuth-e5dca302cd99fd8b5ba65194892edfb33c7bac1c.zip
DotNetOpenAuth-e5dca302cd99fd8b5ba65194892edfb33c7bac1c.tar.gz
DotNetOpenAuth-e5dca302cd99fd8b5ba65194892edfb33c7bac1c.tar.bz2
Fixed up all tests so they pass.
-rw-r--r--src/DotNetOpenAuth.Test/CoordinatorBase.cs1
-rw-r--r--src/DotNetOpenAuth.Test/Messaging/ChannelTests.cs1
-rw-r--r--src/DotNetOpenAuth.Test/Messaging/ResponseTests.cs1
-rw-r--r--src/DotNetOpenAuth.Test/OAuth/ChannelElements/PlaintextSigningBindingElementTest.cs6
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/Messages/IndirectSignedResponseTests.cs2
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/Provider/OpenIdProviderTests.cs2
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/XriIdentifierTests.cs2
-rw-r--r--src/DotNetOpenAuth.Test/TestBase.cs11
-rw-r--r--src/DotNetOpenAuth.sln4
-rw-r--r--src/DotNetOpenAuth/Messaging/Channel.cs2
-rw-r--r--src/DotNetOpenAuth/Messaging/ErrorUtilities.cs3
-rw-r--r--src/DotNetOpenAuth/Messaging/OutgoingWebResponse.cs2
-rw-r--r--src/DotNetOpenAuth/OpenId/Provider/OpenIdProvider.cs8
-rw-r--r--src/DotNetOpenAuth/OpenId/XriIdentifier.cs2
14 files changed, 35 insertions, 12 deletions
diff --git a/src/DotNetOpenAuth.Test/CoordinatorBase.cs b/src/DotNetOpenAuth.Test/CoordinatorBase.cs
index 458ec5e..df331f3 100644
--- a/src/DotNetOpenAuth.Test/CoordinatorBase.cs
+++ b/src/DotNetOpenAuth.Test/CoordinatorBase.cs
@@ -39,6 +39,7 @@ namespace DotNetOpenAuth.Test {
// terminate the other thread and inform the test host that the test failed.
Action<Action> safeWrapper = (action) => {
try {
+ TestBase.SetMockHttpContext();
action();
} catch (Exception ex) {
// We may be the second thread in an ThreadAbortException, so check the "flag"
diff --git a/src/DotNetOpenAuth.Test/Messaging/ChannelTests.cs b/src/DotNetOpenAuth.Test/Messaging/ChannelTests.cs
index 669abbc..7846411 100644
--- a/src/DotNetOpenAuth.Test/Messaging/ChannelTests.cs
+++ b/src/DotNetOpenAuth.Test/Messaging/ChannelTests.cs
@@ -201,6 +201,7 @@ namespace DotNetOpenAuth.Test.Messaging {
[TestMethod, ExpectedException(typeof(InvalidOperationException))]
public void ReadFromRequestNoContext() {
+ HttpContext.Current = null;
TestBadChannel badChannel = new TestBadChannel(false);
badChannel.ReadFromRequest();
}
diff --git a/src/DotNetOpenAuth.Test/Messaging/ResponseTests.cs b/src/DotNetOpenAuth.Test/Messaging/ResponseTests.cs
index a0e7c3f..89d165a 100644
--- a/src/DotNetOpenAuth.Test/Messaging/ResponseTests.cs
+++ b/src/DotNetOpenAuth.Test/Messaging/ResponseTests.cs
@@ -15,6 +15,7 @@ namespace DotNetOpenAuth.Test.Messaging {
public class ResponseTests : TestBase {
[TestMethod, ExpectedException(typeof(InvalidOperationException))]
public void SendWithoutAspNetContext() {
+ HttpContext.Current = null;
new OutgoingWebResponse().Send();
}
diff --git a/src/DotNetOpenAuth.Test/OAuth/ChannelElements/PlaintextSigningBindingElementTest.cs b/src/DotNetOpenAuth.Test/OAuth/ChannelElements/PlaintextSigningBindingElementTest.cs
index 627db8f..01d51a3 100644
--- a/src/DotNetOpenAuth.Test/OAuth/ChannelElements/PlaintextSigningBindingElementTest.cs
+++ b/src/DotNetOpenAuth.Test/OAuth/ChannelElements/PlaintextSigningBindingElementTest.cs
@@ -9,6 +9,7 @@ namespace DotNetOpenAuth.Test.ChannelElements {
using DotNetOpenAuth.OAuth;
using DotNetOpenAuth.OAuth.ChannelElements;
using DotNetOpenAuth.OAuth.Messages;
+ using DotNetOpenAuth.Test.Mocks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
@@ -16,6 +17,7 @@ namespace DotNetOpenAuth.Test.ChannelElements {
[TestMethod]
public void HttpsSignatureGeneration() {
SigningBindingElementBase target = new PlaintextSigningBindingElement();
+ target.Channel = new TestChannel();
MessageReceivingEndpoint endpoint = new MessageReceivingEndpoint("https://localtest", HttpDeliveryMethods.GetRequest);
ITamperResistantOAuthMessage message = new UnauthorizedTokenRequest(endpoint, Protocol.Default.Version);
message.ConsumerSecret = "cs";
@@ -29,6 +31,7 @@ namespace DotNetOpenAuth.Test.ChannelElements {
public void HttpsSignatureVerification() {
MessageReceivingEndpoint endpoint = new MessageReceivingEndpoint("https://localtest", HttpDeliveryMethods.GetRequest);
ITamperProtectionChannelBindingElement target = new PlaintextSigningBindingElement();
+ target.Channel = new TestChannel();
ITamperResistantOAuthMessage message = new UnauthorizedTokenRequest(endpoint, Protocol.Default.Version);
message.ConsumerSecret = "cs";
message.TokenSecret = "ts";
@@ -40,6 +43,7 @@ namespace DotNetOpenAuth.Test.ChannelElements {
[TestMethod]
public void HttpsSignatureVerificationNotApplicable() {
SigningBindingElementBase target = new PlaintextSigningBindingElement();
+ target.Channel = new TestChannel();
MessageReceivingEndpoint endpoint = new MessageReceivingEndpoint("https://localtest", HttpDeliveryMethods.GetRequest);
ITamperResistantOAuthMessage message = new UnauthorizedTokenRequest(endpoint, Protocol.Default.Version);
message.ConsumerSecret = "cs";
@@ -52,6 +56,7 @@ namespace DotNetOpenAuth.Test.ChannelElements {
[TestMethod]
public void HttpSignatureGeneration() {
SigningBindingElementBase target = new PlaintextSigningBindingElement();
+ target.Channel = new TestChannel();
MessageReceivingEndpoint endpoint = new MessageReceivingEndpoint("http://localtest", HttpDeliveryMethods.GetRequest);
ITamperResistantOAuthMessage message = new UnauthorizedTokenRequest(endpoint, Protocol.Default.Version);
message.ConsumerSecret = "cs";
@@ -66,6 +71,7 @@ namespace DotNetOpenAuth.Test.ChannelElements {
[TestMethod]
public void HttpSignatureVerification() {
SigningBindingElementBase target = new PlaintextSigningBindingElement();
+ target.Channel = new TestChannel();
MessageReceivingEndpoint endpoint = new MessageReceivingEndpoint("http://localtest", HttpDeliveryMethods.GetRequest);
ITamperResistantOAuthMessage message = new UnauthorizedTokenRequest(endpoint, Protocol.Default.Version);
message.ConsumerSecret = "cs";
diff --git a/src/DotNetOpenAuth.Test/OpenId/Messages/IndirectSignedResponseTests.cs b/src/DotNetOpenAuth.Test/OpenId/Messages/IndirectSignedResponseTests.cs
index e140b24..8b0937a 100644
--- a/src/DotNetOpenAuth.Test/OpenId/Messages/IndirectSignedResponseTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/Messages/IndirectSignedResponseTests.cs
@@ -127,7 +127,7 @@ namespace DotNetOpenAuth.Test.OpenId.Messages {
}
}
- [TestMethod, ExpectedException(typeof(ArgumentNullException))]
+ [TestMethod, ExpectedException(typeof(ArgumentException))]
public void GetReturnToArgumentNullKey() {
this.response.GetReturnToArgument(null);
}
diff --git a/src/DotNetOpenAuth.Test/OpenId/Provider/OpenIdProviderTests.cs b/src/DotNetOpenAuth.Test/OpenId/Provider/OpenIdProviderTests.cs
index 28b2b55..7c92389 100644
--- a/src/DotNetOpenAuth.Test/OpenId/Provider/OpenIdProviderTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/Provider/OpenIdProviderTests.cs
@@ -6,6 +6,7 @@
namespace DotNetOpenAuth.Test.OpenId.Provider {
using System;
+ using System.Web;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OpenId;
using DotNetOpenAuth.OpenId.Extensions;
@@ -73,6 +74,7 @@ namespace DotNetOpenAuth.Test.OpenId.Provider {
/// </summary>
[TestMethod, ExpectedException(typeof(InvalidOperationException))]
public void GetRequestNoContext() {
+ HttpContext.Current = null;
this.provider.GetRequest();
}
diff --git a/src/DotNetOpenAuth.Test/OpenId/XriIdentifierTests.cs b/src/DotNetOpenAuth.Test/OpenId/XriIdentifierTests.cs
index 87ecd4b..46427bb 100644
--- a/src/DotNetOpenAuth.Test/OpenId/XriIdentifierTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/XriIdentifierTests.cs
@@ -22,7 +22,7 @@ namespace DotNetOpenAuth.Test.OpenId {
base.SetUp();
}
- [TestMethod, ExpectedException(typeof(ArgumentNullException))]
+ [TestMethod, ExpectedException(typeof(ArgumentException))]
public void CtorNull() {
new XriIdentifier(null);
}
diff --git a/src/DotNetOpenAuth.Test/TestBase.cs b/src/DotNetOpenAuth.Test/TestBase.cs
index d21691b..b90d7b5 100644
--- a/src/DotNetOpenAuth.Test/TestBase.cs
+++ b/src/DotNetOpenAuth.Test/TestBase.cs
@@ -7,6 +7,7 @@
namespace DotNetOpenAuth.Test {
using System.IO;
using System.Reflection;
+ using System.Web;
using DotNetOpenAuth.Messaging.Reflection;
using DotNetOpenAuth.OAuth.Messages;
using log4net;
@@ -48,6 +49,7 @@ namespace DotNetOpenAuth.Test {
log4net.Config.XmlConfigurator.Configure(Assembly.GetExecutingAssembly().GetManifestResourceStream("DotNetOpenAuth.Test.Logging.config"));
MessageBase.LowSecurityMode = true;
this.messageDescriptions = new MessageDescriptionCollection();
+ SetMockHttpContext();
}
/// <summary>
@@ -57,5 +59,14 @@ namespace DotNetOpenAuth.Test {
public virtual void Cleanup() {
log4net.LogManager.Shutdown();
}
+
+ /// <summary>
+ /// Sets HttpContext.Current to some empty (but non-null!) value.
+ /// </summary>
+ protected internal static void SetMockHttpContext() {
+ HttpContext.Current = new HttpContext(
+ new HttpRequest("mock", "http://mock", "mock"),
+ new HttpResponse(new StringWriter()));
+ }
}
}
diff --git a/src/DotNetOpenAuth.sln b/src/DotNetOpenAuth.sln
index 9e3c0af..0a156c4 100644
--- a/src/DotNetOpenAuth.sln
+++ b/src/DotNetOpenAuth.sln
@@ -76,7 +76,7 @@ Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "InfoCardRelyingParty", "..\
Release.AspNetCompiler.ForceOverwrite = "true"
Release.AspNetCompiler.FixedNames = "false"
Release.AspNetCompiler.Debug = "False"
- VWDPort = "4490"
+ VWDPort = "59719"
DefaultWebSiteLanguage = "Visual Basic"
EndProjectSection
EndProject
@@ -130,7 +130,7 @@ Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "OAuthConsumer", "..\samples
Release.AspNetCompiler.ForceOverwrite = "true"
Release.AspNetCompiler.FixedNames = "false"
Release.AspNetCompiler.Debug = "False"
- VWDPort = "10335"
+ VWDPort = "59721"
EndProjectSection
EndProject
Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "OAuthServiceProvider", "..\samples\OAuthServiceProvider", "{7ADCCD5C-AC2B-4340-9410-FE3A31A48191}"
diff --git a/src/DotNetOpenAuth/Messaging/Channel.cs b/src/DotNetOpenAuth/Messaging/Channel.cs
index 15e4f76..df56b31 100644
--- a/src/DotNetOpenAuth/Messaging/Channel.cs
+++ b/src/DotNetOpenAuth/Messaging/Channel.cs
@@ -224,7 +224,7 @@ namespace DotNetOpenAuth.Messaging {
/// Requires an HttpContext.Current context.
/// </remarks>
public void Send(IProtocolMessage message) {
- Contract.Requires<InvalidOperationException>(HttpContext.Current != null);
+ Contract.Requires<InvalidOperationException>(HttpContext.Current != null, MessagingStrings.CurrentHttpContextRequired);
Contract.Requires<ArgumentNullException>(message != null);
this.PrepareResponse(message).Send();
}
diff --git a/src/DotNetOpenAuth/Messaging/ErrorUtilities.cs b/src/DotNetOpenAuth/Messaging/ErrorUtilities.cs
index 88a1243..b7b2c55 100644
--- a/src/DotNetOpenAuth/Messaging/ErrorUtilities.cs
+++ b/src/DotNetOpenAuth/Messaging/ErrorUtilities.cs
@@ -396,7 +396,8 @@ namespace DotNetOpenAuth.Messaging {
/// <exception cref="ArgumentException">Thrown if <paramref name="value"/> has zero length.</exception>
[Pure]
internal static void VerifyNonZeroLength(string value, string paramName) {
- Contract.Requires((value != null && value.Length > 0) || !string.IsNullOrEmpty(value));
+ Contract.Ensures((value != null && value.Length > 0) && !string.IsNullOrEmpty(value));
+ Contract.EnsuresOnThrow<ArgumentException>(value == null || value.Length == 0);
VerifyArgumentNotNull(value, paramName);
if (value.Length == 0) {
throw new ArgumentException(MessagingStrings.UnexpectedEmptyString, paramName);
diff --git a/src/DotNetOpenAuth/Messaging/OutgoingWebResponse.cs b/src/DotNetOpenAuth/Messaging/OutgoingWebResponse.cs
index 5ce1f85..ba23a40 100644
--- a/src/DotNetOpenAuth/Messaging/OutgoingWebResponse.cs
+++ b/src/DotNetOpenAuth/Messaging/OutgoingWebResponse.cs
@@ -120,7 +120,7 @@ namespace DotNetOpenAuth.Messaging {
/// Requires a current HttpContext.
/// </remarks>
public virtual void Send() {
- Contract.Requires(HttpContext.Current != null);
+ Contract.Requires<InvalidOperationException>(HttpContext.Current != null, MessagingStrings.CurrentHttpContextRequired);
ErrorUtilities.VerifyHttpContext();
this.Send(HttpContext.Current);
diff --git a/src/DotNetOpenAuth/OpenId/Provider/OpenIdProvider.cs b/src/DotNetOpenAuth/OpenId/Provider/OpenIdProvider.cs
index 14a60a8..0fe7e5a 100644
--- a/src/DotNetOpenAuth/OpenId/Provider/OpenIdProvider.cs
+++ b/src/DotNetOpenAuth/OpenId/Provider/OpenIdProvider.cs
@@ -280,9 +280,9 @@ namespace DotNetOpenAuth.OpenId.Provider {
/// <exception cref="InvalidOperationException">Thrown if <see cref="IRequest.IsResponseReady"/> is <c>false</c>.</exception>
[SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily", Justification = "Code Contract requires that we cast early.")]
public void SendResponse(IRequest request) {
- Contract.Requires(HttpContext.Current != null);
+ Contract.Requires<InvalidOperationException>(HttpContext.Current != null, MessagingStrings.CurrentHttpContextRequired);
Contract.Requires<ArgumentNullException>(request != null);
- Contract.Requires(((Request)request).IsResponseReady);
+ Contract.Requires<ArgumentException>(((Request)request).IsResponseReady);
this.ApplyBehaviorsToResponse(request);
Request requestInternal = (Request)request;
@@ -321,9 +321,9 @@ namespace DotNetOpenAuth.OpenId.Provider {
/// be the same as <paramref name="claimedIdentifier"/>.</param>
/// <param name="extensions">The extensions.</param>
public void SendUnsolicitedAssertion(Uri providerEndpoint, Realm relyingParty, Identifier claimedIdentifier, Identifier localIdentifier, params IExtensionMessage[] extensions) {
- Contract.Requires(HttpContext.Current != null);
+ Contract.Requires<InvalidOperationException>(HttpContext.Current != null, MessagingStrings.HttpContextRequired);
Contract.Requires<ArgumentNullException>(providerEndpoint != null);
- Contract.Requires(providerEndpoint.IsAbsoluteUri);
+ Contract.Requires<ArgumentException>(providerEndpoint.IsAbsoluteUri);
Contract.Requires<ArgumentNullException>(relyingParty != null);
Contract.Requires<ArgumentNullException>(claimedIdentifier != null);
Contract.Requires<ArgumentNullException>(localIdentifier != null);
diff --git a/src/DotNetOpenAuth/OpenId/XriIdentifier.cs b/src/DotNetOpenAuth/OpenId/XriIdentifier.cs
index a6e3dfa..f58c14b 100644
--- a/src/DotNetOpenAuth/OpenId/XriIdentifier.cs
+++ b/src/DotNetOpenAuth/OpenId/XriIdentifier.cs
@@ -62,7 +62,7 @@ namespace DotNetOpenAuth.OpenId {
/// <param name="xri">The string value of the XRI.</param>
internal XriIdentifier(string xri)
: this(xri, false) {
- Contract.Requires((xri != null && xri.Length > 0) || !string.IsNullOrEmpty(xri));
+ Contract.Requires<ArgumentException>(!String.IsNullOrEmpty(xri));
}
/// <summary>