public void checkbox_list_renders_in_a_div()
        {
            var html    = new CheckBoxList("foo.Bar").ToString();
            var element = html.ShouldHaveHtmlNode("foo_Bar");

            element.ShouldBeNamed(HtmlTag.Div).ShouldHaveChildNodesCount(0);
        }
        public void radio_renders_selected_item_as_checked()
        {
            var html = new CheckBoxList("foo.Bar").Options<FakeEnum>()
                .Selected(new[] { FakeEnum.Zero, FakeEnum.Two }).ToString();
            var element = html.ShouldHaveHtmlNode("foo_Bar");

            VerifyItem("foo.Bar", (int)FakeEnum.Zero, FakeEnum.Zero.ToString(), element, 0, true);
            VerifyItem("foo.Bar", (int)FakeEnum.One, FakeEnum.One.ToString(), element, 1, false);
            VerifyItem("foo.Bar", (int)FakeEnum.Two, FakeEnum.Two.ToString(), element, 2, true);
            VerifyItem("foo.Bar", (int)FakeEnum.Three, FakeEnum.Three.ToString(), element, 3, false);
        }
        public void radio_renders_selected_item_as_checked()
        {
            var html = new CheckBoxList("foo.Bar").Options <FakeEnum>()
                       .Selected(new[] { FakeEnum.Zero, FakeEnum.Two }).ToString();
            var element = html.ShouldHaveHtmlNode("foo_Bar");

            VerifyItem("foo.Bar", (int)FakeEnum.Zero, FakeEnum.Zero.ToString(), element, 0, true);
            VerifyItem("foo.Bar", (int)FakeEnum.One, FakeEnum.One.ToString(), element, 1, false);
            VerifyItem("foo.Bar", (int)FakeEnum.Two, FakeEnum.Two.ToString(), element, 2, true);
            VerifyItem("foo.Bar", (int)FakeEnum.Three, FakeEnum.Three.ToString(), element, 3, false);
        }
Exemple #4
0
 public void can_specify_item_class_for_checkbox_list()
 {
     var cssClass = "highClass";
     var html = new CheckBoxList("foo.Bar").Options<FakeEnum>().ItemClass(cssClass).ToString();
     var element = html.ShouldHaveHtmlNode("foo_Bar");
     var nodes = element.ShouldHaveChildNodesCount(8);
     foreach (var node in nodes)
     {
         node.ShouldHaveAttribute(HtmlAttribute.Class).WithValue(cssClass);
     }
 }
        public void can_generate_checkbox_list_with_formatted_items()
        {
            var items = new List<FakeModel>
            {
                new FakeModel { Price = 1, Title = "One" },
            };
            var html = new CheckBoxList("foo.Bar").Options(items, x => x.Price, x => x.Title)
                .ItemFormat("<div>{0}</div>").ToString();
            var element = html.ShouldHaveHtmlNode("foo_Bar");

            element.ShouldHaveChildNodesCount(1)[0].ShouldBeNamed(HtmlTag.Div);
        }
        public void can_specify_item_class_for_checkbox_list()
        {
            var cssClass = "highClass";
            var html     = new CheckBoxList("foo.Bar").Options <FakeEnum>().ItemClass(cssClass).ToString();
            var element  = html.ShouldHaveHtmlNode("foo_Bar");
            var nodes    = element.ShouldHaveChildNodesCount(8);

            foreach (var node in nodes)
            {
                node.ShouldHaveAttribute(HtmlAttribute.Class).WithValue(cssClass);
            }
        }
        public void can_generate_checkbox_list_from_model_choices()
        {
            var items = new List<FakeModel>
            {
                new FakeModel { Price = 1, Title = "One" },
                new FakeModel { Price = 2, Title = "Two" },
            };
            var html = new CheckBoxList("foo.Bar").Options(items, x => x.Price, x => x.Title).ToString();
            var element = html.ShouldHaveHtmlNode("foo_Bar");

            VerifyItem("foo.Bar", items[0].Price, items[0].Title, element, 0, false);
            VerifyItem("foo.Bar", items[1].Price, items[1].Title, element, 1, false);
        }
        public void can_generate_checkbox_list_with_formatted_items()
        {
            var items = new List <FakeModel>
            {
                new FakeModel {
                    Price = 1, Title = "One"
                },
            };
            var html = new CheckBoxList("foo.Bar").Options(items, x => x.Price, x => x.Title)
                       .ItemFormat("<div>{0}</div>").ToString();
            var element = html.ShouldHaveHtmlNode("foo_Bar");

            element.ShouldHaveChildNodesCount(1)[0].ShouldBeNamed(HtmlTag.Div);
        }
        public void can_modify_each_checkbox_element_using_the_option_data_item()
        {
            var items = new List<FakeModel>
            {
                new FakeModel { Price = 1, Title = "One" },
                new FakeModel { Price = 2, Title = "Two", Done = true },
            };
            const string name = "foo";
            var html = new CheckBoxList(name).Options(items, x => x.Price, x => x.Title)
                .EachOption((cb, opt, i) => cb.Disabled(((FakeModel)opt).Done)).ToString();
            var element = html.ShouldHaveHtmlNode(name);

            GetCheckBox(element, name, 0).ShouldNotHaveAttribute("disabled");
            GetCheckBox(element, name, 1).ShouldHaveAttribute("disabled");
        }
        public void can_generate_checkbox_list_from_model_choices()
        {
            var items = new List <FakeModel>
            {
                new FakeModel {
                    Price = 1, Title = "One"
                },
                new FakeModel {
                    Price = 2, Title = "Two"
                },
            };
            var html    = new CheckBoxList("foo.Bar").Options(items, x => x.Price, x => x.Title).ToString();
            var element = html.ShouldHaveHtmlNode("foo_Bar");

            VerifyItem("foo.Bar", items[0].Price, items[0].Title, element, 0, false);
            VerifyItem("foo.Bar", items[1].Price, items[1].Title, element, 1, false);
        }
        public void can_modify_each_checkbox_element_using_the_option_data_item()
        {
            var items = new List <FakeModel>
            {
                new FakeModel {
                    Price = 1, Title = "One"
                },
                new FakeModel {
                    Price = 2, Title = "Two", Done = true
                },
            };
            const string name = "foo";
            var          html = new CheckBoxList(name).Options(items, x => x.Price, x => x.Title)
                                .EachOption((cb, opt, i) => cb.Disabled(((FakeModel)opt).Done)).ToString();
            var element = html.ShouldHaveHtmlNode(name);

            GetCheckBox(element, name, 0).ShouldNotHaveAttribute("disabled");
            GetCheckBox(element, name, 1).ShouldHaveAttribute("disabled");
        }
 public void checkbox_list_renders_in_a_div()
 {
     var html = new CheckBoxList("foo.Bar").ToString();
     var element = html.ShouldHaveHtmlNode("foo_Bar");
     element.ShouldBeNamed(HtmlTag.Div).ShouldHaveChildNodesCount(0);
 }