public virtual void TestToStringAndMultiAttributeImplementations() { AttributeSource src = new AttributeSource(); ITermAttribute termAtt = src.AddAttribute <ITermAttribute>(); ITypeAttribute typeAtt = src.AddAttribute <ITypeAttribute>(); termAtt.SetTermBuffer("TestTerm"); typeAtt.Type = "TestType"; Assert.AreEqual("(" + typeAtt.ToString() + "," + termAtt.ToString() + ")", src.ToString(), "Attributes should appear in original order"); System.Collections.Generic.IEnumerator <Attribute> it = src.GetAttributeImplsIterator().GetEnumerator(); Assert.IsTrue(it.MoveNext(), "Iterator should have 2 attributes left"); Assert.AreSame(typeAtt, it.Current, "First AttributeImpl from iterator should be typeAtt"); Assert.IsTrue(it.MoveNext(), "Iterator should have 1 attributes left"); Assert.AreSame(termAtt, it.Current, "Second AttributeImpl from iterator should be termAtt"); Assert.IsFalse(it.MoveNext(), "Iterator should have 0 attributes left"); src = new AttributeSource(); src.AddAttributeImpl(new Token()); // this should not add a new attribute as Token implements TermAttribute, too termAtt = src.AddAttribute <ITermAttribute>(); Assert.IsTrue(termAtt is Token, "TermAttribute should be implemented by Token"); // get the Token attribute and check, that it is the only one it = src.GetAttributeImplsIterator().GetEnumerator(); Assert.IsTrue(it.MoveNext()); Token tok = (Token)it.Current; Assert.IsFalse(it.MoveNext(), "There should be only one attribute implementation instance"); termAtt.SetTermBuffer("TestTerm"); Assert.AreEqual("(" + tok.ToString() + ")", src.ToString(), "Token should only printed once"); }