protected override void beforeEach()
        {
            theElementRequest = ElementRequest.For <Address>(x => x.Address1);

            theAddress = new Address();
            MockFor <IFubuRequest>().Stub(x => x.Get(theElementRequest.HolderType()))
            .Return(theAddress);

            MockFor <IElementNamingConvention>().Stub(
                x => x.GetName(theElementRequest.HolderType(), theElementRequest.Accessor))
            .Return("the element name");

            ClassUnderTest.Activate(theElementRequest);
        }
Exemplo n.º 2
0
        protected override void modify(ElementRequest request)
        {
            var rules    = request.Get <ValidationGraph>().FieldRulesFor(request.HolderType(), request.Accessor);
            var modifier = request.Get <IFieldValidationModifier>();

            rules.Each(x => modifier.ModifyFor(x, request));
        }
Exemplo n.º 3
0
 public override void Activate(ElementRequest request)
 {
     base.Activate(request);
     if (request.Model == null)
     {
         request.Model = _request.Get(request.HolderType());
     }
 }
Exemplo n.º 4
0
        public HtmlTag Build(ElementRequest request)
        {
            request.ElementId = string.IsNullOrEmpty(request.ElementId)
                ? ElementNamingConvention.GetName(request.HolderType(), request.Accessor)
                : request.ElementId;

            var tag = Builder.Build(request);
            request.ReplaceTag(tag);

            _modifiers.Each(m => m.Modify(request));

            return request.CurrentTag;
        }
Exemplo n.º 5
0
        public bool Matches(ElementRequest elementRequest)
        {
            // TODO: Refactor this. Make it easier to get validator
            var container        = App.Container;
            var validatorFactory = container.GetInstance <IValidatorFactory>();

            _validator = validatorFactory.GetValidator(elementRequest.HolderType());

            if (_validator == null)
            {
                return(false);
            }

            return(_validator.DescriptorFor(elementRequest.Accessor.Name).Has <NotEmptyValidator>());
        }
        private static HtmlTag BuildCheckBox(ElementRequest request)
        {
            var namingConvention = new DotNotationElementNamingConvention();
            var name             = namingConvention.GetName(request.HolderType(), request.Accessor);

            var checkboxTag = new CheckboxTag(request.Value <bool>())
                              .Attr("value", "true")
                              .Attr("name", name)
                              .Attr("id", name);

            var mvcConventionHiddenInput = new HiddenTag()
                                           .Attr("value", "false")
                                           .Attr("name", name);

            checkboxTag.After(mvcConventionHiddenInput);
            return(checkboxTag);
        }
Exemplo n.º 7
0
        public static ValidatorRules ValidatorRules(this ElementRequest elementRequest)
        {
            var command = elementRequest.FindModel();

            var validator = (IValidator)elementRequest.Get(typeof(IValidator <>).MakeGenericType(command.GetType()));

            if (validator == null)
            {
                return(new ValidatorRules(new List <IPropertyValidator>()));
            }

            string propertyFullName = elementRequest.FindPropertyFullName();

            var builder = validator.RulesFor(propertyFullName);

            if (builder.Has <IPropertyValidator>())
            {
                return(builder);
            }

            // the property's owner type has a specialized validator
            validator = (IValidator)elementRequest.Get(typeof(IValidator <>).MakeGenericType(elementRequest.HolderType()));

            if (validator == null)
            {
                return(new ValidatorRules(new List <IPropertyValidator>()));
            }

            var propertyName = elementRequest.Accessor.Name;

            return(validator.RulesFor(propertyName));
        }
Exemplo n.º 8
0
        public void ForRule <T>(ElementRequest request, Action <T> continuation) where T : IFieldValidationRule
        {
            var graph = request.Get <ValidationGraph>();

            graph.Query().ForRule(request.HolderType(), request.Accessor, continuation);
        }
Exemplo n.º 9
0
        public bool Matches(ElementRequest elementRequest)
        {
            // var validatorFactory = elementRequest.Get<ValidatorFactory>();
            //
            // if (validatorFactory == null)
            //     return false;

            var validator = (IValidator)elementRequest.Get(typeof(IValidator <>).MakeGenericType(elementRequest.HolderType()));

            if (validator == null)
            {
                return(false);
            }

            if (validator.DescriptorFor(elementRequest.Accessor.Name).Has <NotEmptyValidator>())
            {
                return(true);
            }

            var childValidator = (IValidator)elementRequest.Get(typeof(IValidator <>).MakeGenericType(elementRequest.Accessor.OwnerType));

            if (childValidator == null)
            {
                return(false);
            }

            if (childValidator.DescriptorFor(elementRequest.Accessor.InnerProperty.Name).Has <NotEmptyValidator>())
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 10
0
        public bool Matches(ElementRequest elementRequest)
        {
            var validator = (IValidator)elementRequest.Get(typeof(IValidator <>).MakeGenericType(elementRequest.HolderType()));

            if (validator == null)
            {
                return(false);
            }

            if (validator.RulesFor(elementRequest.Accessor.Name).Has(typeof(NotEmptyValidator <,>)))
            {
                return(true);
            }

            var childValidator = (IValidator)elementRequest.Get(typeof(IValidator <>).MakeGenericType(elementRequest.Accessor.OwnerType));

            if (childValidator == null)
            {
                return(false);
            }

            if (childValidator.RulesFor(elementRequest.Accessor.InnerProperty.Name).Has(typeof(NotEmptyValidator <,>)))
            {
                return(true);
            }

            return(false);
        }