コード例 #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 RenderWithNoNameInDesignModeRendersWithSampleData() {
            // Setup
            DropDownList c = new DropDownList();

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

            // Verify
            Assert.AreEqual<string>(@"<select>
	<option>
		Sample Item
	</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.AreEqual<string>(@"<select name=""nameKey"">
	<option>
		aaa
	</option><option selected=""selected"">
		bbb
	</option><option>
		ccc
	</option>
</select>", html);
        }