Ejemplo n.º 1
0
 /// <summary>
 /// Constructs the field generator.
 /// </summary>
 /// <param name="htmlHelper">The HTML helper for the current view</param>
 /// <param name="fieldProperty">Expression to identify the property to generate the field for</param>
 /// <param name="template">The template being used to output the form</param>
 public DefaultFieldGenerator(HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, T> > fieldProperty, IFormTemplate template)
 {
     HtmlHelper    = htmlHelper;
     FieldProperty = fieldProperty;
     Template      = template;
     Metadata      = ModelMetadata.FromLambdaExpression(FieldProperty, HtmlHelper.ViewData);
 }
Ejemplo n.º 2
0
 public void Setup()
 {
     _autoSubstitute = AutoSubstituteContainer.Create();
     _h = _autoSubstitute.ResolveAndSubstituteFor <HtmlHelper <TestFieldViewModel> >();
     _t = _autoSubstitute.Resolve <IFormTemplate>();
     _t.BeginForm(Action, Method, _htmlAttributes, Enctype).Returns(_beginHtml);
     _t.EndForm().Returns(_endHtml);
 }
Ejemplo n.º 3
0
 public void Setup()
 {
     _autoSubstitute = AutoSubstituteContainer.Create();
     _h = _autoSubstitute.ResolveAndSubstituteFor<HtmlHelper<TestFieldViewModel>>();
     _t = _autoSubstitute.Resolve<IFormTemplate>();
     _t.BeginForm(Action, Method, _htmlAttributes, Enctype).Returns(_beginHtml);
     _t.EndForm().Returns(_endHtml);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Construct a Chameleon Form.
 /// Note: Contains a call to the virtual method Write.
 /// </summary>
 /// <param name="helper">The HTML Helper for the current view</param>
 /// <param name="template">A template renderer instance to use to render the form</param>
 /// <param name="action">The action the form should submit to</param>
 /// <param name="method">The HTTP method the form submission should use</param>
 /// <param name="htmlAttributes">Any HTML attributes the form should use expressed as an anonymous object</param>
 /// <param name="enctype">The encoding type the form submission should use</param>
 public Form(HtmlHelper <TModel> helper, IFormTemplate template, string action, FormMethod method, HtmlAttributes htmlAttributes, EncType?enctype)
 {
     HtmlHelper = helper;
     Template   = template;
     // ReSharper disable DoNotCallOverridableMethodsInConstructor
     // Write method is virtual to allow it to be mocked for testing
     Write(Template.BeginForm(action, method, htmlAttributes, enctype));
     // ReSharper restore DoNotCallOverridableMethodsInConstructor
 }
 /// <summary>
 /// Constructs the field generator.
 /// </summary>
 /// <param name="htmlHelper">The HTML helper for the current view</param>
 /// <param name="fieldProperty">Expression to identify the property to generate the field for</param>
 /// <param name="template">The template being used to output the form</param>
 public DefaultFieldGenerator(IHtmlHelper <TModel> htmlHelper, Expression <Func <TModel, T> > fieldProperty, IFormTemplate template)
 {
     HtmlHelper    = htmlHelper;
     FieldProperty = fieldProperty;
     Template      = template;
     Metadata      = htmlHelper.ViewContext.HttpContext.RequestServices
                     .GetRequiredService <ModelExpressionProvider>()
                     .CreateModelExpression(htmlHelper.ViewData, fieldProperty)
                     .Metadata;
 }
Ejemplo n.º 6
0
        public void Setup()
        {
            _context = new MvcTestContext();
            var viewContext = _context.GetViewTestContext <TestFieldViewModel>();

            _h = viewContext.HtmlHelper;

            _t = Substitute.For <IFormTemplate>();
            _t.BeginForm(Action, Method, _htmlAttributes, Enctype).Returns(_beginHtml);
            _t.EndForm().Returns(_endHtml);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Construct a Chameleon Form.
 /// Note: Contains a call to the virtual method Write.
 /// </summary>
 /// <param name="helper">The HTML Helper for the current view</param>
 /// <param name="template">A template renderer instance to use to render the form</param>
 /// <param name="action">The action the form should submit to</param>
 /// <param name="method">The HTTP method the form submission should use</param>
 /// <param name="htmlAttributes">Any HTML attributes the form should use expressed as an anonymous object</param>
 /// <param name="enctype">The encoding type the form submission should use</param>
 /// <param name="outputAntiforgeryToken">Whether or not to output an antiforgery token in the form; defaults to null which will output a token if the method isn't GET</param>
 public Form(IHtmlHelper <TModel> helper, IFormTemplate template, string action, FormMethod method, HtmlAttributes htmlAttributes, EncType?enctype, bool?outputAntiforgeryToken)
 {
     _outputAntiforgeryToken = outputAntiforgeryToken ?? method != FormMethod.Get;
     helper.ViewData[Constants.ViewDataFormKey] = this;
     HtmlHelper = helper;
     Template   = template;
     // ReSharper disable DoNotCallOverridableMethodsInConstructor
     // Write method is virtual to allow it to be mocked for testing
     Write(Template.BeginForm(action, method, htmlAttributes, enctype));
     // ReSharper restore DoNotCallOverridableMethodsInConstructor
 }
Ejemplo n.º 8
0
 public void ProvideTemplate(IFormTemplate template)
 {
     Services.GetRequiredService <FormTemplateProvider>().Template = template;
 }
 public FormInstance(IFormTemplate template)
 {
     Id   = 0;
     Html = template.Body;
 }