diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2008-09-20 17:17:39 -0700 |
---|---|---|
committer | Andrew <andrewarnott@gmail.com> | 2008-09-20 17:17:39 -0700 |
commit | b11a9a3a69ab79c92e3d1fb0de501c5311134723 (patch) | |
tree | 7ba9031a2728dc2123bbf9f2f06f0ce69984b6bc | |
parent | ccd062ccfaa33aed1da1e39e62c07348392f4367 (diff) | |
download | DotNetOpenAuth-b11a9a3a69ab79c92e3d1fb0de501c5311134723.zip DotNetOpenAuth-b11a9a3a69ab79c92e3d1fb0de501c5311134723.tar.gz DotNetOpenAuth-b11a9a3a69ab79c92e3d1fb0de501c5311134723.tar.bz2 |
Removed EnsureCompleteMessageBindingElement and moved its functionality back into the Channel class.
6 files changed, 16 insertions, 52 deletions
diff --git a/src/DotNetOAuth.Test/Messaging/ChannelTests.cs b/src/DotNetOAuth.Test/Messaging/ChannelTests.cs index 7fef82d..e8c4514 100644 --- a/src/DotNetOAuth.Test/Messaging/ChannelTests.cs +++ b/src/DotNetOAuth.Test/Messaging/ChannelTests.cs @@ -283,15 +283,12 @@ namespace DotNetOAuth.Test.Messaging { transformB,
transformA);
- Assert.AreEqual(6, channel.BindingElements.Count);
+ Assert.AreEqual(5, channel.BindingElements.Count);
Assert.AreSame(transformB, channel.BindingElements[0]);
Assert.AreSame(transformA, channel.BindingElements[1]);
Assert.AreSame(replay, channel.BindingElements[2]);
Assert.AreSame(expire, channel.BindingElements[3]);
Assert.AreSame(sign, channel.BindingElements[4]);
-
- // This last one is added by the channel.
- Assert.IsInstanceOfType(channel.BindingElements[5], typeof(EnsureCompleteMessageBindingElement));
}
[TestMethod, ExpectedException(typeof(UnprotectedMessageException))]
diff --git a/src/DotNetOAuth.Test/Messaging/Reflection/MessagePartTests.cs b/src/DotNetOAuth.Test/Messaging/Reflection/MessagePartTests.cs index 5c032e6..b6c3b9d 100644 --- a/src/DotNetOAuth.Test/Messaging/Reflection/MessagePartTests.cs +++ b/src/DotNetOAuth.Test/Messaging/Reflection/MessagePartTests.cs @@ -32,6 +32,10 @@ namespace DotNetOAuth.Test.Messaging.Reflection { [MessagePart(IsRequired = false)]
internal int? optionalInt = 0;
}
+ class MessageWithNullableRequiredStruct : TestMessage {
+ [MessagePart(IsRequired = true)]
+ internal int? optionalInt;
+ }
[TestMethod, ExpectedException(typeof(ArgumentException))]
public void OptionalNonNullableStruct() {
@@ -48,6 +52,11 @@ namespace DotNetOAuth.Test.Messaging.Reflection { ParameterizedMessageTypeTest(typeof(MessageWithNullableOptionalStruct));
}
+ [TestMethod]
+ public void RequiredNullableStruct() {
+ ParameterizedMessageTypeTest(typeof(MessageWithNullableRequiredStruct));
+ }
+
[TestMethod, ExpectedException(typeof(ArgumentNullException))]
public void CtorNullMember() {
new MessagePart(null, new MessagePartAttribute());
diff --git a/src/DotNetOAuth/DotNetOAuth.csproj b/src/DotNetOAuth/DotNetOAuth.csproj index a1fac72..f5882ef 100644 --- a/src/DotNetOAuth/DotNetOAuth.csproj +++ b/src/DotNetOAuth/DotNetOAuth.csproj @@ -68,7 +68,6 @@ <ItemGroup>
<Compile Include="Consumer.cs" />
<Compile Include="IWebRequestHandler.cs" />
- <Compile Include="Messaging\Bindings\EnsureCompleteMessageBindingElement.cs" />
<Compile Include="Messaging\Reflection\MessagePartAttribute.cs" />
<Compile Include="Messaging\MessageProtection.cs" />
<Compile Include="Messaging\IChannelBindingElement.cs" />
diff --git a/src/DotNetOAuth/Messaging/Bindings/EnsureCompleteMessageBindingElement.cs b/src/DotNetOAuth/Messaging/Bindings/EnsureCompleteMessageBindingElement.cs deleted file mode 100644 index dc00c12..0000000 --- a/src/DotNetOAuth/Messaging/Bindings/EnsureCompleteMessageBindingElement.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using DotNetOAuth.Messaging.Reflection;
-
-namespace DotNetOAuth.Messaging.Bindings {
- internal class EnsureCompleteMessageBindingElement : IChannelBindingElement {
- #region IChannelBindingElement Members
-
- public MessageProtection Protection {
- get { return MessageProtection.None; }
- }
-
- public bool PrepareMessageForSending(IProtocolMessage message) {
- // Before we're sending the message, make sure all the required parts are present.
- MessageDictionary dictionary = new MessageDictionary(message);
- MessageDescription.Get(message.GetType()).EnsureRequiredMessagePartsArePresent(dictionary.Keys);
- return true;
- }
-
- public bool PrepareMessageForReceiving(IProtocolMessage message) {
- // Once the message is deserialized, it is too late to use the MessageDictionary
- // to see if all the message parts were included in the original serialized message
- // because non-nullable value types will already have default values by now.
- // The code for verifying complete incoming messages is included in
- // MessageSerializer.Deserialize.
- return false;
- }
-
- #endregion
- }
-}
diff --git a/src/DotNetOAuth/Messaging/Channel.cs b/src/DotNetOAuth/Messaging/Channel.cs index be3cdf2..db6cc10 100644 --- a/src/DotNetOAuth/Messaging/Channel.cs +++ b/src/DotNetOAuth/Messaging/Channel.cs @@ -84,9 +84,6 @@ namespace DotNetOAuth.Messaging { this.messageTypeProvider = messageTypeProvider;
this.bindingElements = new List<IChannelBindingElement>(ValidateAndPrepareBindingElements(bindingElements));
-
- // Add a complete message check as a last outgoing step.
- this.bindingElements.Add(new EnsureCompleteMessageBindingElement());
}
/// <summary>
@@ -505,6 +502,9 @@ namespace DotNetOAuth.Messaging { if ((message.RequiredProtection & appliedProtection) != message.RequiredProtection) {
throw new UnprotectedMessageException(message, appliedProtection);
}
+
+ EnsureValidMessageParts(message);
+ message.EnsureValidMessage();
}
/// <summary>
@@ -536,14 +536,10 @@ namespace DotNetOAuth.Messaging { private void EnsureValidMessageParts(IProtocolMessage message) {
Debug.Assert(message != null, "message == null");
+
+ MessageDictionary dictionary = new MessageDictionary(message);
MessageDescription description = MessageDescription.Get(message.GetType());
- List<MessagePart> invalidParts = description.Mapping.Values.Where(part => !part.IsValidValue(message)).ToList();
- if (invalidParts.Count > 0) {
- throw new ProtocolException(string.Format(
- CultureInfo.CurrentCulture,
- MessagingStrings.InvalidMessageParts,
- string.Join(", ", invalidParts.Select(part => part.Name).ToArray())));
- }
+ description.EnsureRequiredMessagePartsArePresent(dictionary.Keys);
}
}
}
diff --git a/src/DotNetOAuth/Messaging/Reflection/MessagePart.cs b/src/DotNetOAuth/Messaging/Reflection/MessagePart.cs index 3f64e63..6556ffe 100644 --- a/src/DotNetOAuth/Messaging/Reflection/MessagePart.cs +++ b/src/DotNetOAuth/Messaging/Reflection/MessagePart.cs @@ -99,10 +99,6 @@ namespace DotNetOAuth.Messaging.Reflection { }
}
- internal bool IsValidValue(IProtocolMessage message) {
- return true;
- }
-
private static object deriveDefaultValue(Type type) {
if (type.IsValueType) {
return Activator.CreateInstance(type);
|