public static void ValidateRepeaterControl(ResolvedTreeRoot resolvedTreeRoot) { ValidateAddTaskControlBindings(resolvedTreeRoot); DotHtmlCommonValidator.CheckControlTypeCount <Repeater>(resolvedTreeRoot, 1); var repeater = resolvedTreeRoot.GetDescendantControls <Repeater>().Single(); DotHtmlCommonValidator.ValidatePropertyBinding(resolvedTreeRoot, CreateStep6Property()); DotHtmlCommonValidator.CheckCountOfHtmlTag(resolvedTreeRoot, "div", 1); IAbstractPropertySetter setter; if (!repeater.TryGetProperty(Repeater.ItemTemplateProperty, out setter) || !(setter is ResolvedPropertyTemplate)) { throw new CodeValidationException(Lesson2Texts.RepeaterTemplateMissingDivError); } var template = (ResolvedPropertyTemplate)setter; var div = template.GetDescendantControls <HtmlGenericControl>().ToList(); if (div.Count(d => d.DothtmlNode.As <DothtmlElementNode>()?.TagName == "div") != 1) { throw new CodeValidationException(Lesson2Texts.RepeaterTemplateMissingDivError); } }
public void Validate(ResolvedTreeRoot resolvedTreeRoot) { Lesson1CommonValidator.ValidateTextBoxBindings(resolvedTreeRoot); resolvedTreeRoot.GetDescendantControls <Button>().Single() .ValidateCommandBindingExpression(ButtonBase.ClickProperty, "Calculate()"); var buttonTextBinding = resolvedTreeRoot.GetDescendantControls <Button>() .Select(c => c.GetValue(ButtonBase.TextProperty)) .SingleOrDefault(); if (buttonTextBinding == null) { throw new CodeValidationException(Lesson1Texts.ButtonDoesNotHaveText); } }
public void Validate(ResolvedTreeRoot resolvedTreeRoot) { Lesson2CommonValidator.ValidateRepeaterTemplate3(resolvedTreeRoot); var template = resolvedTreeRoot.GetDescendantControls <Repeater>().Single() .Properties[Repeater.ItemTemplateProperty] .CastTo <ResolvedPropertyTemplate>(); List <ResolvedControl> resolvedControls = template .GetDescendantControls <HtmlGenericControl>() .ToList(); var div = resolvedControls.First(d => d.DothtmlNode.As <DothtmlElementNode>()?.TagName == "div"); List <ResolvedPropertyBinding> divClassProperties = div.Properties .Where(p => p.Value.Property.Name == "Attributes:class") .Select(p => p.Value) .OfType <ResolvedPropertyBinding>() .ToList(); if (divClassProperties.Count != 1) { throw new CodeValidationException(Lesson2Texts.InvalidClassBinding); } var classBinding = divClassProperties[0].Binding.Value.Replace(" ", "").Replace("\"", "'"); if ((classBinding != "IsCompleted?'task-completed':'task'") && (classBinding != "IsCompleted==true?'task-completed':'task'") && (classBinding != "!IsCompleted?'task':'task-completed'") && (classBinding != "IsCompleted==false?'task':'task-completed'")) { throw new CodeValidationException(Lesson2Texts.InvalidClassExpressionBinding); } }
public static void ValidateAddTaskControlBindings(ResolvedTreeRoot root) { ValidateAddTaskControls(root); DotHtmlCommonValidator.ValidatePropertyBinding(root, CreateStep3Property()); root.GetDescendantControls <Button>().Single() .ValidateCommandBindingExpression(ButtonBase.ClickProperty, "AddTask()"); }
public static void ValidateAddTaskControls(ResolvedTreeRoot resolvedTreeRoot) { DotHtmlCommonValidator.CheckControlTypeCount <TextBox>(resolvedTreeRoot, 1); DotHtmlCommonValidator.CheckControlTypeCount <Button>(resolvedTreeRoot, 1); var buttonText = resolvedTreeRoot.GetDescendantControls <Button>() .Select(c => c.GetValue(ButtonBase.TextProperty)) .SingleOrDefault(); if (buttonText == null) { throw new CodeValidationException(Lesson2Texts.ButtonDoesNotHaveText); } }
public void Validate(ResolvedTreeRoot resolvedTreeRoot) { DotHtmlCommonValidator.ValidatePropertiesBindings(resolvedTreeRoot, Lesson3CommonValidator.CreateStep6Properties()); Lesson3CommonValidator.CheckStep5Controls(resolvedTreeRoot); DotHtmlCommonValidator.CheckControlTypeCount <CheckBox>(resolvedTreeRoot, 3); var checkboxes = resolvedTreeRoot.GetDescendantControls <CheckBox>().ToList(); if (!checkboxes.Any(c => c.GetValue(CheckableControlBase.CheckedValueProperty) == "M")) { throw new CodeValidationException(string.Format(ValidationErrorMessages.PropertyValueError, "CheckedValue", "M")); } if (!checkboxes.Any(c => c.GetValue(CheckableControlBase.CheckedValueProperty) == "S")) { throw new CodeValidationException(string.Format(ValidationErrorMessages.PropertyValueError, "CheckedValue", "S")); } if (!checkboxes.Any(c => c.GetValue(CheckableControlBase.CheckedValueProperty) == "N")) { throw new CodeValidationException(string.Format(ValidationErrorMessages.PropertyValueError, "CheckedValue", "N")); } }
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); }