summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2008-09-03 18:38:48 -0700
committerAndrew <andrewarnott@gmail.com>2008-09-03 18:38:48 -0700
commit871dc36214618e53ab682ab71413f925a78b27f5 (patch)
tree82576c7d8c8958abea86cc2724692a717a5ca6fc
parentefb71eb0514b352ed3fdbad75a8e8d885a94ce05 (diff)
downloadDotNetOpenAuth-871dc36214618e53ab682ab71413f925a78b27f5.zip
DotNetOpenAuth-871dc36214618e53ab682ab71413f925a78b27f5.tar.gz
DotNetOpenAuth-871dc36214618e53ab682ab71413f925a78b27f5.tar.bz2
More channel work and testing.
-rw-r--r--src/DotNetOAuth.Test/DotNetOAuth.Test.csproj1
-rw-r--r--src/DotNetOAuth.Test/Messaging/ChannelTests.cs21
-rw-r--r--src/DotNetOAuth.Test/Messaging/MessageSerializerTests.cs2
-rw-r--r--src/DotNetOAuth.Test/Mocks/TestDirectedMessage.cs47
-rw-r--r--src/DotNetOAuth/Logger.cs2
-rw-r--r--src/DotNetOAuth/Loggers/Log4NetLogger.cs2
-rw-r--r--src/DotNetOAuth/Messaging/Channel.cs2
-rw-r--r--src/DotNetOAuth/Messaging/IDirectedProtocolMessage.cs7
-rw-r--r--src/DotNetOAuth/Messaging/MessagingStrings.Designer.cs9
-rw-r--r--src/DotNetOAuth/Messaging/MessagingStrings.resx3
-rw-r--r--src/DotNetOAuth/Protocol.cs10
11 files changed, 90 insertions, 16 deletions
diff --git a/src/DotNetOAuth.Test/DotNetOAuth.Test.csproj b/src/DotNetOAuth.Test/DotNetOAuth.Test.csproj
index 769cd56..8f28791 100644
--- a/src/DotNetOAuth.Test/DotNetOAuth.Test.csproj
+++ b/src/DotNetOAuth.Test/DotNetOAuth.Test.csproj
@@ -61,6 +61,7 @@
<Compile Include="MessagingUtilitiesTest.cs" />
<Compile Include="Messaging\ChannelTests.cs" />
<Compile Include="Messaging\DictionaryXmlReaderTests.cs" />
+ <Compile Include="Mocks\TestDirectedMessage.cs" />
<Compile Include="Mocks\TestBadChannel.cs" />
<Compile Include="OAuthChannelTests.cs" />
<Compile Include="Messaging\MessageSerializerTests.cs" />
diff --git a/src/DotNetOAuth.Test/Messaging/ChannelTests.cs b/src/DotNetOAuth.Test/Messaging/ChannelTests.cs
index 3282788..a2909c4 100644
--- a/src/DotNetOAuth.Test/Messaging/ChannelTests.cs
+++ b/src/DotNetOAuth.Test/Messaging/ChannelTests.cs
@@ -38,12 +38,29 @@ namespace DotNetOAuth.Test.Messaging {
[TestMethod]
public void ReadFromRequestQueryString() {
- ParameterizedReceiveTest("GET");
+ this.ParameterizedReceiveTest("GET");
}
[TestMethod]
public void ReadFromRequestForm() {
- ParameterizedReceiveTest("POST");
+ this.ParameterizedReceiveTest("POST");
+ }
+
+ [TestMethod]
+ public void SendIndirectMessage() {
+ IProtocolMessage message = new TestDirectedMessage {
+ Age = 15,
+ Name = "Andrew",
+ Location = new Uri("http://host/path"),
+ Recipient = new Uri("http://provider/path"),
+ };
+ this.channel.Send(message);
+ Response response = this.channel.DequeueIndirectOrResponseMessage();
+ Assert.AreEqual(HttpStatusCode.Redirect, response.Status);
+ StringAssert.StartsWith(response.Headers[HttpResponseHeader.Location], "http://provider/path");
+ StringAssert.Contains(response.Headers[HttpResponseHeader.Location], "age=15");
+ StringAssert.Contains(response.Headers[HttpResponseHeader.Location], "Name=Andrew");
+ StringAssert.Contains(response.Headers[HttpResponseHeader.Location], "Location=http%3a%2f%2fhost%2fpath");
}
private static HttpRequestInfo CreateHttpRequest(string method, IDictionary<string, string> fields) {
diff --git a/src/DotNetOAuth.Test/Messaging/MessageSerializerTests.cs b/src/DotNetOAuth.Test/Messaging/MessageSerializerTests.cs
index 7224e84..5cb5375 100644
--- a/src/DotNetOAuth.Test/Messaging/MessageSerializerTests.cs
+++ b/src/DotNetOAuth.Test/Messaging/MessageSerializerTests.cs
@@ -52,7 +52,7 @@ namespace DotNetOAuth.Test.Messaging {
public void SerializeInvalidMessage() {
var serializer = MessageSerializer.Get(typeof(Mocks.TestMessage));
Dictionary<string, string> fields = new Dictionary<string, string>(StringComparer.Ordinal);
- Mocks.TestMessage message = new DotNetOAuth.Test.Mocks.TestMessage();
+ Mocks.TestMessage message = new Mocks.TestMessage();
message.EmptyMember = "invalidvalue";
serializer.Serialize(message);
}
diff --git a/src/DotNetOAuth.Test/Mocks/TestDirectedMessage.cs b/src/DotNetOAuth.Test/Mocks/TestDirectedMessage.cs
new file mode 100644
index 0000000..6972624
--- /dev/null
+++ b/src/DotNetOAuth.Test/Mocks/TestDirectedMessage.cs
@@ -0,0 +1,47 @@
+//-----------------------------------------------------------------------
+// <copyright file="TestDirectedMessage.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOAuth.Test.Mocks {
+ using System;
+ using System.Runtime.Serialization;
+ using DotNetOAuth.Messaging;
+
+ [DataContract(Namespace = Protocol.DataContractNamespaceV10)]
+ internal class TestDirectedMessage : IDirectedProtocolMessage {
+ [DataMember(Name = "age", IsRequired = true)]
+ public int Age { get; set; }
+ [DataMember]
+ public string Name { get; set; }
+ [DataMember]
+ public string EmptyMember { get; set; }
+ [DataMember]
+ public Uri Location { get; set; }
+
+ #region IDirectedProtocolMessage Members
+
+ public Uri Recipient { get; internal set; }
+
+ #endregion
+
+ #region IProtocolMessage Members
+
+ Protocol IProtocolMessage.Protocol {
+ get { return Protocol.V10; }
+ }
+
+ MessageTransport IProtocolMessage.Transport {
+ get { return MessageTransport.Direct; }
+ }
+
+ void IProtocolMessage.EnsureValidMessage() {
+ if (this.EmptyMember != null || this.Age < 0) {
+ throw new ProtocolException();
+ }
+ }
+
+ #endregion
+ }
+}
diff --git a/src/DotNetOAuth/Logger.cs b/src/DotNetOAuth/Logger.cs
index 844dcc6..206efca 100644
--- a/src/DotNetOAuth/Logger.cs
+++ b/src/DotNetOAuth/Logger.cs
@@ -11,7 +11,7 @@ namespace DotNetOAuth {
using log4net.Core;
/// <summary>
- /// A general logger for the entire YOURLIBNAME library.
+ /// A general logger for the entire DotNetOAuth library.
/// </summary>
/// <remarks>
/// Because this logger is intended for use with non-localized strings, the
diff --git a/src/DotNetOAuth/Loggers/Log4NetLogger.cs b/src/DotNetOAuth/Loggers/Log4NetLogger.cs
index 98fc8f2..352f8c2 100644
--- a/src/DotNetOAuth/Loggers/Log4NetLogger.cs
+++ b/src/DotNetOAuth/Loggers/Log4NetLogger.cs
@@ -205,7 +205,7 @@ namespace DotNetOAuth.Loggers {
/// </summary>
/// <returns>The created <see cref="ILog"/> instance.</returns>
private static ILog CreateLogger() {
- return new Log4NetLogger(log4net.LogManager.GetLogger("YOURLIBNAME"));
+ return new Log4NetLogger(log4net.LogManager.GetLogger("DotNetOAuth"));
}
}
}
diff --git a/src/DotNetOAuth/Messaging/Channel.cs b/src/DotNetOAuth/Messaging/Channel.cs
index 825f018..40261b1 100644
--- a/src/DotNetOAuth/Messaging/Channel.cs
+++ b/src/DotNetOAuth/Messaging/Channel.cs
@@ -128,7 +128,7 @@ namespace DotNetOAuth.Messaging {
this.ReportErrorToUser(exception);
}
} else {
- throw new InvalidOperationException();
+ throw new InvalidOperationException(MessagingStrings.DirectedMessageMissingRecipient);
}
}
}
diff --git a/src/DotNetOAuth/Messaging/IDirectedProtocolMessage.cs b/src/DotNetOAuth/Messaging/IDirectedProtocolMessage.cs
index 82ee08e..bebd303 100644
--- a/src/DotNetOAuth/Messaging/IDirectedProtocolMessage.cs
+++ b/src/DotNetOAuth/Messaging/IDirectedProtocolMessage.cs
@@ -13,11 +13,8 @@ namespace DotNetOAuth.Messaging {
/// </summary>
internal interface IDirectedProtocolMessage : IProtocolMessage {
/// <summary>
- /// Gets or sets the URL of the intended receiver of this message.
+ /// Gets the URL of the intended receiver of this message.
/// </summary>
- Uri Recipient {
- get;
- set;
- }
+ Uri Recipient { get; }
}
}
diff --git a/src/DotNetOAuth/Messaging/MessagingStrings.Designer.cs b/src/DotNetOAuth/Messaging/MessagingStrings.Designer.cs
index 60aadfb..98e8cc6 100644
--- a/src/DotNetOAuth/Messaging/MessagingStrings.Designer.cs
+++ b/src/DotNetOAuth/Messaging/MessagingStrings.Designer.cs
@@ -70,6 +70,15 @@ namespace DotNetOAuth.Messaging {
}
/// <summary>
+ /// Looks up a localized string similar to The directed message&apos;s Recipient property must not be null..
+ /// </summary>
+ internal static string DirectedMessageMissingRecipient {
+ get {
+ return ResourceManager.GetString("DirectedMessageMissingRecipient", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to Error occurred while sending a direct message or gettings the response..
/// </summary>
internal static string ErrorInRequestReplyMessage {
diff --git a/src/DotNetOAuth/Messaging/MessagingStrings.resx b/src/DotNetOAuth/Messaging/MessagingStrings.resx
index 4602058..2125e15 100644
--- a/src/DotNetOAuth/Messaging/MessagingStrings.resx
+++ b/src/DotNetOAuth/Messaging/MessagingStrings.resx
@@ -120,6 +120,9 @@
<data name="DerivedTypeNotExpected" xml:space="preserve">
<value>An instance of type {0} was expected, but received unexpected derived type {1}.</value>
</data>
+ <data name="DirectedMessageMissingRecipient" xml:space="preserve">
+ <value>The directed message's Recipient property must not be null.</value>
+ </data>
<data name="ErrorInRequestReplyMessage" xml:space="preserve">
<value>Error occurred while sending a direct message or gettings the response.</value>
</data>
diff --git a/src/DotNetOAuth/Protocol.cs b/src/DotNetOAuth/Protocol.cs
index be76e2a..f3dc3b6 100644
--- a/src/DotNetOAuth/Protocol.cs
+++ b/src/DotNetOAuth/Protocol.cs
@@ -20,11 +20,6 @@ namespace DotNetOAuth {
/// </remarks>
internal class Protocol {
/// <summary>
- /// Gets the default <see cref="Protocol"/> instance.
- /// </summary>
- internal static Protocol Default { get { return V10; } }
-
- /// <summary>
/// The namespace to use for V1.0 of the protocol.
/// </summary>
internal const string DataContractNamespaceV10 = "http://oauth.net/core/1.0/";
@@ -52,6 +47,11 @@ namespace DotNetOAuth {
private string authorizationHeaderScheme = "OAuth";
/// <summary>
+ /// Gets the default <see cref="Protocol"/> instance.
+ /// </summary>
+ internal static Protocol Default { get { return V10; } }
+
+ /// <summary>
/// Gets the namespace to use for this version of the protocol.
/// </summary>
internal string DataContractNamespace {