Ejemplo n.º 1
0
 public void TestParseOfDoubleAttribute()
 {
     try
     {
         Base().Parse(
             "<c:if test=\"true\" test=\"true\">Y</c:if>");
         Assert.Fail("Expected exception");
     }
     catch (TagException Te)
     {
         Assert.That(Te.MessageWithOutContext, Is.EqualTo(TagException.PropertyAlReadySet("Test").Message));
     }
 }
Ejemplo n.º 2
0
        public void TestDoubleAttribute()
        {
            var model = new TagModel(new Hashtable());

            model.Page[Html.PAGE_MODEL_HTMLHELPER_INSTANCE] = GetHtmlHelper();
            model.Model["name"] = "name";
            try
            {
                CreateFactory().Parse("<html:textBox name=\"${Model.name}\" name=\"${Model.name}\"/>");
                Assert.Fail("Expected exception");
            }
            catch (TagException Te)
            {
                Assert.That(Te.MessageWithOutContext, Is.EqualTo(TagException.PropertyAlReadySet("name").Message));
            }
        }
Ejemplo n.º 3
0
        private void AddAttributes(ITagAttributeSetter tagReflection, ITag tag)
        {
            while (!_helper.IsAhead(CLOSING_TOKENS))
            {
//                _helper.Read(TokenType.Seperator);
                _helper.Next();
                ReadWhiteSpace(_helper);
                if (_helper.IsAhead(CLOSING_TOKENS))
                {
                    return;
                }
                var keyToken = _helper.Read(TokenType.Regular);
                var key      = tagReflection.SupportNaturalLanguage?LanguageHelper.CamelCaseAttribute(keyToken.Contents): keyToken.Contents;
                _helper.Read(TagLibConstants.FIELD_ASSIGNMENT);
                var value    = _helper.Read(TokenType.Literal).Contents;
                var existing = tagReflection[key];
                if (!existing?.AllowOverWrite ?? false)
                {
                    throw TagException.PropertyAlReadySet(key).Decorate(keyToken.Context);
                }
                if (string.IsNullOrEmpty(value))
                {
                    tagReflection[key] = new ConstantAttribute("", tag)
                    {
                        AttributeName = key, Context = keyToken.Context
                    };
                    continue;
                }
                if (!value.Contains("${"))
                {
                    tagReflection[key] = new ConstantAttribute(value, tag)
                    {
                        AttributeName = key, Context = keyToken.Context, ResourceLocator = _locator
                    };
                    continue;
                }
                var offSet = _helper.Current.Context;
                var attr   = new TemplateAttribute(new InternalFormatter(new TagLibParserFactoryAdapter(this), _expressionLib, value, false, _locator, offSet).Parse())
                {
                    AttributeName = key
                };
                tagReflection[key] = attr;
            }
        }