summaryrefslogtreecommitdiffstats
path: root/src/DotNetOAuth.Test/Messaging
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2008-09-21 12:39:32 -0700
committerAndrew <andrewarnott@gmail.com>2008-09-21 12:39:32 -0700
commit76c4a164c8af4b5239834934bfa8915a60678ed5 (patch)
treebcf40394f040fced8b7b121d4a2d7f9367c78985 /src/DotNetOAuth.Test/Messaging
parent3b3a1836352fc2d50cb2698f9a2910aa1f9ba0d2 (diff)
downloadDotNetOpenAuth-76c4a164c8af4b5239834934bfa8915a60678ed5.zip
DotNetOpenAuth-76c4a164c8af4b5239834934bfa8915a60678ed5.tar.gz
DotNetOpenAuth-76c4a164c8af4b5239834934bfa8915a60678ed5.tar.bz2
StylCop and FxCop work.
Diffstat (limited to 'src/DotNetOAuth.Test/Messaging')
-rw-r--r--src/DotNetOAuth.Test/Messaging/ChannelTests.cs1
-rw-r--r--src/DotNetOAuth.Test/Messaging/MessageSerializerTests.cs2
-rw-r--r--src/DotNetOAuth.Test/Messaging/MessagingTestBase.cs54
-rw-r--r--src/DotNetOAuth.Test/Messaging/Reflection/MessageDescriptionTests.cs13
-rw-r--r--src/DotNetOAuth.Test/Messaging/Reflection/MessageDictionaryTests.cs4
-rw-r--r--src/DotNetOAuth.Test/Messaging/Reflection/MessagePartTests.cs95
-rw-r--r--src/DotNetOAuth.Test/Messaging/Reflection/ValueMappingTests.cs13
7 files changed, 94 insertions, 88 deletions
diff --git a/src/DotNetOAuth.Test/Messaging/ChannelTests.cs b/src/DotNetOAuth.Test/Messaging/ChannelTests.cs
index e8c4514..8aeaa5b 100644
--- a/src/DotNetOAuth.Test/Messaging/ChannelTests.cs
+++ b/src/DotNetOAuth.Test/Messaging/ChannelTests.cs
@@ -14,7 +14,6 @@ namespace DotNetOAuth.Test.Messaging {
using DotNetOAuth.Messaging.Bindings;
using DotNetOAuth.Test.Mocks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
- using System.Xml;
[TestClass]
public class ChannelTests : MessagingTestBase {
diff --git a/src/DotNetOAuth.Test/Messaging/MessageSerializerTests.cs b/src/DotNetOAuth.Test/Messaging/MessageSerializerTests.cs
index a41753b..1d36b83 100644
--- a/src/DotNetOAuth.Test/Messaging/MessageSerializerTests.cs
+++ b/src/DotNetOAuth.Test/Messaging/MessageSerializerTests.cs
@@ -7,9 +7,9 @@
namespace DotNetOAuth.Test.Messaging {
using System;
using System.Collections.Generic;
+ using System.Xml;
using DotNetOAuth.Messaging;
using Microsoft.VisualStudio.TestTools.UnitTesting;
- using System.Xml;
/// <summary>
/// Tests for the <see cref="MessageSerializer"/> class.
diff --git a/src/DotNetOAuth.Test/Messaging/MessagingTestBase.cs b/src/DotNetOAuth.Test/Messaging/MessagingTestBase.cs
index 34cf1df..aa4f350 100644
--- a/src/DotNetOAuth.Test/Messaging/MessagingTestBase.cs
+++ b/src/DotNetOAuth.Test/Messaging/MessagingTestBase.cs
@@ -19,6 +19,30 @@ namespace DotNetOAuth.Test {
/// The base class that all messaging test classes inherit from.
/// </summary>
public class MessagingTestBase : TestBase {
+ internal enum FieldFill {
+ /// <summary>
+ /// An empty dictionary is returned.
+ /// </summary>
+ None,
+
+ /// <summary>
+ /// Only enough fields for the <see cref="TestMessageTypeProvider"/>
+ /// to identify the message are included.
+ /// </summary>
+ IdentifiableButNotAllRequired,
+
+ /// <summary>
+ /// All fields marked as required are included.
+ /// </summary>
+ AllRequired,
+
+ /// <summary>
+ /// All user-fillable fields in the message, leaving out those whose
+ /// values are to be set by channel binding elements.
+ /// </summary>
+ CompleteBeforeBindings,
+ }
+
internal Channel Channel { get; set; }
[TestInitialize]
@@ -85,30 +109,6 @@ namespace DotNetOAuth.Test {
return new TestChannel(typeProvider, bindingElements.ToArray());
}
- internal enum FieldFill {
- /// <summary>
- /// An empty dictionary is returned.
- /// </summary>
- None,
-
- /// <summary>
- /// Only enough fields for the <see cref="TestMessageTypeProvider"/>
- /// to identify the message are included.
- /// </summary>
- IdentifiableButNotAllRequired,
-
- /// <summary>
- /// All fields marked as required are included.
- /// </summary>
- AllRequired,
-
- /// <summary>
- /// All user-fillable fields in the message, leaving out those whose
- /// values are to be set by channel binding elements.
- /// </summary>
- CompleteBeforeBindings,
- }
-
internal static IDictionary<string, string> GetStandardTestFields(FieldFill fill) {
TestMessage expectedMessage = GetStandardTestMessage(fill);
@@ -152,8 +152,8 @@ namespace DotNetOAuth.Test {
internal void ParameterizedReceiveTest(string method) {
var fields = GetStandardTestFields(FieldFill.CompleteBeforeBindings);
- TestMessage expectedMessage = GetStandardTestMessage(FieldFill.CompleteBeforeBindings); ;
-
+ TestMessage expectedMessage = GetStandardTestMessage(FieldFill.CompleteBeforeBindings);
+
IProtocolMessage requestMessage = this.Channel.ReadFromRequest(CreateHttpRequestInfo(method, fields));
Assert.IsNotNull(requestMessage);
Assert.IsInstanceOfType(requestMessage, typeof(TestMessage));
@@ -164,7 +164,7 @@ namespace DotNetOAuth.Test {
}
internal void ParameterizedReceiveProtectedTest(DateTime? utcCreatedDate, bool invalidSignature) {
- TestMessage expectedMessage = GetStandardTestMessage(FieldFill.CompleteBeforeBindings); ;
+ TestMessage expectedMessage = GetStandardTestMessage(FieldFill.CompleteBeforeBindings);
var fields = GetStandardTestFields(FieldFill.CompleteBeforeBindings);
fields.Add("Signature", invalidSignature ? "badsig" : MockSigningBindingElement.MessageSignature);
fields.Add("Nonce", "someNonce");
diff --git a/src/DotNetOAuth.Test/Messaging/Reflection/MessageDescriptionTests.cs b/src/DotNetOAuth.Test/Messaging/Reflection/MessageDescriptionTests.cs
index 04c1df8..90c64dc 100644
--- a/src/DotNetOAuth.Test/Messaging/Reflection/MessageDescriptionTests.cs
+++ b/src/DotNetOAuth.Test/Messaging/Reflection/MessageDescriptionTests.cs
@@ -1,10 +1,13 @@
-namespace DotNetOAuth.Test.Messaging.Reflection {
+//-----------------------------------------------------------------------
+// <copyright file="MessageDescriptionTests.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOAuth.Test.Messaging.Reflection {
using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Microsoft.VisualStudio.TestTools.UnitTesting;
using DotNetOAuth.Messaging.Reflection;
+ using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public class MessageDescriptionTests : MessagingTestBase {
diff --git a/src/DotNetOAuth.Test/Messaging/Reflection/MessageDictionaryTests.cs b/src/DotNetOAuth.Test/Messaging/Reflection/MessageDictionaryTests.cs
index b1ae0b6..143e6b8 100644
--- a/src/DotNetOAuth.Test/Messaging/Reflection/MessageDictionaryTests.cs
+++ b/src/DotNetOAuth.Test/Messaging/Reflection/MessageDictionaryTests.cs
@@ -1,5 +1,5 @@
//-----------------------------------------------------------------------
-// <copyright file="MessageDictionaryTest.cs" company="Andrew Arnott">
+// <copyright file="MessageDictionaryTests.cs" company="Andrew Arnott">
// Copyright (c) Andrew Arnott. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
@@ -9,10 +9,10 @@ namespace DotNetOAuth.Test.Messaging.Reflection {
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
+ using System.Xml;
using DotNetOAuth.Messaging;
using DotNetOAuth.Messaging.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
- using System.Xml;
[TestClass]
public class MessageDictionaryTests : MessagingTestBase {
diff --git a/src/DotNetOAuth.Test/Messaging/Reflection/MessagePartTests.cs b/src/DotNetOAuth.Test/Messaging/Reflection/MessagePartTests.cs
index 0dba07b..90ccca4 100644
--- a/src/DotNetOAuth.Test/Messaging/Reflection/MessagePartTests.cs
+++ b/src/DotNetOAuth.Test/Messaging/Reflection/MessagePartTests.cs
@@ -1,61 +1,38 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using DotNetOAuth.Messaging.Reflection;
-using System.Reflection;
-using DotNetOAuth.Test.Mocks;
-using DotNetOAuth.Messaging;
+//-----------------------------------------------------------------------
+// <copyright file="MessagePartTests.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
namespace DotNetOAuth.Test.Messaging.Reflection {
- [TestClass]
- public class MessagePartTests :MessagingTestBase {
- class MessageWithNonNullableOptionalStruct : TestMessage {
- /// <summary>
- /// Optional structs like int must be nullable for Optional to make sense.
- /// </summary>
- [MessagePart(IsRequired = false)]
- internal int optionalInt = 0;
- }
- class MessageWithNonNullableRequiredStruct : TestMessage {
- /// <summary>
- /// This should work because a required field will always have a value so it
- /// need not be nullable.
- /// </summary>
- [MessagePart(IsRequired = true)]
- internal int optionalInt = 0;
- }
- class MessageWithNullableOptionalStruct : TestMessage {
- /// <summary>
- /// Optional structs like int must be nullable for Optional to make sense.
- /// </summary>
- [MessagePart(IsRequired = false)]
- internal int? optionalInt = 0;
- }
- class MessageWithNullableRequiredStruct : TestMessage {
- [MessagePart(IsRequired = true)]
- internal int? optionalInt = null;
- }
+ using System;
+ using System.Linq;
+ using System.Reflection;
+ using DotNetOAuth.Messaging;
+ using DotNetOAuth.Messaging.Reflection;
+ using DotNetOAuth.Test.Mocks;
+ using Microsoft.VisualStudio.TestTools.UnitTesting;
+ [TestClass]
+ public class MessagePartTests : MessagingTestBase {
[TestMethod, ExpectedException(typeof(ArgumentException))]
public void OptionalNonNullableStruct() {
- ParameterizedMessageTypeTest(typeof(MessageWithNonNullableOptionalStruct));
+ this.ParameterizedMessageTypeTest(typeof(MessageWithNonNullableOptionalStruct));
}
[TestMethod]
public void RequiredNonNullableStruct() {
- ParameterizedMessageTypeTest(typeof(MessageWithNonNullableRequiredStruct));
+ this.ParameterizedMessageTypeTest(typeof(MessageWithNonNullableRequiredStruct));
}
[TestMethod]
public void OptionalNullableStruct() {
- ParameterizedMessageTypeTest(typeof(MessageWithNullableOptionalStruct));
+ this.ParameterizedMessageTypeTest(typeof(MessageWithNullableOptionalStruct));
}
[TestMethod]
public void RequiredNullableStruct() {
- ParameterizedMessageTypeTest(typeof(MessageWithNullableRequiredStruct));
+ this.ParameterizedMessageTypeTest(typeof(MessageWithNullableRequiredStruct));
}
[TestMethod, ExpectedException(typeof(ArgumentNullException))]
@@ -65,23 +42,23 @@ namespace DotNetOAuth.Test.Messaging.Reflection {
[TestMethod, ExpectedException(typeof(ArgumentNullException))]
public void CtorNullAttribute() {
- FieldInfo field = typeof(MessageWithNullableOptionalStruct).GetField("optionalInt", BindingFlags.NonPublic | BindingFlags.Instance);
+ PropertyInfo field = typeof(MessageWithNullableOptionalStruct).GetProperty("OptionalInt", BindingFlags.NonPublic | BindingFlags.Instance);
new MessagePart(field, null);
}
[TestMethod]
public void SetValue() {
var message = new MessageWithNonNullableRequiredStruct();
- MessagePart part = ParameterizedMessageTypeTest(message.GetType());
+ MessagePart part = this.ParameterizedMessageTypeTest(message.GetType());
part.SetValue(message, "5");
- Assert.AreEqual(5, message.optionalInt);
+ Assert.AreEqual(5, message.OptionalInt);
}
[TestMethod]
public void GetValue() {
var message = new MessageWithNonNullableRequiredStruct();
- message.optionalInt = 8;
- MessagePart part = ParameterizedMessageTypeTest(message.GetType());
+ message.OptionalInt = 8;
+ MessagePart part = this.ParameterizedMessageTypeTest(message.GetType());
Assert.AreEqual("8", part.GetValue(message));
}
@@ -92,9 +69,33 @@ namespace DotNetOAuth.Test.Messaging.Reflection {
}
private MessagePart ParameterizedMessageTypeTest(Type messageType) {
- FieldInfo field = messageType.GetField("optionalInt", BindingFlags.NonPublic | BindingFlags.Instance);
+ PropertyInfo field = messageType.GetProperty("OptionalInt", BindingFlags.NonPublic | BindingFlags.Instance);
MessagePartAttribute attribute = field.GetCustomAttributes(typeof(MessagePartAttribute), true).OfType<MessagePartAttribute>().Single();
return new MessagePart(field, attribute);
}
+
+ private class MessageWithNonNullableOptionalStruct : TestMessage {
+ // Optional structs like int must be nullable for Optional to make sense.
+ [MessagePart(IsRequired = false)]
+ internal int OptionalInt { get; set; }
+ }
+
+ private class MessageWithNonNullableRequiredStruct : TestMessage {
+ // This should work because a required field will always have a value so it
+ // need not be nullable.
+ [MessagePart(IsRequired = true)]
+ internal int OptionalInt { get; set; }
+ }
+
+ private class MessageWithNullableOptionalStruct : TestMessage {
+ // Optional structs like int must be nullable for Optional to make sense.
+ [MessagePart(IsRequired = false)]
+ internal int? OptionalInt { get; set; }
+ }
+
+ private class MessageWithNullableRequiredStruct : TestMessage {
+ [MessagePart(IsRequired = true)]
+ private int? OptionalInt { get; set; }
+ }
}
}
diff --git a/src/DotNetOAuth.Test/Messaging/Reflection/ValueMappingTests.cs b/src/DotNetOAuth.Test/Messaging/Reflection/ValueMappingTests.cs
index 9142a0c..5def394 100644
--- a/src/DotNetOAuth.Test/Messaging/Reflection/ValueMappingTests.cs
+++ b/src/DotNetOAuth.Test/Messaging/Reflection/ValueMappingTests.cs
@@ -1,10 +1,13 @@
-namespace DotNetOAuth.Test.Messaging.Reflection {
+//-----------------------------------------------------------------------
+// <copyright file="ValueMappingTests.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOAuth.Test.Messaging.Reflection {
using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Microsoft.VisualStudio.TestTools.UnitTesting;
using DotNetOAuth.Messaging.Reflection;
+ using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public class ValueMappingTests {