Exemple #1
0
        public override XElement Parse(ITagProcessor parentProcessor, XElement startElement)
        {
            this.ValidateStartTag(startElement, StartTagName);
            var startTag = startElement;

            if (string.IsNullOrEmpty(startTag.Value))
            {
                throw new Exception(string.Format(MessageStrings.TagNotFoundOrEmpty, "If"));
            }

            var endTag = this.FindEndTag(startTag);

            var content    = TraverseUtils.ElementsBetween(startTag, endTag).ToList();
            var expression = startTag.GetExpression();

            var ifTag = new IfTag
            {
                Conidition = expression,
                EndIf      = endTag,
                IfContent  = content,
                StartIf    = startTag,
            };

            var ifProcessor = new IfProcessor {
                Tag = ifTag
            };

            if (content.Any())
            {
                this.GoDeeper(ifProcessor, content.First(), endTag);
            }
            parentProcessor.AddProcessor(ifProcessor);

            return(endTag);
        }
Exemple #2
0
        public void TestParseIfNested()
        {
            using (var docStream = AssemblyResourceHelper.GetResourceStream(this, "text_in_if_document.xml"))
            {
                doc = XDocument.Load(docStream);

                var           expectedRootProcessor = new RootProcessor();
                ITagProcessor expectedIfProcessor   = new IfProcessor();

                expectedIfProcessor.AddProcessor(new TextProcessor());
                var expectedIfProcessors = new List <ITagProcessor>(expectedIfProcessor.Processors);
                expectedRootProcessor.AddProcessor(expectedIfProcessor);
                var expectedRootProcessors = new List <ITagProcessor>(expectedRootProcessor.Processors);

                var actualRootProcessor = new RootProcessor();
                generalParser.Parse(actualRootProcessor, doc.Root);

                var actualRootProcessors = new List <ITagProcessor>(actualRootProcessor.Processors);
                Assert.AreEqual(expectedRootProcessors.Count, actualRootProcessors.Count);
                Assert.AreEqual(expectedRootProcessors[0].GetType(), actualRootProcessors[0].GetType());
                var actualIfProcessors = new List <ITagProcessor>(actualRootProcessors[0].Processors);
                Assert.AreEqual(expectedIfProcessors.Count, actualIfProcessors.Count);
                Assert.AreEqual(expectedIfProcessors[0].GetType(), actualIfProcessors[0].GetType());
                Assert.AreEqual(expectedIfProcessors[0].Processors.Count, expectedIfProcessors[0].Processors.Count);
            }
        }
        public override XElement Parse(ITagProcessor parentProcessor, XElement startElement)
        {
            this.ValidateStartTag(startElement, StartTagName);
            var startTag = startElement;

            if (string.IsNullOrEmpty(startTag.Value))
            {
                throw new Exception(string.Format(MessageStrings.TagNotFoundOrEmpty, "If"));
            }

            var endTag = this.FindEndTag(startTag);

            var content = TraverseUtils.ElementsBetween(startTag, endTag).ToList();
            var expression = startTag.GetExpression();

            var ifTag = new IfTag
                            {
                                Conidition = expression,
                                EndIf = endTag,
                                IfContent = content,
                                StartIf = startTag,
                            };

            var ifProcessor = new IfProcessor { Tag = ifTag };
            if (content.Any())
            {
                this.GoDeeper(ifProcessor, content.First(), endTag);
            }            
            parentProcessor.AddProcessor(ifProcessor);

            return endTag;
        }
Exemple #4
0
        public void TestParse()
        {
            var expectedTableProcessor = new TableProcessor();
            var expectedIfProcessor    = new IfProcessor();

            expectedIfProcessor.AddProcessor(new TextProcessor());
            expectedTableProcessor.AddProcessor(new TextProcessor());
            expectedTableProcessor.AddProcessor(expectedIfProcessor);
            var expectedRepeaterProcessor = new RepeaterProcessor();

            expectedRepeaterProcessor.AddProcessor(new TextProcessor());
            var expectedRootProcessor = new RootProcessor();

            expectedRootProcessor.AddProcessor(expectedTableProcessor);
            expectedRootProcessor.AddProcessor(expectedRepeaterProcessor);

            var actualRootProcessor = new RootProcessor();

            generalParser.Parse(actualRootProcessor, this.doc.Root);

            Assert.AreEqual(2, actualRootProcessor.Processors.Count);
            var actualInnerRootProcessors = new List <ITagProcessor>(actualRootProcessor.Processors);

            Assert.AreEqual(typeof(TableProcessor), actualInnerRootProcessors[0].GetType());
            Assert.AreEqual(typeof(RepeaterProcessor), actualInnerRootProcessors[1].GetType());

            var actualTableProcessor = actualInnerRootProcessors[0];

            Assert.AreEqual(2, actualTableProcessor.Processors.Count);
            var actualInnerTableProcessors = new List <ITagProcessor>(actualTableProcessor.Processors);

            Assert.AreEqual(typeof(TextProcessor), actualInnerTableProcessors[0].GetType());
            Assert.AreEqual(typeof(IfProcessor), actualInnerTableProcessors[1].GetType());

            Assert.AreEqual(0, actualInnerTableProcessors[0].Processors.Count);
            var actualIfProcessor = actualInnerTableProcessors[1];

            Assert.AreEqual(1, actualIfProcessor.Processors.Count);
            var actualInnerIfProcessors = new List <ITagProcessor>(actualIfProcessor.Processors);

            Assert.AreEqual(typeof(TextProcessor), actualInnerIfProcessors[0].GetType());

            var actualRepeaterProcessor = actualInnerRootProcessors[1];

            Assert.AreEqual(1, actualRepeaterProcessor.Processors.Count);
            var actualInnerRepeaterProcessors = new List <ITagProcessor>(actualRepeaterProcessor.Processors);

            Assert.AreEqual(typeof(TextProcessor), actualInnerRepeaterProcessors[0].GetType());
            Assert.AreEqual(0, actualInnerRepeaterProcessors[0].Processors.Count);
        }
        public void TestParse()
        {
            var expectedTableProcessor = new TableProcessor();
            var expectedIfProcessor = new IfProcessor();
            expectedIfProcessor.AddProcessor(new TextProcessor());
            expectedTableProcessor.AddProcessor(new TextProcessor());
            expectedTableProcessor.AddProcessor(expectedIfProcessor);
            var expectedRepeaterProcessor = new RepeaterProcessor();
            expectedRepeaterProcessor.AddProcessor(new TextProcessor());
            var expectedRootProcessor = new RootProcessor();
            expectedRootProcessor.AddProcessor(expectedTableProcessor);
            expectedRootProcessor.AddProcessor(expectedRepeaterProcessor);

            var actualRootProcessor = new RootProcessor();
            generalParser.Parse(actualRootProcessor, this.doc.Root);

            Assert.AreEqual(2, actualRootProcessor.Processors.Count);
            var actualInnerRootProcessors = new List<ITagProcessor>(actualRootProcessor.Processors);
            Assert.AreEqual(typeof(TableProcessor), actualInnerRootProcessors[0].GetType());
            Assert.AreEqual(typeof(RepeaterProcessor), actualInnerRootProcessors[1].GetType());

            var actualTableProcessor = actualInnerRootProcessors[0];
            Assert.AreEqual(2, actualTableProcessor.Processors.Count);
            var actualInnerTableProcessors = new List<ITagProcessor>(actualTableProcessor.Processors);
            Assert.AreEqual(typeof(TextProcessor), actualInnerTableProcessors[0].GetType());
            Assert.AreEqual(typeof(IfProcessor), actualInnerTableProcessors[1].GetType());

            Assert.AreEqual(0, actualInnerTableProcessors[0].Processors.Count);
            var actualIfProcessor = actualInnerTableProcessors[1];

            Assert.AreEqual(1, actualIfProcessor.Processors.Count);
            var actualInnerIfProcessors = new List<ITagProcessor>(actualIfProcessor.Processors);
            Assert.AreEqual(typeof(TextProcessor), actualInnerIfProcessors[0].GetType());

            var actualRepeaterProcessor = actualInnerRootProcessors[1];
            Assert.AreEqual(1,actualRepeaterProcessor.Processors.Count);
            var actualInnerRepeaterProcessors = new List<ITagProcessor>(actualRepeaterProcessor.Processors);
            Assert.AreEqual(typeof(TextProcessor), actualInnerRepeaterProcessors[0].GetType());
            Assert.AreEqual(0, actualInnerRepeaterProcessors[0].Processors.Count);
        }
        public void TestParseIfNested()
        {
            using (var docStream = AssemblyResourceHelper.GetResourceStream(this, "text_in_if_document.xml"))
            {
                doc = XDocument.Load(docStream);

                var expectedRootProcessor = new RootProcessor();
                ITagProcessor expectedIfProcessor = new IfProcessor();

                expectedIfProcessor.AddProcessor(new TextProcessor());
                var expectedIfProcessors = new List<ITagProcessor>(expectedIfProcessor.Processors);
                expectedRootProcessor.AddProcessor(expectedIfProcessor);
                var expectedRootProcessors = new List<ITagProcessor>(expectedRootProcessor.Processors);

                var actualRootProcessor = new RootProcessor();
                generalParser.Parse(actualRootProcessor, doc.Root);

                var actualRootProcessors = new List<ITagProcessor>(actualRootProcessor.Processors);
                Assert.AreEqual(expectedRootProcessors.Count, actualRootProcessors.Count);
                Assert.AreEqual(expectedRootProcessors[0].GetType(), actualRootProcessors[0].GetType());
                var actualIfProcessors = new List<ITagProcessor>(actualRootProcessors[0].Processors);
                Assert.AreEqual(expectedIfProcessors.Count, actualIfProcessors.Count);
                Assert.AreEqual(expectedIfProcessors[0].GetType(), actualIfProcessors[0].GetType());
                Assert.AreEqual(expectedIfProcessors[0].Processors.Count, expectedIfProcessors[0].Processors.Count);
            }
        }