Beispiel #1
0
        public void AutoComplete_Off()
        {
            var model = new ExamplePostModel();

            var tag = model.Helper().InputText(f => f.String).AutoCompleteOff().RenderTag();

            tag.Attr("autocomplete").Should().Be("off");
        }
Beispiel #2
0
        public void Form_AutoCompleteDefault()
        {
            var model = new ExamplePostModel();

            var tag = model.Helper().InputText(f => f.String).RenderTag();

            tag.ToString().Should().NotContain("autocomplete");
        }
Beispiel #3
0
        public void NullValue()
        {
            var model = new ExamplePostModel();

            var tag = model.Helper().InputText(f => f.String).RenderTag();

            tag.Value().Should().Be("");
        }
Beispiel #4
0
        public void Size()
        {
            var model = new ExamplePostModel();

            var tag = model.Helper().Select(f => f.String, new Option[0]).Size(3).RenderTag();

            tag.Attr("size").Should().Be("3");
        }
Beispiel #5
0
        public void MutateControl()
        {
            var model = new ExamplePostModel();

            var group = model.Helper().FormGroup("test label", fg => fg.InputText(f => f.String)).Control(tb => tb.Value("override"));
            var tag   = Render(group);

            tag.Control.Value().Should().Be("override");
        }
Beispiel #6
0
        public void Form_AutoCompleteDefault()
        {
            var model = new ExamplePostModel {
                String = "existing value"
            };

            var tag = model.Helper().Form().RenderTag();

            tag.ToString().Should().NotContain("autocomplete");
        }
Beispiel #7
0
        public void FormGroup()
        {
            var model = new ExamplePostModel();

            var helper = FakeHtmlHelper.New(model);

            var group = helper.FormGroup("test label", fg => fg.InputText(f => f.String));
            var tags  = Render(group);

            tags.Label.Attr("for").Should().Be(tags.Control.Id());
        }
Beispiel #8
0
        public void NullableEnum()
        {
            var model = new ExamplePostModel {
                NullableEnum = ExamplePostModel.Values.Key2
            };

            var tag = model.Helper().Select(f => f.NullableEnum, _enumValues).RenderTag();

            var options = tag.Children;

            options.Select(o => o.HasAttr("selected")).Should().BeEquivalentTo(false, true, false);
        }
Beispiel #9
0
        public void NullableBool()
        {
            var model = new ExamplePostModel {
                NullableBool = true
            };

            var tag = model.Helper().Select(f => f.NullableBool, _boolValues).RenderTag();

            var options = tag.Children;

            options.Select(o => o.HasAttr("selected")).Should().BeEquivalentTo(false, true);
        }
Beispiel #10
0
        public void InputNumber_String()
        {
            var model = new ExamplePostModel {
                String = "123"
            };

            var tag = model.Helper().InputNumber(f => f.String).RenderTag();

            tag.Attr("type").Should().Be("number");
            tag.Attr("name").Should().Be("String");
            tag.Attr("value").Should().Be("123");
        }
Beispiel #11
0
        public void Typed()
        {
            var model = new ExamplePostModel {
                String = "Key2"
            };

            var tag = model.Helper().Select(f => f.String, _stringValues).RenderTag();

            var optionTags = tag.Children;

            optionTags.Select(o => o.HasAttr("selected")).Should().BeEquivalentTo(false, true, false);
        }
Beispiel #12
0
        public void AutoComplete_Off()
        {
            var model = new ExamplePostModel {
                String = "existing value"
            };

            var tag = model.Helper().Form()
                      .AutoCompleteOff()
                      .RenderTag();

            tag.Attr("autocomplete").Should().Be("off");
        }
Beispiel #13
0
        public void String_NullValue()
        {
            var model = new ExamplePostModel {
                String = null
            };

            var tag = model.Helper().Select(f => f.String, _stringValues).Optional("<please select>").RenderTag();

            var options = tag.Children;

            options.Select(o => o.HasAttr("selected")).Count(s => s == true).Should().Be(0, "nothin should be selected");
        }
Beispiel #14
0
        public void Int()
        {
            var model = new ExamplePostModel {
                Int = 2
            };

            var tag = model.Helper().Select(f => f.Int, _intValues).RenderTag();

            var options = tag.Children;

            options.Select(o => o.HasAttr("selected")).Should().BeEquivalentTo(false, true, false);
        }
Beispiel #15
0
        public void InputNumber_NullableInt()
        {
            var model = new ExamplePostModel {
                NullableInt = 123
            };

            var tag = model.Helper().InputNumber(f => f.NullableInt).RenderTag();

            tag.Attr("type").Should().Be("number");
            tag.Attr("name").Should().Be("NullableInt");
            tag.Attr("value").Should().Be("123");
        }
Beispiel #16
0
        public void InputHidden_Long()
        {
            var model = new ExamplePostModel {
                Long = 123
            };

            var tag = model.Helper().InputHidden(f => f.Long).RenderTag();

            tag.TagName().Should().Be("input");
            tag.Attr("type").Should().Be("hidden");
            tag.Attr("name").Should().Be("Long");
            tag.Attr("value").Should().Be("123");
        }
Beispiel #17
0
        public void InputText()
        {
            var model = new ExamplePostModel {
                String = "existing value"
            };

            var tag = model.Helper().InputText(f => f.String).RenderTag();

            tag.Attr("type").Should().Be("text");
            tag.Attr("name").Should().Be("String");
            tag.Attr("id").Should().Be("String");
            tag.Attr("value").Should().Be("existing value");
        }
Beispiel #18
0
        public void Multiple()
        {
            var model = new ExamplePostModel {
                Strings = new[] { "Key2", "Key3" }
            };

            var tag = model.Helper().Select(f => f.Strings, _stringValues).RenderTag();

            tag.Attr("multiple").Should().Be("true");

            var options = tag.Children;

            options.Select(o => o.HasAttr("selected")).Should().BeEquivalentTo(false, true, true);
        }
Beispiel #19
0
        public void Typed_Optional()
        {
            var model = new ExamplePostModel {
                NullableEnum = ExamplePostModel.Values.Key2
            };

            var options = new Dictionary <ExamplePostModel.Values, string>
            {
                { ExamplePostModel.Values.Key1, "Value 1" },
                { ExamplePostModel.Values.Key2, "Value 2" },
                { ExamplePostModel.Values.Key3, "Value 3" },
            };

            var tag = model.Helper().Select(f => f.NullableEnum, options).Optional("<please select>").RenderTag();

            var optionTags = tag.Children;

            optionTags.Select(o => o.Text()).Should().BeEquivalentTo("<please select>", "Value 1", "Value 2", "Value 3");
            optionTags.Select(o => o.HasAttr("selected")).Should().BeEquivalentTo(false, false, true, false);
        }
Beispiel #20
0
        public void String()
        {
            var model = new ExamplePostModel {
                String = "Key2"
            };

            var tag = model.Helper().Select(f => f.String, _stringValues).Optional("<please select>").RenderTag();

            tag.TagName().Should().Be("select");
            tag.Attr("name").Should().Be("String");
            tag.Attr("id").Should().Be("String");

            var options = tag.Children;

            options.Select(o => o.HasAttr("value")).Should().AllBeEquivalentTo(true, "all key values should be set");
            options.Select(o => o.Attr("value")).Should().BeEquivalentTo("", "Key1", "Key2", "Key3");
            options.Select(o => o.Text()).Should().BeEquivalentTo("<please select>", "Value 1", "Value 2", "Value 3");

            options.Select(o => o.HasAttr("selected")).Count(s => s == true).Should().Be(1, "current value should be selected");
            options.Select(o => o.Attr("selected")).Should().BeEquivalentTo("", "", "selected", "");
        }
Beispiel #21
0
        public void OptGroups()
        {
            var model = new ExamplePostModel {
                String = "Key3"
            };

            var values = new List <Option>
            {
                Option.Value(null, "<please select>"),
                Option.Group("Primary", new []
                {
                    Option.Value("Key1", "value 1"),
                    Option.Value("Key2", "value 2"),
                }),
                Option.Group("Secondary", new []
                {
                    Option.Value("Key3", "value 3"),
                    Option.Value("Key4", "value 4"),
                }),
            };

            var tag = model.Helper().Select(f => f.String, values).RenderTag();

            var options = tag.Children;

            options.Select(o => o.TagName()).Should().BeEquivalentTo("option", "optgroup", "optgroup");

            {
                var primayGroup = options[1];
                primayGroup.Attr("label").Should().Be("Primary");
                primayGroup.Children.Select(t => t.Attr("value")).Should().BeEquivalentTo("Key1", "Key2");
            }
            {
                var secondaryGroup = options[2];
                secondaryGroup.Attr("label").Should().Be("Secondary");
                secondaryGroup.Children.Select(t => t.Attr("value")).Should().BeEquivalentTo("Key3", "Key4");
            }
        }