Add some tests to verify behaviour of Annotations
authorAlan McGovern <alan.mcgovern@gmail.com>
Fri, 20 Jul 2012 10:47:34 +0000 (11:47 +0100)
committerAlan McGovern <alan.mcgovern@gmail.com>
Fri, 20 Jul 2012 15:41:05 +0000 (16:41 +0100)
mcs/class/System.Xml.Linq/Test/System.Xml.Linq/XAttributeTest.cs

index afdc2b6a2b8ee5f82931eeb2bdc647d2476dc255..eb8012229ad0614b32c4b1e5019f8c496541c4fe 100644 (file)
@@ -26,6 +26,7 @@
 
 using System;
 using System.Collections.Generic;
+using System.Linq;
 using System.Xml;
 using System.Xml.Linq;
 
@@ -36,6 +37,29 @@ namespace MonoTests.System.Xml.Linq
        [TestFixture]
        public class XAttributeTest
        {
+               [Test]
+               public void Annotations_GetSubclass()
+               {
+                       var x = new XAttribute("foo", "bar");
+                       var annotation = new InvalidCastException();
+                       x.AddAnnotation(annotation);
+                       
+                       Assert.AreSame(annotation, x.Annotation<InvalidCastException>(), "#1");
+                       Assert.AreSame(annotation, x.Annotation<object>(), "#2");
+                       Assert.AreSame(annotation, x.Annotations<object>().Single (), "#3");
+               }
+
+               [Test]
+               public void Annotations_SameTypeTwice()
+               {
+                       var x = new XAttribute("foo", "bar");
+                       var first = new InvalidCastException();
+                       var second = new InvalidCastException();
+                       x.AddAnnotation(first);
+                       x.AddAnnotation(second);
+                       Assert.AreEqual(2, x.Annotations<object>().Count(), "#1");
+                       Assert.AreSame(first, x.Annotation<object>(), "#2");
+               }
 
                [Test]
                [ExpectedException (typeof (ArgumentNullException))]