summaryrefslogtreecommitdiffstats
path: root/src/DotNetOAuth.Test/Messaging/Reflection/MessagePartTests.cs
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2008-11-03 17:22:00 -0800
committerAndrew <andrewarnott@gmail.com>2008-11-04 08:12:52 -0800
commit462e19abd9034c11a12cad30e9899740f2bef8ff (patch)
treee08667f1d69249f8daa6c348a919bd0fd5434415 /src/DotNetOAuth.Test/Messaging/Reflection/MessagePartTests.cs
parent6a79be0eca3929d8fb4e797799dac8d6f7875475 (diff)
downloadDotNetOpenAuth-462e19abd9034c11a12cad30e9899740f2bef8ff.zip
DotNetOpenAuth-462e19abd9034c11a12cad30e9899740f2bef8ff.tar.gz
DotNetOpenAuth-462e19abd9034c11a12cad30e9899740f2bef8ff.tar.bz2
Changed namepace and project names in preparation for merge with DotNetOpenId.
Diffstat (limited to 'src/DotNetOAuth.Test/Messaging/Reflection/MessagePartTests.cs')
-rw-r--r--src/DotNetOAuth.Test/Messaging/Reflection/MessagePartTests.cs101
1 files changed, 0 insertions, 101 deletions
diff --git a/src/DotNetOAuth.Test/Messaging/Reflection/MessagePartTests.cs b/src/DotNetOAuth.Test/Messaging/Reflection/MessagePartTests.cs
deleted file mode 100644
index 90ccca4..0000000
--- a/src/DotNetOAuth.Test/Messaging/Reflection/MessagePartTests.cs
+++ /dev/null
@@ -1,101 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="MessagePartTests.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOAuth.Test.Messaging.Reflection {
- 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() {
- this.ParameterizedMessageTypeTest(typeof(MessageWithNonNullableOptionalStruct));
- }
-
- [TestMethod]
- public void RequiredNonNullableStruct() {
- this.ParameterizedMessageTypeTest(typeof(MessageWithNonNullableRequiredStruct));
- }
-
- [TestMethod]
- public void OptionalNullableStruct() {
- this.ParameterizedMessageTypeTest(typeof(MessageWithNullableOptionalStruct));
- }
-
- [TestMethod]
- public void RequiredNullableStruct() {
- this.ParameterizedMessageTypeTest(typeof(MessageWithNullableRequiredStruct));
- }
-
- [TestMethod, ExpectedException(typeof(ArgumentNullException))]
- public void CtorNullMember() {
- new MessagePart(null, new MessagePartAttribute());
- }
-
- [TestMethod, ExpectedException(typeof(ArgumentNullException))]
- public void CtorNullAttribute() {
- PropertyInfo field = typeof(MessageWithNullableOptionalStruct).GetProperty("OptionalInt", BindingFlags.NonPublic | BindingFlags.Instance);
- new MessagePart(field, null);
- }
-
- [TestMethod]
- public void SetValue() {
- var message = new MessageWithNonNullableRequiredStruct();
- MessagePart part = this.ParameterizedMessageTypeTest(message.GetType());
- part.SetValue(message, "5");
- Assert.AreEqual(5, message.OptionalInt);
- }
-
- [TestMethod]
- public void GetValue() {
- var message = new MessageWithNonNullableRequiredStruct();
- message.OptionalInt = 8;
- MessagePart part = this.ParameterizedMessageTypeTest(message.GetType());
- Assert.AreEqual("8", part.GetValue(message));
- }
-
- [TestMethod, ExpectedException(typeof(ArgumentException))]
- public void NonFieldOrPropertyMember() {
- MemberInfo method = typeof(MessageWithNullableOptionalStruct).GetMethod("Equals", BindingFlags.Public | BindingFlags.Instance);
- new MessagePart(method, new MessagePartAttribute());
- }
-
- private MessagePart ParameterizedMessageTypeTest(Type messageType) {
- 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; }
- }
- }
-}