示例#1
0
 public void FormElements()
 {
     var e = new FormElements();
     var f = e.Int(required: true);
     Assert.Equal("<input required=\"required\" name=\"f0\" value=\"\" type=\"number\" />", f.ToString());
     var result = f.Run(new Dictionary<string, string> {
         {"f0", ""},
     });
     var errorForm = result.Form.Render();
     Assert.Contains("errorinput", errorForm);
 }
示例#2
0
 public void LINQ_formlet_with_validation_error()
 {
     var e = new FormElements();
     var f = from name in e.Text()
             join age in e.Int() on 1 equals 1
             where age == 42
             select new { name, age };
     var r = f.Run(new Dictionary<string,string> {
         {"f0", "John"},
         {"f1", "44"},
     });
     Assert.False(r.Value.HasValue());
     Assert.Equal(1, r.Errors.Length);
 }
示例#3
0
 public void LINQ_formlet()
 {
     var e = new FormElements();
     var f = from name in e.Text()
             join _ in Formlet.Raw(X.E("br")) on 1 equals 1
             join age in e.Int() on 1 equals 1
             where age == 42
             select new { name, age };
     var r = f.Run(new Dictionary<string, string> {
         {"f0", "John"},
         {"f1", "42"},
     });
     Assert.True(r.Value.HasValue());
     Assert.Equal("John", r.Value.Value.name);
     Assert.Equal(42, r.Value.Value.age);
 }