예제 #1
0
        public virtual void TestCloneAttributes()
        {
            AttributeSource src     = new AttributeSource();
            ITermAttribute  termAtt = src.AddAttribute <ITermAttribute>();
            ITypeAttribute  typeAtt = src.AddAttribute <ITypeAttribute>();

            termAtt.SetTermBuffer("TestTerm");
            typeAtt.Type = "TestType";

            var                types = new List <Type>();
            AttributeSource    clone = src.CloneAttributes();
            IEnumerator <Type> it    = clone.GetAttributeTypesIterator().GetEnumerator();

            Assert.IsTrue(it.MoveNext());
            types.Add(it.Current);
            Assert.IsTrue(it.MoveNext());
            types.Add(it.Current);
            Assert.IsFalse(it.MoveNext(), "No more attributes");

            Assert.Contains(typeof(ITypeAttribute), types, "TypeAttribute must be present in attributes");
            Assert.Contains(typeof(ITermAttribute), types, "TermAttribute must be present in attributes");

            ITermAttribute termAtt2 = clone.GetAttribute <ITermAttribute>();
            ITypeAttribute typeAtt2 = clone.GetAttribute <ITypeAttribute>();

            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");
        }
예제 #2
0
        public virtual void TestCloneAttributes()
        {
            AttributeSource src     = new AttributeSource();
            ITermAttribute  termAtt = src.AddAttribute <ITermAttribute>();
            ITypeAttribute  typeAtt = src.AddAttribute <ITypeAttribute>();

            termAtt.SetTermBuffer("TestTerm");
            typeAtt.Type = "TestType";

            AttributeSource clone = src.CloneAttributes();

            System.Collections.Generic.IEnumerator <Type> it = clone.GetAttributeTypesIterator().GetEnumerator();
            Assert.IsTrue(it.MoveNext());
            Assert.AreEqual(typeof(ITermAttribute), it.Current, "TermAttribute must be the first attribute");
            Assert.IsTrue(it.MoveNext());
            Assert.AreEqual(typeof(ITypeAttribute), it.Current, "TypeAttribute must be the second attribute");
            Assert.IsFalse(it.MoveNext(), "No more attributes");

            ITermAttribute termAtt2 = clone.GetAttribute <ITermAttribute>();
            ITypeAttribute typeAtt2 = clone.GetAttribute <ITypeAttribute>();

            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");
        }