protected XElement ParseSdt(ITagProcessor parentProcessor, XElement sdtElement)
        {
            ITagParser parser = null;
            switch (this.GetTagName(sdtElement).ToLower())
            {                
                case "htmlcontent":
                    parser = new HtmlContentParser();
                    break;

                case "text":
                    parser = new TextParser();
                    break;

                case "table":
                    parser = new TableParser();
                    break;

                case "repeater":
                    parser = new RepeaterParser();
                    break;

                case "if":
                    parser = new IfParser();
                    break;
            }
            return parser != null ? parser.Parse(parentProcessor, sdtElement) : sdtElement;
        }
 public void TestRepeaterNotClosed()
 {
     const string TagName = "EndRepeater";
     var endRepeater = TraverseUtils.TagElement(this.documentRoot, TagName);
     endRepeater.Remove();
     var parser = new RepeaterParser();
     try
     {
         parser.Parse(new TagProcessorMock<RepeaterProcessor>(), this.documentRoot.Descendants(WordMl.SdtName).First());
         Assert.Fail("An exception shoud've been thrown");
     }
     catch (Exception e)
     {
         Assert.AreEqual(string.Format(MessageStrings.TagNotFoundOrEmpty, TagName), e.Message);
     }
 }
        public void TestOkay()
        {
            var parser = new RepeaterParser();
            var tagProcessorMock = new TagProcessorMock<RepeaterProcessor>();
            parser.Parse(tagProcessorMock, this.documentRoot.Descendants(WordMl.SdtName).First());

            var result = tagProcessorMock.InnerProcessor.RepeaterTag;

            var repeaterElements = 
                TraverseUtils.ElementsBetween(result.StartRepeater, result.EndRepeater)
                             .Select(result.MakeElementCallback).ToList();
            Assert.AreEqual(1, repeaterElements.Count);

            var childrenOfFirstElement = repeaterElements.First().Elements.ToList();
            Assert.AreEqual(9, childrenOfFirstElement.Count);
            Assert.AreEqual("./Subject", childrenOfFirstElement[3].Expression);
            Assert.AreEqual(true, childrenOfFirstElement[5].IsIndex);
            Assert.AreEqual("./ExpireDate", childrenOfFirstElement[7].Expression);
            Assert.AreEqual("//test/certificates", result.Source);
        }
        public void TestParseNested()
        {
            var parser = new RepeaterParser();
            var rootProcessor = new RootProcessor();
            parser.Parse(rootProcessor, this.nestedDocumentRoot.Descendants(WordMl.SdtName).First());

            var repeaterProcessor = rootProcessor.Processors.First();
            var result = ((RepeaterProcessor)repeaterProcessor).RepeaterTag;

            var repeaterElements = 
                TraverseUtils.ElementsBetween(result.StartRepeater, result.EndRepeater)
                             .Select(result.MakeElementCallback).ToList();
            Assert.AreEqual(2, repeaterElements.Count);

            var textTag = repeaterElements.First();

            Assert.IsTrue(textTag.XElement.IsSdt());
            Assert.IsTrue(textTag.XElement.IsTag("Text"));

            var repeaterContent = repeaterElements[1].Elements.ToList();

            Assert.AreEqual(10, repeaterContent.Count);
            var textSdt = repeaterContent[3];
            Assert.IsNull(textSdt.Expression);
            Assert.IsTrue(textSdt.XElement.IsSdt());
            Assert.IsTrue(textSdt.XElement.IsTag("Text"));
            Assert.AreEqual("./Subject", repeaterContent[4].Expression);
            Assert.AreEqual(true, repeaterContent[6].IsIndex);
            Assert.AreEqual("./ExpireDate", repeaterContent[8].Expression);
            Assert.AreEqual("//test/certificates", result.Source);

            Assert.IsTrue(repeaterProcessor.Processors.All(p => p is TextProcessor));
            Assert.AreEqual(2, repeaterProcessor.Processors.Count);
        }