summaryrefslogtreecommitdiffstats
path: root/src/DotNetOAuth.Test/Messaging/Reflection
diff options
context:
space:
mode:
Diffstat (limited to 'src/DotNetOAuth.Test/Messaging/Reflection')
-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
4 files changed, 66 insertions, 59 deletions
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 {