public void Setup()
 {
     _autofixture = new Fixture();
       _model = new Mock<ITalesModel>();
       _element = Mock.Of<RenderingContext>();
       _sut = new PathExpressionEvaluator();
 }
Esempio n. 2
0
        /// <summary>
        /// Visit the given context and return a collection of the resultant contexts.
        /// </summary>
        /// <returns>Zero or more <see cref="IRenderingContext"/> instances, determined by the outcome of this visit.</returns>
        /// <param name="context">The rendering context to visit.</param>
        public override IRenderingContext[] Visit(IRenderingContext context)
        {
            if(context == null)
              {
            throw new ArgumentNullException(nameof(context));
              }

              IEnumerable<IRenderingContext>
            output = new [] { context },
            newlyExposedElements = new RenderingContext[0];

              var macroAttribute = context.Element.GetMetalAttribute(ZptConstants.Metal.DefineMacroAttribute);
              if(macroAttribute != null)
              {
            context.TalModel.AddLocal(MACRONAME, macroAttribute.Value);
              }

              foreach(var handler in _handlers)
              {
            var handlingResult = new HashSet<AttributeHandlingResult>();

            foreach(var ctx in output)
            {
              var processedBatch = handler.Handle(ctx);
              handlingResult.Add(processedBatch);
            }

            newlyExposedElements = newlyExposedElements.Union(handlingResult.SelectMany(x => x.NewlyExposedContexts));
            output = handlingResult.Where(x => x.ContinueHandling).SelectMany(x => x.Contexts).ToArray();
              }

              output = output.Union(newlyExposedElements.SelectMany(x => this.Visit(x)));

              return output.ToArray();
        }
Esempio n. 3
0
        public void Setup()
        {
            _autofixture = new Fixture();
              new RenderingContextCustomisation().Customize(_autofixture);

              _context = _autofixture.Create<RenderingContext>();
        }
        public void Setup()
        {
            _autofixture = new Fixture();
              new DummyModelCustomisation().Customize(_autofixture);

              _model = _autofixture.Create<DummyModel>();
              _element = new Mock<ZptElement>() { CallBase = true };
              _context = Mock.Of<RenderingContext>(x => x.Element == _element.Object && x.TalModel == _model);

              _element.Setup(x => x.Remove());
              _element.Setup(x => x.RemoveAllChildren());
              _element.Setup(x => x.ReplaceWith(It.IsAny<string>(), It.IsAny<bool>())).Returns(new ZptElement[0]);
              _element.Setup(x => x.ReplaceChildrenWith(It.IsAny<string>(), It.IsAny<bool>()));

              _sut = new ContentOrReplaceAttributeHandler();
        }
        public void Setup()
        {
            _autofixture = new Fixture();
              new DummyModelCustomisation().Customize(_autofixture);

              _model = _autofixture.Create<DummyModel>();
              _element = new Mock<ZptElement>() { CallBase = true };
              _context = Mock.Of<RenderingContext>(x => x.Element == _element.Object && x.TalModel == _model);

              _sut = new AttributesAttributeHandler();
        }
Esempio n. 6
0
        /// <summary>
        /// Creates and returns a new sibling rendering context.
        /// </summary>
        /// <returns>The sibling context.</returns>
        /// <param name="element">The ZPT element for which the new context is to be created.</param>
        /// <param name="cloneAttributes">A value indicating whether or not the element's attributes should be cloned or not.</param>
        public virtual IRenderingContext CreateSiblingContext(IZptElement element, bool cloneAttributes = false)
        {
            if(element == null)
              {
            throw new ArgumentNullException(nameof(element));
              }

              var output = new RenderingContext(this.MetalModel.CreateSiblingModel(),
                                        this.TalModel.CreateSiblingModel(),
                                        element,
                                        this.RenderingOptions,
                                        this.SourceAnnotationRootPath);

              if(cloneAttributes)
              {
            output.OriginalAttributes = this.OriginalAttributes;
              }

              return output;
        }
        public void Setup()
        {
            _autofixture = new Fixture();
              new RenderingContextCustomisation().Customize(_autofixture);

              _context = _autofixture.Create<RenderingContext>();
              _model = (DummyModel) _context.TalModel;

              _sut = new DefineAttributeHandler();
        }
Esempio n. 8
0
        /// <summary>
        /// Gets a collection of elements in the document which are defined as METAL macros.
        /// </summary>
        /// <returns>Elements representing the METAL macros.</returns>
        public override ITalesPathHandler GetMacros()
        {
            var output = this.Document
            .DocumentNode
            .DescendantsAndSelf()
            .Where(ele => ele.Attributes.Any(attr => attr.Name == String.Format("{0}:{1}",
                                                                            ZptConstants.Metal.Namespace.Prefix,
                                                                            ZptConstants.Metal.DefineMacroAttribute)))
            .Select(x => {
              var element = new ZptHtmlElement(x, this.SourceFile, this, isImported: true);
              var context = new RenderingContext(Model.Empty, Model.Empty, element, GetDefaultOptions());
              return new Metal.MetalMacro(context.GetMetalAttribute(ZptConstants.Metal.DefineMacroAttribute).Value, element);
            })
            .ToArray();

              return new CSF.Zpt.Metal.MetalMacroCollection(output);
        }
Esempio n. 9
0
        /// <summary>
        /// Gets a collection of elements in the document which are defined as METAL macros.
        /// </summary>
        /// <returns>Elements representing the METAL macros.</returns>
        public override ITalesPathHandler GetMacros()
        {
            var xpath = String.Format("//*[@{0}:{1}]",
                                ZptConstants.Metal.Namespace.Prefix,
                                ZptConstants.Metal.DefineMacroAttribute);

              var reader = this.Document.CreateReader();
              var root = this.Document.Root;

              var nsManager = new XmlNamespaceManager(reader.NameTable);
              nsManager.AddNamespace(ZptConstants.Metal.Namespace.Prefix, ZptConstants.Metal.Namespace.Uri);

              var output = root
            .XPathSelectElements(xpath, nsManager)
            .Cast<XNode>()
            .Select(x => {
              var element = new ZptXmlLinqElement(x, this.SourceFile, this, isImported: true);
              var context = new RenderingContext(Model.Empty, Model.Empty, element, GetDefaultOptions());
              return new Metal.MetalMacro(context.GetMetalAttribute(ZptConstants.Metal.DefineMacroAttribute).Value, element);
            })
            .ToArray();

              return new CSF.Zpt.Metal.MetalMacroCollection(output);
        }
        public void Setup()
        {
            _autofixture = new Fixture();
              new DummyModelCustomisation().Customize(_autofixture);

              _model = _autofixture.Create<DummyModel>();
              _element = new Mock<ZptElement>() { CallBase = true };
              _parent = new Mock<ZptElement>() { CallBase = true };
              _clone = new Mock<ZptElement>() { CallBase = true };
              _context = Mock.Of<RenderingContext>(x => x.Element == _element.Object && x.TalModel == _model);

              _element.Setup(x => x.Remove());
              _element.Setup(x => x.Clone()).Returns(_clone.Object);
              _element.Setup(x => x.GetParentElement()).Returns(_parent.Object);
              _parent.Setup(x => x.InsertBefore(It.IsAny<ZptElement>(), _clone.Object)).Returns(_clone.Object);

              _sut = new RepeatAttributeHandler();
        }