summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Test
diff options
context:
space:
mode:
Diffstat (limited to 'src/DotNetOpenAuth.Test')
-rw-r--r--src/DotNetOpenAuth.Test/Messaging/MessageSerializerTests.cs10
-rw-r--r--src/DotNetOpenAuth.Test/Messaging/Reflection/MessageDescriptionTests.cs20
-rw-r--r--src/DotNetOpenAuth.Test/Messaging/Reflection/MessageDictionaryTests.cs44
-rw-r--r--src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs15
-rw-r--r--src/DotNetOpenAuth.Test/Mocks/CoordinatingHttpRequestInfo.cs8
-rw-r--r--src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthChannel.cs7
-rw-r--r--src/DotNetOpenAuth.Test/Mocks/TestChannel.cs6
-rw-r--r--src/DotNetOpenAuth.Test/OAuth/ChannelElements/HmacSha1SigningBindingElementTests.cs4
-rw-r--r--src/DotNetOpenAuth.Test/OAuth/ChannelElements/SigningBindingElementBaseTests.cs8
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/ChannelElements/ExtensionsBindingElementTests.cs1
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/ChannelElements/OpenIdChannelTests.cs2
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/ChannelElements/SigningBindingElementTests.cs5
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/Extensions/ProviderAuthenticationPolicy/PolicyRequestTests.cs2
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/Extensions/ProviderAuthenticationPolicy/PolicyResponseTests.cs2
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/Extensions/SimpleRegistration/ClaimsRequestTests.cs2
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/Messages/AssociateRequestTests.cs2
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/Messages/AssociateUnencryptedResponseTests.cs7
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/Messages/AssociateUnsuccessfulResponseTests.cs8
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/Messages/CheckAuthenticationResponseTests.cs2
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/Messages/DirectErrorResponseTests.cs2
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/Messages/IndirectErrorResponseTests.cs2
-rw-r--r--src/DotNetOpenAuth.Test/TestBase.cs8
22 files changed, 96 insertions, 71 deletions
diff --git a/src/DotNetOpenAuth.Test/Messaging/MessageSerializerTests.cs b/src/DotNetOpenAuth.Test/Messaging/MessageSerializerTests.cs
index 3bcca10..481a715 100644
--- a/src/DotNetOpenAuth.Test/Messaging/MessageSerializerTests.cs
+++ b/src/DotNetOpenAuth.Test/Messaging/MessageSerializerTests.cs
@@ -37,7 +37,7 @@ namespace DotNetOpenAuth.Test.Messaging {
var serializer = MessageSerializer.Get(typeof(Mocks.TestMessage));
var message = GetStandardTestMessage(FieldFill.CompleteBeforeBindings);
var expected = GetStandardTestFields(FieldFill.CompleteBeforeBindings);
- IDictionary<string, string> actual = serializer.Serialize(message);
+ IDictionary<string, string> actual = serializer.Serialize(this.MessageDescriptions.GetAccessor(message));
Assert.AreEqual(4, actual.Count);
// Test case sensitivity of generated dictionary
@@ -66,7 +66,7 @@ namespace DotNetOpenAuth.Test.Messaging {
fields["age"] = "15";
fields["Timestamp"] = "1990-01-01T00:00:00";
var actual = new Mocks.TestDirectedMessage();
- serializer.Deserialize(fields, actual);
+ serializer.Deserialize(fields, this.MessageDescriptions.GetAccessor(actual));
Assert.AreEqual(15, actual.Age);
Assert.AreEqual("Andrew", actual.Name);
Assert.AreEqual(DateTime.Parse("1/1/1990"), actual.Timestamp);
@@ -96,7 +96,7 @@ namespace DotNetOpenAuth.Test.Messaging {
fields["explicit"] = "explicitValue";
fields["private"] = "privateValue";
var actual = new Mocks.TestDerivedMessage();
- serializer.Deserialize(fields, actual);
+ serializer.Deserialize(fields, this.MessageDescriptions.GetAccessor(actual));
Assert.AreEqual(15, actual.Age);
Assert.AreEqual("Andrew", actual.Name);
Assert.AreEqual("first", actual.TheFirstDerivedElement);
@@ -116,7 +116,7 @@ namespace DotNetOpenAuth.Test.Messaging {
// more parameters than are actually interesting to the protocol message.
fields["someExtraField"] = "asdf";
var actual = new Mocks.TestDirectedMessage();
- serializer.Deserialize(fields, actual);
+ serializer.Deserialize(fields, this.MessageDescriptions.GetAccessor(actual));
Assert.AreEqual(15, actual.Age);
Assert.AreEqual("Andrew", actual.Name);
Assert.IsNull(actual.EmptyMember);
@@ -128,7 +128,7 @@ namespace DotNetOpenAuth.Test.Messaging {
var serializer = MessageSerializer.Get(message.GetType());
var fields = GetStandardTestFields(FieldFill.AllRequired);
fields["age"] = "-1"; // Set an disallowed value.
- serializer.Deserialize(fields, message);
+ serializer.Deserialize(fields, this.MessageDescriptions.GetAccessor(message));
}
}
}
diff --git a/src/DotNetOpenAuth.Test/Messaging/Reflection/MessageDescriptionTests.cs b/src/DotNetOpenAuth.Test/Messaging/Reflection/MessageDescriptionTests.cs
index 7a1165b..76c454a 100644
--- a/src/DotNetOpenAuth.Test/Messaging/Reflection/MessageDescriptionTests.cs
+++ b/src/DotNetOpenAuth.Test/Messaging/Reflection/MessageDescriptionTests.cs
@@ -13,26 +13,26 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection {
[TestClass]
public class MessageDescriptionTests : MessagingTestBase {
[TestMethod, ExpectedException(typeof(ArgumentNullException))]
- public void GetNullType() {
- MessageDescription.Get(null, new Version(1, 0));
+ public void CtorNullType() {
+ new MessageDescription(null, new Version(1, 0));
}
[TestMethod, ExpectedException(typeof(ArgumentNullException))]
- public void GetNullVersion() {
- MessageDescription.Get(typeof(Mocks.TestMessage), null);
+ public void CtorNullVersion() {
+ new MessageDescription(typeof(Mocks.TestMessage), null);
}
[TestMethod, ExpectedException(typeof(ArgumentException))]
- public void GetNonMessageType() {
- MessageDescription.Get(typeof(string), new Version(1, 0));
+ public void CtorNonMessageType() {
+ new MessageDescription(typeof(string), new Version(1, 0));
}
[TestMethod]
public void MultiVersionedMessageTest() {
- var v10 = MessageDescription.Get(typeof(MultiVersionMessage), new Version(1, 0));
- var v20 = MessageDescription.Get(typeof(MultiVersionMessage), new Version(2, 0));
- var v25 = MessageDescription.Get(typeof(MultiVersionMessage), new Version(2, 5));
- var v30 = MessageDescription.Get(typeof(MultiVersionMessage), new Version(3, 0));
+ var v10 = new MessageDescription(typeof(MultiVersionMessage), new Version(1, 0));
+ var v20 = new MessageDescription(typeof(MultiVersionMessage), new Version(2, 0));
+ var v25 = new MessageDescription(typeof(MultiVersionMessage), new Version(2, 5));
+ var v30 = new MessageDescription(typeof(MultiVersionMessage), new Version(3, 0));
// Verify that the AllVersion member appears in every version.
Assert.IsTrue(v10.Mapping.ContainsKey("AllVersion"));
diff --git a/src/DotNetOpenAuth.Test/Messaging/Reflection/MessageDictionaryTests.cs b/src/DotNetOpenAuth.Test/Messaging/Reflection/MessageDictionaryTests.cs
index 0175173..7083b1e 100644
--- a/src/DotNetOpenAuth.Test/Messaging/Reflection/MessageDictionaryTests.cs
+++ b/src/DotNetOpenAuth.Test/Messaging/Reflection/MessageDictionaryTests.cs
@@ -27,7 +27,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection {
[TestMethod, ExpectedException(typeof(ArgumentNullException))]
public void CtorNull() {
- new MessageDictionary(null);
+ this.MessageDescriptions.GetAccessor(null);
}
/// <summary>
@@ -35,7 +35,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection {
/// </summary>
[TestMethod]
public void Values() {
- IDictionary<string, string> target = new MessageDictionary(this.message);
+ IDictionary<string, string> target = this.MessageDescriptions.GetAccessor(this.message);
Collection<string> expected = new Collection<string> {
this.message.Age.ToString(),
XmlConvert.ToString(DateTime.SpecifyKind(this.message.Timestamp, DateTimeKind.Utc), XmlDateTimeSerializationMode.Utc),
@@ -63,7 +63,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection {
public void Keys() {
// We expect that non-nullable value type fields will automatically have keys
// in the dictionary for them.
- IDictionary<string, string> target = new MessageDictionary(this.message);
+ IDictionary<string, string> target = this.MessageDescriptions.GetAccessor(this.message);
Collection<string> expected = new Collection<string> {
"age",
"Timestamp",
@@ -82,7 +82,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection {
/// </summary>
[TestMethod]
public void Item() {
- IDictionary<string, string> target = new MessageDictionary(this.message);
+ IDictionary<string, string> target = this.MessageDescriptions.GetAccessor(this.message);
// Test setting of declared message properties.
this.message.Age = 15;
@@ -105,7 +105,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection {
/// </summary>
[TestMethod]
public void IsReadOnly() {
- ICollection<KeyValuePair<string, string>> target = new MessageDictionary(this.message);
+ ICollection<KeyValuePair<string, string>> target = this.MessageDescriptions.GetAccessor(this.message);
Assert.IsFalse(target.IsReadOnly);
}
@@ -114,7 +114,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection {
/// </summary>
[TestMethod]
public void Count() {
- ICollection<KeyValuePair<string, string>> target = new MessageDictionary(this.message);
+ ICollection<KeyValuePair<string, string>> target = this.MessageDescriptions.GetAccessor(this.message);
IDictionary<string, string> targetDictionary = (IDictionary<string, string>)target;
Assert.AreEqual(targetDictionary.Keys.Count, target.Count);
targetDictionary["extraField"] = "hi";
@@ -126,7 +126,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection {
/// </summary>
[TestMethod]
public void GetEnumerator() {
- IEnumerable<KeyValuePair<string, string>> target = new MessageDictionary(this.message);
+ IEnumerable<KeyValuePair<string, string>> target = this.MessageDescriptions.GetAccessor(this.message);
IDictionary<string, string> targetDictionary = (IDictionary<string, string>)target;
var keys = targetDictionary.Keys.GetEnumerator();
var values = targetDictionary.Values.GetEnumerator();
@@ -149,7 +149,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection {
[TestMethod]
public void GetEnumeratorUntyped() {
- IEnumerable target = new MessageDictionary(this.message);
+ IEnumerable target = this.MessageDescriptions.GetAccessor(this.message);
IDictionary<string, string> targetDictionary = (IDictionary<string, string>)target;
var keys = targetDictionary.Keys.GetEnumerator();
var values = targetDictionary.Values.GetEnumerator();
@@ -176,7 +176,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection {
/// </summary>
[TestMethod]
public void TryGetValue() {
- IDictionary<string, string> target = new MessageDictionary(this.message);
+ IDictionary<string, string> target = this.MessageDescriptions.GetAccessor(this.message);
this.message.Name = "andrew";
string name;
Assert.IsTrue(target.TryGetValue("Name", out name));
@@ -196,7 +196,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection {
/// </summary>
[TestMethod]
public void RemoveTest1() {
- IDictionary<string, string> target = new MessageDictionary(this.message);
+ IDictionary<string, string> target = this.MessageDescriptions.GetAccessor(this.message);
this.message.Name = "andrew";
Assert.IsTrue(target.Remove("Name"));
Assert.IsNull(this.message.Name);
@@ -213,7 +213,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection {
/// </summary>
[TestMethod]
public void ContainsKey() {
- IDictionary<string, string> target = new MessageDictionary(this.message);
+ IDictionary<string, string> target = this.MessageDescriptions.GetAccessor(this.message);
Assert.IsTrue(target.ContainsKey("age"), "Value type declared element should have a key.");
Assert.IsFalse(target.ContainsKey("Name"), "Null declared element should NOT have a key.");
@@ -227,7 +227,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection {
/// </summary>
[TestMethod]
public void AddByKeyAndValue() {
- IDictionary<string, string> target = new MessageDictionary(this.message);
+ IDictionary<string, string> target = this.MessageDescriptions.GetAccessor(this.message);
target.Add("extra", "value");
Assert.IsTrue(target.Contains(new KeyValuePair<string, string>("extra", "value")));
target.Add("Name", "Andrew");
@@ -236,7 +236,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection {
[TestMethod, ExpectedException(typeof(ArgumentNullException))]
public void AddNullValue() {
- IDictionary<string, string> target = new MessageDictionary(this.message);
+ IDictionary<string, string> target = this.MessageDescriptions.GetAccessor(this.message);
target.Add("extra", null);
}
@@ -245,35 +245,35 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection {
/// </summary>
[TestMethod]
public void AddByKeyValuePair() {
- IDictionary<string, string> target = new MessageDictionary(this.message);
+ IDictionary<string, string> target = this.MessageDescriptions.GetAccessor(this.message);
target.Add(new KeyValuePair<string, string>("extra", "value"));
Assert.IsTrue(target.Contains(new KeyValuePair<string, string>("extra", "value")));
}
[TestMethod, ExpectedException(typeof(ArgumentException))]
public void AddExtraFieldThatAlreadyExists() {
- IDictionary<string, string> target = new MessageDictionary(this.message);
+ IDictionary<string, string> target = this.MessageDescriptions.GetAccessor(this.message);
target.Add("extra", "value");
target.Add("extra", "value");
}
[TestMethod, ExpectedException(typeof(ArgumentException))]
public void AddDeclaredValueThatAlreadyExists() {
- IDictionary<string, string> target = new MessageDictionary(this.message);
+ IDictionary<string, string> target = this.MessageDescriptions.GetAccessor(this.message);
target.Add("Name", "andrew");
target.Add("Name", "andrew");
}
[TestMethod]
public void DefaultReferenceTypeDeclaredPropertyHasNoKey() {
- IDictionary<string, string> target = new MessageDictionary(this.message);
+ IDictionary<string, string> target = this.MessageDescriptions.GetAccessor(this.message);
Assert.IsFalse(target.ContainsKey("Name"), "A null value should result in no key.");
Assert.IsFalse(target.Keys.Contains("Name"), "A null value should result in no key.");
}
[TestMethod]
public void RemoveStructDeclaredProperty() {
- IDictionary<string, string> target = new MessageDictionary(this.message);
+ IDictionary<string, string> target = this.MessageDescriptions.GetAccessor(this.message);
this.message.Age = 5;
Assert.IsTrue(target.ContainsKey("age"));
target.Remove("age");
@@ -286,7 +286,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection {
/// </summary>
[TestMethod]
public void RemoveByKeyValuePair() {
- ICollection<KeyValuePair<string, string>> target = new MessageDictionary(this.message);
+ ICollection<KeyValuePair<string, string>> target = this.MessageDescriptions.GetAccessor(this.message);
this.message.Name = "Andrew";
Assert.IsFalse(target.Remove(new KeyValuePair<string, string>("Name", "andrew")));
Assert.AreEqual("Andrew", this.message.Name);
@@ -299,7 +299,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection {
/// </summary>
[TestMethod]
public void CopyTo() {
- ICollection<KeyValuePair<string, string>> target = new MessageDictionary(this.message);
+ ICollection<KeyValuePair<string, string>> target = this.MessageDescriptions.GetAccessor(this.message);
IDictionary<string, string> targetAsDictionary = ((IDictionary<string, string>)target);
KeyValuePair<string, string>[] array = new KeyValuePair<string, string>[target.Count + 1];
int arrayIndex = 1;
@@ -316,7 +316,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection {
/// </summary>
[TestMethod]
public void ContainsKeyValuePair() {
- ICollection<KeyValuePair<string, string>> target = new MessageDictionary(this.message);
+ ICollection<KeyValuePair<string, string>> target = this.MessageDescriptions.GetAccessor(this.message);
IDictionary<string, string> targetAsDictionary = ((IDictionary<string, string>)target);
Assert.IsFalse(target.Contains(new KeyValuePair<string, string>("age", "1")));
Assert.IsTrue(target.Contains(new KeyValuePair<string, string>("age", "0")));
@@ -332,7 +332,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection {
/// </summary>
[TestMethod]
public void Clear() {
- ICollection<KeyValuePair<string, string>> target = new MessageDictionary(this.message);
+ ICollection<KeyValuePair<string, string>> target = this.MessageDescriptions.GetAccessor(this.message);
IDictionary<string, string> targetAsDictionary = ((IDictionary<string, string>)target);
this.message.Name = "Andrew";
this.message.Age = 15;
diff --git a/src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs b/src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs
index 80351d4..b5fc321 100644
--- a/src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs
+++ b/src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs
@@ -127,7 +127,7 @@ namespace DotNetOpenAuth.Test.Mocks {
/// <param name="message">The message that this channel should receive. This message will be cloned.</param>
internal void PostMessage(IProtocolMessage message) {
ErrorUtilities.VerifyInternal(this.incomingMessage == null, "Oops, a message is already waiting for the remote party!");
- this.incomingMessage = new Dictionary<string, string>(new MessageDictionary(message));
+ this.incomingMessage = this.MessageDescriptions.GetAccessor(message).Serialize();
var directedMessage = message as IDirectedProtocolMessage;
this.incomingMessageRecipient = directedMessage != null ? new MessageReceivingEndpoint(directedMessage.Recipient, directedMessage.HttpMethods) : null;
this.incomingMessageSignal.Set();
@@ -137,7 +137,7 @@ namespace DotNetOpenAuth.Test.Mocks {
MessageReceivingEndpoint recipient;
var messageData = this.AwaitIncomingMessage(out recipient);
if (messageData != null) {
- return new CoordinatingHttpRequestInfo(this.MessageFactory, messageData, recipient);
+ return new CoordinatingHttpRequestInfo(this, this.MessageFactory, messageData, recipient);
} else {
return new CoordinatingHttpRequestInfo(recipient);
}
@@ -160,8 +160,8 @@ namespace DotNetOpenAuth.Test.Mocks {
return null;
}
- var responseSerializer = MessageSerializer.Get(responseMessage.GetType());
- responseSerializer.Deserialize(responseData, responseMessage);
+ var responseAccessor = this.MessageDescriptions.GetAccessor(responseMessage);
+ responseAccessor.Deserialize(responseData);
this.ProcessMessageFilter(responseMessage, false);
return responseMessage;
@@ -211,8 +211,8 @@ namespace DotNetOpenAuth.Test.Mocks {
ErrorUtilities.VerifyArgumentNotNull(message, "message");
IProtocolMessage clonedMessage;
- MessageSerializer serializer = MessageSerializer.Get(message.GetType());
- var fields = serializer.Serialize(message);
+ var messageAccessor = this.MessageDescriptions.GetAccessor(message);
+ var fields = messageAccessor.Serialize();
MessageReceivingEndpoint recipient = null;
var directedMessage = message as IDirectedProtocolMessage;
@@ -232,7 +232,8 @@ namespace DotNetOpenAuth.Test.Mocks {
ErrorUtilities.VerifyInternal(clonedMessage != null, "Message factory did not generate a message instance for " + message.GetType().Name);
// Fill the cloned message with data.
- serializer.Deserialize(fields, clonedMessage);
+ var clonedMessageAccessor = this.MessageDescriptions.GetAccessor(clonedMessage);
+ clonedMessageAccessor.Deserialize(fields);
return (T)clonedMessage;
}
diff --git a/src/DotNetOpenAuth.Test/Mocks/CoordinatingHttpRequestInfo.cs b/src/DotNetOpenAuth.Test/Mocks/CoordinatingHttpRequestInfo.cs
index 5467045..f611552 100644
--- a/src/DotNetOpenAuth.Test/Mocks/CoordinatingHttpRequestInfo.cs
+++ b/src/DotNetOpenAuth.Test/Mocks/CoordinatingHttpRequestInfo.cs
@@ -13,18 +13,22 @@ namespace DotNetOpenAuth.Test.Mocks {
private IDictionary<string, string> messageData;
private IMessageFactory messageFactory;
private MessageReceivingEndpoint recipient;
+ private Channel channel;
/// <summary>
/// Initializes a new instance of the <see cref="CoordinatingHttpRequestInfo"/> class
/// that will generate a message when the <see cref="Message"/> property getter is called.
/// </summary>
+ /// <param name="channel">The channel.</param>
/// <param name="messageFactory">The message factory.</param>
/// <param name="messageData">The message data.</param>
/// <param name="recipient">The recipient.</param>
- internal CoordinatingHttpRequestInfo(IMessageFactory messageFactory, IDictionary<string, string> messageData, MessageReceivingEndpoint recipient)
+ internal CoordinatingHttpRequestInfo(Channel channel, IMessageFactory messageFactory, IDictionary<string, string> messageData, MessageReceivingEndpoint recipient)
: this(recipient) {
+ Contract.Requires(channel != null);
Contract.Requires(messageFactory != null);
Contract.Requires(messageData != null);
+ this.channel = channel;
this.messageFactory = messageFactory;
this.messageData = messageData;
}
@@ -49,7 +53,7 @@ namespace DotNetOpenAuth.Test.Mocks {
if (base.Message == null && this.messageData != null) {
IDirectedProtocolMessage message = this.messageFactory.GetNewRequestMessage(this.recipient, this.messageData);
if (message != null) {
- MessageSerializer.Get(message.GetType()).Deserialize(this.messageData, message);
+ this.channel.MessageDescriptions.GetAccessor(message).Deserialize(this.messageData);
}
base.Message = message;
}
diff --git a/src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthChannel.cs b/src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthChannel.cs
index 4911a9c..a533815 100644
--- a/src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthChannel.cs
+++ b/src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthChannel.cs
@@ -125,8 +125,8 @@ namespace DotNetOpenAuth.Test.Mocks {
ErrorUtilities.VerifyArgumentNotNull(message, "message");
IProtocolMessage clonedMessage;
- MessageSerializer serializer = MessageSerializer.Get(message.GetType());
- var fields = serializer.Serialize(message);
+ var messageAccessor = this.MessageDescriptions.GetAccessor(message);
+ var fields = messageAccessor.Serialize();
MessageReceivingEndpoint recipient = null;
var directedMessage = message as IDirectedProtocolMessage;
@@ -144,7 +144,8 @@ namespace DotNetOpenAuth.Test.Mocks {
}
// Fill the cloned message with data.
- serializer.Deserialize(fields, clonedMessage);
+ var clonedMessageAccessor = this.MessageDescriptions.GetAccessor(clonedMessage);
+ clonedMessageAccessor.Deserialize(fields);
return (T)clonedMessage;
}
diff --git a/src/DotNetOpenAuth.Test/Mocks/TestChannel.cs b/src/DotNetOpenAuth.Test/Mocks/TestChannel.cs
index a65b39c..a72ab63 100644
--- a/src/DotNetOpenAuth.Test/Mocks/TestChannel.cs
+++ b/src/DotNetOpenAuth.Test/Mocks/TestChannel.cs
@@ -9,12 +9,18 @@ namespace DotNetOpenAuth.Test.Mocks {
using System.Collections.Generic;
using System.Net;
using DotNetOpenAuth.Messaging;
+ using DotNetOpenAuth.Messaging.Reflection;
internal class TestChannel : Channel {
internal TestChannel()
: this(new TestMessageFactory()) {
}
+ internal TestChannel(MessageDescriptionCollection messageDescriptions)
+ : this() {
+ this.MessageDescriptions = messageDescriptions;
+ }
+
internal TestChannel(IMessageFactory messageTypeProvider, params IChannelBindingElement[] bindingElements)
: base(messageTypeProvider, bindingElements) {
}
diff --git a/src/DotNetOpenAuth.Test/OAuth/ChannelElements/HmacSha1SigningBindingElementTests.cs b/src/DotNetOpenAuth.Test/OAuth/ChannelElements/HmacSha1SigningBindingElementTests.cs
index ac2c0b1..2596bc5 100644
--- a/src/DotNetOpenAuth.Test/OAuth/ChannelElements/HmacSha1SigningBindingElementTests.cs
+++ b/src/DotNetOpenAuth.Test/OAuth/ChannelElements/HmacSha1SigningBindingElementTests.cs
@@ -7,15 +7,17 @@
namespace DotNetOpenAuth.Test.ChannelElements {
using DotNetOpenAuth.OAuth.ChannelElements;
using DotNetOpenAuth.OAuth.Messages;
+ using DotNetOpenAuth.Test.Mocks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public class HmacSha1SigningBindingElementTests : MessagingTestBase {
[TestMethod]
public void SignatureTest() {
- UnauthorizedTokenRequest message = SigningBindingElementBaseTests.CreateTestRequestTokenMessage();
+ UnauthorizedTokenRequest message = SigningBindingElementBaseTests.CreateTestRequestTokenMessage(this.MessageDescriptions);
HmacSha1SigningBindingElement_Accessor hmac = new HmacSha1SigningBindingElement_Accessor();
+ hmac.Channel = new TestChannel(this.MessageDescriptions);
Assert.AreEqual("kR0LhH8UqylaLfR/esXVVlP4sQI=", hmac.GetSignature(message));
}
}
diff --git a/src/DotNetOpenAuth.Test/OAuth/ChannelElements/SigningBindingElementBaseTests.cs b/src/DotNetOpenAuth.Test/OAuth/ChannelElements/SigningBindingElementBaseTests.cs
index 8f09ef6..e890b6f 100644
--- a/src/DotNetOpenAuth.Test/OAuth/ChannelElements/SigningBindingElementBaseTests.cs
+++ b/src/DotNetOpenAuth.Test/OAuth/ChannelElements/SigningBindingElementBaseTests.cs
@@ -15,14 +15,14 @@ namespace DotNetOpenAuth.Test.ChannelElements {
public class SigningBindingElementBaseTests : MessagingTestBase {
[TestMethod]
public void BaseSignatureStringTest() {
- UnauthorizedTokenRequest message = CreateTestRequestTokenMessage();
+ UnauthorizedTokenRequest message = CreateTestRequestTokenMessage(this.MessageDescriptions);
Assert.AreEqual(
"GET&https%3A%2F%2Fwww.google.com%2Faccounts%2FOAuthGetRequestToken&oauth_consumer_key%3Dnerdbank.org%26oauth_nonce%3Dfe4045a3f0efdd1e019fa8f8ae3f5c38%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1222665749%26oauth_version%3D1.0%26scope%3Dhttp%253A%252F%252Fwww.google.com%252Fm8%252Ffeeds%252F",
- SigningBindingElementBase_Accessor.ConstructSignatureBaseString(message));
+ SigningBindingElementBase_Accessor.ConstructSignatureBaseString(message, MessageDictionary_Accessor.AttachShadow(this.MessageDescriptions.GetAccessor(message))));
}
- internal static UnauthorizedTokenRequest CreateTestRequestTokenMessage() {
+ internal static UnauthorizedTokenRequest CreateTestRequestTokenMessage(MessageDescriptionCollection messageDescriptions) {
MessageReceivingEndpoint endpoint = new MessageReceivingEndpoint("https://www.google.com/accounts/OAuthGetRequestToken", HttpDeliveryMethods.AuthorizationHeaderRequest | HttpDeliveryMethods.GetRequest);
UnauthorizedTokenRequest message = new UnauthorizedTokenRequest(endpoint);
message.ConsumerKey = "nerdbank.org";
@@ -30,7 +30,7 @@ namespace DotNetOpenAuth.Test.ChannelElements {
var signedMessage = (ITamperResistantOAuthMessage)message;
signedMessage.HttpMethod = "GET";
signedMessage.SignatureMethod = "HMAC-SHA1";
- MessageDictionary dictionary = new MessageDictionary(message);
+ MessageDictionary dictionary = messageDescriptions.GetAccessor(message);
dictionary["oauth_timestamp"] = "1222665749";
dictionary["oauth_nonce"] = "fe4045a3f0efdd1e019fa8f8ae3f5c38";
dictionary["scope"] = "http://www.google.com/m8/feeds/";
diff --git a/src/DotNetOpenAuth.Test/OpenId/ChannelElements/ExtensionsBindingElementTests.cs b/src/DotNetOpenAuth.Test/OpenId/ChannelElements/ExtensionsBindingElementTests.cs
index a19df2a..7428a28 100644
--- a/src/DotNetOpenAuth.Test/OpenId/ChannelElements/ExtensionsBindingElementTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/ChannelElements/ExtensionsBindingElementTests.cs
@@ -32,6 +32,7 @@ namespace DotNetOpenAuth.Test.OpenId.ChannelElements {
this.factory = new OpenIdExtensionFactory();
this.factory.RegisterExtension(MockOpenIdExtension.Factory);
this.rpElement = new ExtensionsBindingElement(this.factory, new RelyingPartySecuritySettings());
+ this.rpElement.Channel = new TestChannel(this.MessageDescriptions);
this.request = new SignedResponseRequest(Protocol.Default.Version, OpenIdTestBase.OPUri, AuthenticationRequestMode.Immediate);
}
diff --git a/src/DotNetOpenAuth.Test/OpenId/ChannelElements/OpenIdChannelTests.cs b/src/DotNetOpenAuth.Test/OpenId/ChannelElements/OpenIdChannelTests.cs
index b6a5d29..1355c54 100644
--- a/src/DotNetOpenAuth.Test/OpenId/ChannelElements/OpenIdChannelTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/ChannelElements/OpenIdChannelTests.cs
@@ -76,7 +76,7 @@ namespace DotNetOpenAuth.Test.OpenId.ChannelElements {
[TestMethod]
public void DirectResponsesSentUsingKeyValueForm() {
IProtocolMessage message = MessagingTestBase.GetStandardTestMessage(MessagingTestBase.FieldFill.AllRequired);
- MessageDictionary messageFields = new MessageDictionary(message);
+ MessageDictionary messageFields = this.MessageDescriptions.GetAccessor(message);
byte[] expectedBytes = KeyValueFormEncoding.GetBytes(messageFields);
string expectedContentType = OpenIdChannel_Accessor.KeyValueFormContentType;
diff --git a/src/DotNetOpenAuth.Test/OpenId/ChannelElements/SigningBindingElementTests.cs b/src/DotNetOpenAuth.Test/OpenId/ChannelElements/SigningBindingElementTests.cs
index 6b99541..8cfa106 100644
--- a/src/DotNetOpenAuth.Test/OpenId/ChannelElements/SigningBindingElementTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/ChannelElements/SigningBindingElementTests.cs
@@ -6,13 +6,12 @@
namespace DotNetOpenAuth.Test.OpenId.ChannelElements {
using System;
- using System.Collections.Generic;
using System.Linq;
- using System.Text;
using DotNetOpenAuth.OpenId;
using DotNetOpenAuth.OpenId.ChannelElements;
using DotNetOpenAuth.OpenId.Messages;
using DotNetOpenAuth.OpenId.Provider;
+ using DotNetOpenAuth.Test.Mocks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
@@ -29,6 +28,7 @@ namespace DotNetOpenAuth.Test.OpenId.ChannelElements {
Association association = HmacShaAssociation.Create("mock", associationSecret, TimeSpan.FromDays(1));
store.StoreAssociation(AssociationRelyingPartyType.Smart, association);
SigningBindingElement signer = new SigningBindingElement(store, settings);
+ signer.Channel = new TestChannel(this.MessageDescriptions);
IndirectSignedResponse message = new IndirectSignedResponse(protocol.Version, new Uri("http://rp"));
ITamperResistantOpenIdMessage signedMessage = message;
@@ -46,6 +46,7 @@ namespace DotNetOpenAuth.Test.OpenId.ChannelElements {
public void SignedResponsesIncludeExtraDataInSignature() {
Protocol protocol = Protocol.Default;
SigningBindingElement sbe = new SigningBindingElement(new AssociationMemoryStore<AssociationRelyingPartyType>(), new ProviderSecuritySettings());
+ sbe.Channel = new TestChannel(this.MessageDescriptions);
IndirectSignedResponse response = new IndirectSignedResponse(protocol.Version, RPUri);
response.ReturnTo = RPUri;
response.ProviderEndpoint = OPUri;
diff --git a/src/DotNetOpenAuth.Test/OpenId/Extensions/ProviderAuthenticationPolicy/PolicyRequestTests.cs b/src/DotNetOpenAuth.Test/OpenId/Extensions/ProviderAuthenticationPolicy/PolicyRequestTests.cs
index 253d8ec..303c747 100644
--- a/src/DotNetOpenAuth.Test/OpenId/Extensions/ProviderAuthenticationPolicy/PolicyRequestTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/Extensions/ProviderAuthenticationPolicy/PolicyRequestTests.cs
@@ -109,7 +109,7 @@ namespace DotNetOpenAuth.Test.OpenId.Extensions.ProviderAuthenticationPolicy {
PolicyRequest req = new PolicyRequest();
IMessageWithEvents reqEvents = req;
- var fields = new MessageDictionary(req);
+ var fields = this.MessageDescriptions.GetAccessor(req);
reqEvents.OnSending();
Assert.AreEqual(1, fields.Count);
Assert.IsTrue(fields.ContainsKey("preferred_auth_policies"));
diff --git a/src/DotNetOpenAuth.Test/OpenId/Extensions/ProviderAuthenticationPolicy/PolicyResponseTests.cs b/src/DotNetOpenAuth.Test/OpenId/Extensions/ProviderAuthenticationPolicy/PolicyResponseTests.cs
index 0d0219b..e0faaac 100644
--- a/src/DotNetOpenAuth.Test/OpenId/Extensions/ProviderAuthenticationPolicy/PolicyResponseTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/Extensions/ProviderAuthenticationPolicy/PolicyResponseTests.cs
@@ -169,7 +169,7 @@ namespace DotNetOpenAuth.Test.OpenId.Extensions.ProviderAuthenticationPolicy {
PolicyResponse resp = new PolicyResponse();
IMessageWithEvents respEvents = resp;
- var fields = new MessageDictionary(resp);
+ var fields = this.MessageDescriptions.GetAccessor(resp);
respEvents.OnSending();
Assert.AreEqual(1, fields.Count);
Assert.IsTrue(fields.ContainsKey("auth_policies"));
diff --git a/src/DotNetOpenAuth.Test/OpenId/Extensions/SimpleRegistration/ClaimsRequestTests.cs b/src/DotNetOpenAuth.Test/OpenId/Extensions/SimpleRegistration/ClaimsRequestTests.cs
index feb1450..3af54d3 100644
--- a/src/DotNetOpenAuth.Test/OpenId/Extensions/SimpleRegistration/ClaimsRequestTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/Extensions/SimpleRegistration/ClaimsRequestTests.cs
@@ -24,7 +24,7 @@ namespace DotNetOpenAuth.Test.OpenId.Extensions {
[TestMethod]
public void RequiredOptionalLists() {
ClaimsRequest req = new ClaimsRequest();
- MessageDictionary dictionary = new MessageDictionary(req);
+ MessageDictionary dictionary = this.MessageDescriptions.GetAccessor(req);
Assert.AreEqual(string.Empty, dictionary["required"]);
Assert.AreEqual(string.Empty, dictionary["optional"]);
diff --git a/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateRequestTests.cs b/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateRequestTests.cs
index ef2aa05..0957118 100644
--- a/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateRequestTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateRequestTests.cs
@@ -44,7 +44,7 @@ namespace DotNetOpenAuth.Test.OpenId.Messages {
Assert.AreEqual(this.protocol.Args.SignatureAlgorithm.HMAC_SHA1, this.request.AssociationType);
Assert.AreEqual(this.protocol.Args.SessionType.NoEncryption, this.request.SessionType);
- var dict = new MessageDictionary(this.request);
+ var dict = this.MessageDescriptions.GetAccessor(this.request);
Assert.AreEqual(Protocol.OpenId2Namespace, dict[this.protocol.openid.ns]);
Assert.AreEqual(this.protocol.Args.Mode.associate, dict[this.protocol.openid.mode]);
Assert.AreEqual(this.protocol.Args.SignatureAlgorithm.HMAC_SHA1, dict[this.protocol.openid.assoc_type]);
diff --git a/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateUnencryptedResponseTests.cs b/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateUnencryptedResponseTests.cs
index 89609f6..1f5e87c 100644
--- a/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateUnencryptedResponseTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateUnencryptedResponseTests.cs
@@ -12,11 +12,12 @@ namespace DotNetOpenAuth.Test.OpenId.Messages {
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
- public class AssociateUnencryptedResponseTests {
+ public class AssociateUnencryptedResponseTests : OpenIdTestBase {
private AssociateUnencryptedResponse response;
[TestInitialize]
- public void Setup() {
+ public override void SetUp() {
+ base.SetUp();
var request = new AssociateUnencryptedRequest(Protocol.V20.Version, new Uri("http://host"));
this.response = new AssociateUnencryptedResponse(request.Version, request);
}
@@ -29,7 +30,7 @@ namespace DotNetOpenAuth.Test.OpenId.Messages {
this.response.ExpiresIn = 50;
MessageSerializer serializer = MessageSerializer.Get(this.response.GetType());
- var fields = serializer.Serialize(this.response);
+ var fields = this.MessageDescriptions.GetAccessor(this.response).Serialize();
Assert.AreEqual(Protocol.OpenId2Namespace, fields["ns"]);
Assert.AreEqual("HANDLE", fields["assoc_handle"]);
Assert.AreEqual("HMAC-SHA1", fields["assoc_type"]);
diff --git a/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateUnsuccessfulResponseTests.cs b/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateUnsuccessfulResponseTests.cs
index e803400..a6a691d 100644
--- a/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateUnsuccessfulResponseTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateUnsuccessfulResponseTests.cs
@@ -12,11 +12,12 @@ namespace DotNetOpenAuth.Test.OpenId.Messages {
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
- public class AssociateUnsuccessfulResponseTests {
+ public class AssociateUnsuccessfulResponseTests : OpenIdTestBase {
private AssociateUnsuccessfulResponse response;
[TestInitialize]
- public void Setup() {
+ public override void SetUp() {
+ base.SetUp();
var request = new AssociateUnencryptedRequest(Protocol.V20.Version, new Uri("http://host"));
this.response = new AssociateUnsuccessfulResponse(request.Version, request);
}
@@ -27,8 +28,7 @@ namespace DotNetOpenAuth.Test.OpenId.Messages {
this.response.AssociationType = "HMAC-SHA1";
this.response.SessionType = "DH-SHA1";
- MessageSerializer serializer = MessageSerializer.Get(this.response.GetType());
- var fields = serializer.Serialize(this.response);
+ var fields = this.MessageDescriptions.GetAccessor(this.response).Serialize();
Assert.AreEqual(Protocol.OpenId2Namespace, fields["ns"]);
Assert.AreEqual("unsupported-type", fields["error_code"]);
Assert.AreEqual("Some Error", fields["error"]);
diff --git a/src/DotNetOpenAuth.Test/OpenId/Messages/CheckAuthenticationResponseTests.cs b/src/DotNetOpenAuth.Test/OpenId/Messages/CheckAuthenticationResponseTests.cs
index ce55ea4..1e773bd 100644
--- a/src/DotNetOpenAuth.Test/OpenId/Messages/CheckAuthenticationResponseTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/Messages/CheckAuthenticationResponseTests.cs
@@ -26,7 +26,7 @@ namespace DotNetOpenAuth.Test.OpenId.Messages {
Protocol protocol = Protocol.Default;
var request = new CheckAuthenticationRequest(protocol.Version, OPUri);
var response = new CheckAuthenticationResponse(protocol.Version, request);
- var dictionary = new MessageDictionary(response);
+ var dictionary = this.MessageDescriptions.GetAccessor(response);
Assert.AreEqual("false", dictionary["is_valid"]);
response.IsValid = true;
Assert.AreEqual("true", dictionary["is_valid"]);
diff --git a/src/DotNetOpenAuth.Test/OpenId/Messages/DirectErrorResponseTests.cs b/src/DotNetOpenAuth.Test/OpenId/Messages/DirectErrorResponseTests.cs
index c0ac7de..02fa7df 100644
--- a/src/DotNetOpenAuth.Test/OpenId/Messages/DirectErrorResponseTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/Messages/DirectErrorResponseTests.cs
@@ -31,7 +31,7 @@ namespace DotNetOpenAuth.Test.OpenId.Messages {
this.response.Reference = "http://blog.nerdbank.net/";
MessageSerializer serializer = MessageSerializer.Get(this.response.GetType());
- var fields = serializer.Serialize(this.response);
+ var fields = this.MessageDescriptions.GetAccessor(this.response).Serialize();
Assert.AreEqual(Protocol.OpenId2Namespace, fields["ns"]);
Assert.AreEqual("Some Error", fields["error"]);
Assert.AreEqual("Andrew Arnott", fields["contact"]);
diff --git a/src/DotNetOpenAuth.Test/OpenId/Messages/IndirectErrorResponseTests.cs b/src/DotNetOpenAuth.Test/OpenId/Messages/IndirectErrorResponseTests.cs
index 3448358..fdb08eb 100644
--- a/src/DotNetOpenAuth.Test/OpenId/Messages/IndirectErrorResponseTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/Messages/IndirectErrorResponseTests.cs
@@ -35,7 +35,7 @@ namespace DotNetOpenAuth.Test.OpenId.Messages {
this.response.Reference = "http://blog.nerdbank.net/";
MessageSerializer serializer = MessageSerializer.Get(this.response.GetType());
- var fields = serializer.Serialize(this.response);
+ var fields = this.MessageDescriptions.GetAccessor(this.response).Serialize();
Assert.AreEqual(Protocol.OpenId2Namespace, fields["openid.ns"]);
Assert.AreEqual("Some Error", fields["openid.error"]);
Assert.AreEqual("Andrew Arnott", fields["openid.contact"]);
diff --git a/src/DotNetOpenAuth.Test/TestBase.cs b/src/DotNetOpenAuth.Test/TestBase.cs
index db37c58..d21691b 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 DotNetOpenAuth.Messaging.Reflection;
using DotNetOpenAuth.OAuth.Messages;
using log4net;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -20,6 +21,8 @@ namespace DotNetOpenAuth.Test {
/// </summary>
internal static readonly string TestWebDirectory = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), @"..\..\..\..\src\DotNetOpenAuth.TestWeb"));
+ private MessageDescriptionCollection messageDescriptions = new MessageDescriptionCollection();
+
/// <summary>
/// Gets or sets the test context which provides
/// information about and functionality for the current test run.
@@ -33,6 +36,10 @@ namespace DotNetOpenAuth.Test {
get { return TestUtilities.TestLogger; }
}
+ internal MessageDescriptionCollection MessageDescriptions {
+ get { return this.messageDescriptions; }
+ }
+
/// <summary>
/// The TestInitialize method for the test cases.
/// </summary>
@@ -40,6 +47,7 @@ namespace DotNetOpenAuth.Test {
public virtual void SetUp() {
log4net.Config.XmlConfigurator.Configure(Assembly.GetExecutingAssembly().GetManifestResourceStream("DotNetOpenAuth.Test.Logging.config"));
MessageBase.LowSecurityMode = true;
+ this.messageDescriptions = new MessageDescriptionCollection();
}
/// <summary>