예제 #1
0
        public void Validate(ResolvedTreeRoot resolvedTreeRoot)
        {
            DotHtmlCommonValidator.CheckCountOfHtmlTag(resolvedTreeRoot, "div", 3);
            Lesson4CommonValidator.ValidateStep2ValidationProperties(resolvedTreeRoot);
            Lesson4CommonValidator.ValidateOnlyStep3Properties(resolvedTreeRoot);

            var property = new Property("has-error", "none", ControlBindName.DivValidatorInvalidCssClass);

            DotHtmlCommonValidator.ValidatePropertyBinding(resolvedTreeRoot, property);

            var invalidCssException = new CodeValidationException(Lesson4Texts.AllDivsMustHaveInvalidCssClass);

            DotHtmlCommonValidator.CheckCountOfHtmlTagWithPropertyDescriptor(resolvedTreeRoot, "div", 3, Validator.InvalidCssClassProperty, invalidCssException);
        }
        public static void ValidateStep5(ResolvedTreeRoot resolvedTreeRoot)
        {
            var divEnwrapException = new CodeValidationException(Lesson4Texts.WrapDivsInForm);

            DotHtmlCommonValidator.CheckCountOfHtmlTag(resolvedTreeRoot, "form", 1, divEnwrapException);

            var property = new Property("has-error", "fakeProp", ControlBindName.FormValidatorInvalidCssClass);

            DotHtmlCommonValidator.ValidatePropertyBinding(resolvedTreeRoot, property);

            var contentNode = resolvedTreeRoot.GetDescendantControls <HtmlGenericControl>().
                              FirstOrDefault(d => d.DothtmlNode.As <DothtmlElementNode>()?.TagName == "form");

            DotHtmlCommonValidator.CheckCountOfHtmlTag(contentNode, "div", 3);

            var redundantInvalidCssException = new CodeValidationException(Lesson4Texts.ChildDivsDontNeedInvalidCssClassAnymore);

            ValidateStep2ValidationProperties(contentNode);
            DotHtmlCommonValidator.CheckCountOfHtmlTagWithPropertyDescriptor(contentNode, "div", 0, Validator.InvalidCssClassProperty, redundantInvalidCssException);

            property.TargetControlBindName = ControlBindName.DivValidatorInvalidCssClassRemove;
            DotHtmlCommonValidator.ValidatePropertyBinding(contentNode, property);
        }
예제 #3
0
        public static void CheckCountOfHtmlTagWithPropertyDescriptor(ResolvedContentNode resolvedTreeRoot, string htmlTag, int count, IPropertyDescriptor propertyDescriptor, CodeValidationException codeValidationException)
        {
            var counter = resolvedTreeRoot
                          .GetChildrenControls <HtmlGenericControl>()
                          .Where(d => d.DothtmlNode.As <DothtmlElementNode>()?.TagName == htmlTag)
                          .Count(d => d.GetValueOrNull(propertyDescriptor) != null);

            if (counter != count)
            {
                throw codeValidationException;
            }
        }
예제 #4
0
        public static void CheckCountOfHtmlTag(ResolvedContentNode resolvedTreeRoot, string htmlTag, int count, CodeValidationException codeValidationException = null)
        {
            var counter = resolvedTreeRoot
                          .GetChildrenControls <HtmlGenericControl>()
                          .Count(d => d.DothtmlNode.As <DothtmlElementNode>()?.TagName == htmlTag);

            if (counter != count)
            {
                if (codeValidationException == null)
                {
                    throw new CodeValidationException(string.Format(ValidationErrorMessages.HtmlTagCountError, count,
                                                                    htmlTag));
                }
                throw codeValidationException;
            }
        }