diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2008-12-08 08:25:19 -0800 |
---|---|---|
committer | Andrew <andrewarnott@gmail.com> | 2008-12-08 08:25:19 -0800 |
commit | 05c075cd5400b8a4ad5f16f1f13979e25b89bb6f (patch) | |
tree | c76a0407a98ea97d4d85b082e2f0383093844d77 /src | |
parent | 01a75417c3ad7ed181d0a5e1ca2e8af0872af241 (diff) | |
download | DotNetOpenAuth-05c075cd5400b8a4ad5f16f1f13979e25b89bb6f.zip DotNetOpenAuth-05c075cd5400b8a4ad5f16f1f13979e25b89bb6f.tar.gz DotNetOpenAuth-05c075cd5400b8a4ad5f16f1f13979e25b89bb6f.tar.bz2 |
Added a couple of tests to test MinVersion/MaxVersion MessagePart behavior.
Diffstat (limited to 'src')
-rw-r--r-- | src/DotNetOpenAuth.Test/Messaging/Reflection/MessageDescriptionTests.cs | 68 | ||||
-rw-r--r-- | src/DotNetOpenAuth.Test/Messaging/Reflection/MessagePartTests.cs | 23 |
2 files changed, 91 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth.Test/Messaging/Reflection/MessageDescriptionTests.cs b/src/DotNetOpenAuth.Test/Messaging/Reflection/MessageDescriptionTests.cs index 47e86f7..7a1165b 100644 --- a/src/DotNetOpenAuth.Test/Messaging/Reflection/MessageDescriptionTests.cs +++ b/src/DotNetOpenAuth.Test/Messaging/Reflection/MessageDescriptionTests.cs @@ -6,6 +6,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection { using System; + using DotNetOpenAuth.Messaging; using DotNetOpenAuth.Messaging.Reflection; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -25,5 +26,72 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection { public void GetNonMessageType() { MessageDescription.Get(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)); + + // Verify that the AllVersion member appears in every version. + Assert.IsTrue(v10.Mapping.ContainsKey("AllVersion")); + Assert.IsTrue(v20.Mapping.ContainsKey("AllVersion")); + Assert.IsTrue(v25.Mapping.ContainsKey("AllVersion")); + Assert.IsTrue(v30.Mapping.ContainsKey("AllVersion")); + + // Verify that UpThru25 disappears in 3.0. + Assert.IsTrue(v10.Mapping.ContainsKey("UpThru25")); + Assert.IsTrue(v20.Mapping.ContainsKey("UpThru25")); + Assert.IsTrue(v25.Mapping.ContainsKey("UpThru25")); + Assert.IsFalse(v30.Mapping.ContainsKey("UpThru25")); + + // Verify that NewIn20 doesn't appear before that version. + Assert.IsFalse(v10.Mapping.ContainsKey("NewIn20")); + Assert.IsTrue(v20.Mapping.ContainsKey("NewIn20")); + Assert.IsTrue(v25.Mapping.ContainsKey("NewIn20")); + Assert.IsTrue(v30.Mapping.ContainsKey("NewIn20")); + + // Verify that an optional field in 1.0 becomes required in 2.0 + Assert.IsTrue(v10.Mapping.ContainsKey("RequiredIn20")); + Assert.IsFalse(v10.Mapping["RequiredIn20"].IsRequired); + Assert.IsTrue(v20.Mapping.ContainsKey("RequiredIn20")); + Assert.IsTrue(v20.Mapping["RequiredIn20"].IsRequired); + Assert.IsTrue(v25.Mapping.ContainsKey("RequiredIn20")); + Assert.IsTrue(v25.Mapping["RequiredIn20"].IsRequired); + Assert.IsTrue(v30.Mapping.ContainsKey("RequiredIn20")); + Assert.IsTrue(v30.Mapping["RequiredIn20"].IsRequired); + + // Verify that one (odd) field appeared in 1.0 as optional, + // disappeared in 2.0, and then reappeared in 2.5 and later as required. + Assert.IsTrue(v10.Mapping.ContainsKey("OptionalIn10RequiredIn25AndLater")); + Assert.IsFalse(v10.Mapping["OptionalIn10RequiredIn25AndLater"].IsRequired); + Assert.IsFalse(v20.Mapping.ContainsKey("OptionalIn10RequiredIn25AndLater")); + Assert.IsTrue(v25.Mapping.ContainsKey("OptionalIn10RequiredIn25AndLater")); + Assert.IsTrue(v25.Mapping["OptionalIn10RequiredIn25AndLater"].IsRequired); + Assert.IsTrue(v30.Mapping.ContainsKey("OptionalIn10RequiredIn25AndLater")); + Assert.IsTrue(v30.Mapping["OptionalIn10RequiredIn25AndLater"].IsRequired); + } + + private class MultiVersionMessage : Mocks.TestBaseMessage { +#pragma warning disable 0649 // these fields are never written to, but part of the test + [MessagePart] + public string AllVersion; + + [MessagePart(MaxVersion = "2.5")] + public string UpThru25; + + [MessagePart(MinVersion = "2.0")] + public string NewIn20; + + [MessagePart(IsRequired = false)] + [MessagePart(IsRequired = true, MinVersion = "2.0")] + public string RequiredIn20; + + [MessagePart(MinVersion = "1.0", MaxVersion = "1.0", IsRequired = false)] + [MessagePart(MinVersion = "2.5", IsRequired = true)] + public string OptionalIn10RequiredIn25AndLater; +#pragma warning restore 0649 + } } } diff --git a/src/DotNetOpenAuth.Test/Messaging/Reflection/MessagePartTests.cs b/src/DotNetOpenAuth.Test/Messaging/Reflection/MessagePartTests.cs index cdc5361..0215801 100644 --- a/src/DotNetOpenAuth.Test/Messaging/Reflection/MessagePartTests.cs +++ b/src/DotNetOpenAuth.Test/Messaging/Reflection/MessagePartTests.cs @@ -95,6 +95,19 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection { new MessagePart(method, new MessagePartAttribute()); } + [TestMethod] + public void RequiredMinAndMaxVersions() { + Type messageType = typeof(MessageWithMinAndMaxVersionParts); + FieldInfo newIn2Field = messageType.GetField("NewIn2", BindingFlags.Public | BindingFlags.Instance); + MessagePartAttribute newIn2Attribute = newIn2Field.GetCustomAttributes(typeof(MessagePartAttribute), true).OfType<MessagePartAttribute>().Single(); + + FieldInfo removedIn3Field = messageType.GetField("RemovedIn3", BindingFlags.Public | BindingFlags.Instance); + MessagePartAttribute removedIn3Attribute = removedIn3Field.GetCustomAttributes(typeof(MessagePartAttribute), true).OfType<MessagePartAttribute>().Single(); + + Assert.AreEqual(new Version(2, 0), newIn2Attribute.MinVersionValue); + Assert.AreEqual(new Version(2, 5), removedIn3Attribute.MaxVersionValue); + } + private static MessagePart GetMessagePart(Type messageType, string memberName) { FieldInfo field = messageType.GetField(memberName, BindingFlags.NonPublic | BindingFlags.Instance); MessagePartAttribute attribute = field.GetCustomAttributes(typeof(MessagePartAttribute), true).OfType<MessagePartAttribute>().Single(); @@ -147,5 +160,15 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection { private readonly string ConstantField = "abc"; #pragma warning restore 0414 } + + private class MessageWithMinAndMaxVersionParts : TestMessage { +#pragma warning disable 0649 // written to by reflection + [MessagePart(MinVersion = "2.0")] + public string NewIn2; + + [MessagePart(MaxVersion = "2.5")] + public string RemovedIn3; +#pragma warning restore 0649 + } } } |