public int Process(IContext context, string text) { TagContext tagContext = context as TagContext; if (tagContext == null) { throw new ArgumentException("TagHandler needs TagContext."); } string tagName = text.Substring(2, text.IndexOf('>') - 2); Tag tag; try { tag = (Tag)tagContext.Pop(); } catch (InvalidOperationException e) { throw new MissingOpeningTagException(tagName, e); } if (tag.Name != tagName) { throw new MissingClosingTagException(tagName); } return(text.Length); }
public void ProcessTagTestWithAttribute() { TagContext context = new TagContext(); OpenTagHandler handler = new OpenTagHandler(); int result = handler.Process(context, lineWithAttr); Tag tag = (Tag)context.Pop(); Assert.AreEqual("name", tag.Name); Assert.AreEqual("attr", tag.Attribute); Assert.AreEqual(1, tag.Value); Assert.AreEqual(lineWithAttr.IndexOf('>') + 1, result); }