Пример #1
0
        public void RenderWithTextsAndValues()
        {
            // Setup
            DropDownList c = new DropDownList();

            c.Name = "nameKey";

            ViewDataContainer vdc = new ViewDataContainer();

            vdc.Controls.Add(c);
            vdc.ViewData            = new ViewDataDictionary();
            vdc.ViewData["nameKey"] = new SelectList(
                new[] {
                new { Text = "aaa", Value = "111" },
                new { Text = "bbb", Value = "222" },
                new { Text = "ccc", Value = "333" }
            },
                "Value",
                "Text",
                "222");

            // Execute
            string html = MvcTestHelper.GetControlRendering(c, false);

            // Verify
            Assert.AreEqual <string>(@"<select name=""nameKey"">
	<option value=""111"">
		aaa
	</option><option value=""222"" selected=""selected"">
		bbb
	</option><option value=""333"">
		ccc
	</option>
</select>", html);
        }
Пример #2
0
        public void RenderWithNoAttributes()
        {
            // Setup
            DropDownList c = new DropDownList();

            c.Name = "nameKey";

            ViewDataContainer vdc = new ViewDataContainer();

            vdc.Controls.Add(c);
            vdc.ViewData            = new ViewDataDictionary();
            vdc.ViewData["nameKey"] = new SelectList(new[] { "aaa", "bbb", "ccc" }, "bbb");

            // Execute
            string html = MvcTestHelper.GetControlRendering(c, false);

            // Verify
            Assert.AreEqual <string>(@"<select name=""nameKey"">
	<option>
		aaa
	</option><option selected=""selected"">
		bbb
	</option><option>
		ccc
	</option>
</select>", html);
        }
Пример #3
0
        public void RenderWithNoAttributes()
        {
            // Setup
            DropDownList c = new DropDownList();

            c.Name = "nameKey";

            ViewDataContainer vdc = new ViewDataContainer();

            vdc.Controls.Add(c);
            vdc.ViewData            = new ViewDataDictionary();
            vdc.ViewData["nameKey"] = new SelectList(new[] { "aaa", "bbb", "ccc" }, "bbb");

            // Execute
            string html = MvcTestHelper.GetControlRendering(c, false);

            // Verify
            Assert.Equal("<select name=\"nameKey\">" + Environment.NewLine
                         + "\t<option>" + Environment.NewLine
                         + "\t\taaa" + Environment.NewLine
                         + "\t</option><option selected=\"selected\">" + Environment.NewLine
                         + "\t\tbbb" + Environment.NewLine
                         + "\t</option><option>" + Environment.NewLine
                         + "\t\tccc" + Environment.NewLine
                         + "\t</option>" + Environment.NewLine
                         + "</select>",
                         html);
        }
Пример #4
0
        public void RenderWithNoNameInDesignModeRendersWithSampleData()
        {
            // Setup
            DropDownList c = new DropDownList();

            // Execute
            string html = MvcTestHelper.GetControlRendering(c, true);

            // Verify
            Assert.AreEqual <string>(@"<select>
	<option>
		Sample Item
	</option>
</select>", html);
        }
Пример #5
0
        public void RenderWithTextsAndValues()
        {
            // Setup
            DropDownList c = new DropDownList();

            c.Name = "nameKey";

            ViewDataContainer vdc = new ViewDataContainer();

            vdc.Controls.Add(c);
            vdc.ViewData            = new ViewDataDictionary();
            vdc.ViewData["nameKey"] = new SelectList(
                new[]
            {
                new { Text = "aaa", Value = "111" },
                new { Text = "bbb", Value = "222" },
                new { Text = "ccc", Value = "333" }
            },
                "Value",
                "Text",
                "222"
                );

            // Execute
            string html = MvcTestHelper.GetControlRendering(c, false);

            // Verify
            Assert.Equal(
                "<select name=\"nameKey\">"
                + Environment.NewLine
                + "\t<option value=\"111\">"
                + Environment.NewLine
                + "\t\taaa"
                + Environment.NewLine
                + "\t</option><option value=\"222\" selected=\"selected\">"
                + Environment.NewLine
                + "\t\tbbb"
                + Environment.NewLine
                + "\t</option><option value=\"333\">"
                + Environment.NewLine
                + "\t\tccc"
                + Environment.NewLine
                + "\t</option>"
                + Environment.NewLine
                + "</select>",
                html
                );
        }
Пример #6
0
        public void RenderWithNoNameInDesignModeRendersWithSampleData()
        {
            // Setup
            DropDownList c = new DropDownList();

            // Execute
            string html = MvcTestHelper.GetControlRendering(c, true);

            // Verify
            Assert.Equal("<select>" + Environment.NewLine
                         + "\t<option>" + Environment.NewLine
                         + "\t\tSample Item" + Environment.NewLine
                         + "\t</option>" + Environment.NewLine
                         + "</select>",
                         html);
        }