Exemplo n.º 1
0
        public virtual void TestCloneAttributes()
        {
            AttributeSource src     = new AttributeSource();
            TermAttribute   termAtt = (TermAttribute)src.AddAttribute(typeof(TermAttribute));
            TypeAttribute   typeAtt = (TypeAttribute)src.AddAttribute(typeof(TypeAttribute));

            termAtt.SetTermBuffer("TestTerm");
            typeAtt.SetType("TestType");

            AttributeSource clone = src.CloneAttributes();

            System.Collections.IEnumerator it = clone.GetAttributeClassesIterator().GetEnumerator();
            Assert.IsTrue(it.MoveNext());
            Assert.AreEqual(typeof(TermAttribute), it.Current, "TermAttribute must be the first attribute");
            Assert.IsTrue(it.MoveNext());
            Assert.AreEqual(typeof(TypeAttribute), it.Current, "TypeAttribute must be the second attribute");
            Assert.IsFalse(it.MoveNext(), "No more attributes");

            TermAttribute termAtt2 = (TermAttribute)clone.GetAttribute(typeof(TermAttribute));
            TypeAttribute typeAtt2 = (TypeAttribute)clone.GetAttribute(typeof(TypeAttribute));

            Assert.IsFalse(ReferenceEquals(termAtt2, termAtt), "TermAttribute of original and clone must be different instances");
            Assert.IsFalse(ReferenceEquals(typeAtt2, typeAtt), "TypeAttribute of original and clone must be different instances");
            Assert.AreEqual(termAtt2, termAtt, "TermAttribute of original and clone must be equal");
            Assert.AreEqual(typeAtt2, typeAtt, "TypeAttribute of original and clone must be equal");
        }