diff --git a/MvcContrib b/MvcContrib
new file mode 160000
index 0000000..8e205a6
--- /dev/null
+++ b/MvcContrib
@@ -0,0 +1 @@
+Subproject commit 8e205a6918fe9519406513f725dff30a04079de9
diff --git a/src/MVCContrib.4.5.resharper b/src/MVCContrib.4.5.resharper
index e23ae93..eeb9cac 100644
--- a/src/MVCContrib.4.5.resharper
+++ b/src/MVCContrib.4.5.resharper
@@ -18,7 +18,6 @@
False
4
NEXT_LINE
- True
- public
- protected
@@ -75,10 +74,8 @@
-
-
-
-
+
+
\ No newline at end of file
diff --git a/src/MVCContrib.UnitTests/FluentHtml/SelectTests.cs b/src/MVCContrib.UnitTests/FluentHtml/SelectTests.cs
index 2b863c5..a5f252e 100644
--- a/src/MVCContrib.UnitTests/FluentHtml/SelectTests.cs
+++ b/src/MVCContrib.UnitTests/FluentHtml/SelectTests.cs
@@ -108,14 +108,32 @@ public void basic_select_can_select_null_valued_options()
new FakeModel {Price = null, Title = "One"},
new FakeModel {Price = 2, Title = "Two"}
};
- var html = new Select("foo.Bar").Options(items, "Price", "Title").Selected(items[0].Price).ToString();
- var element = html.ShouldHaveHtmlNode("foo_Bar");
- var optionNodes = element.ShouldHaveChildNodesCount(2);
+ var optionNodes = new Select("foo.Bar").Options(items, "Price", "Title").Selected(items[0].Price).ToString()
+ .ShouldHaveHtmlNode("foo_Bar")
+ .ShouldHaveChildNodesCount(2);
+
optionNodes[0].ShouldBeSelectedOption(items[0].Price, items[0].Title);
optionNodes[1].ShouldBeUnSelectedOption(items[1].Price, items[1].Title);
}
+ [Test]
+ public void basic_select_can_set_selected_value_before_options()
+ {
+ var items = new List
+ {
+ new FakeModel {Price = 1, Title = "One"},
+ new FakeModel {Price = 2, Title = "Two"}
+ };
+
+ var optionNodes = new Select("foo.Bar").Options(items, "Price", "Title").Selected(items[1].Price).ToString()
+ .ShouldHaveHtmlNode("foo_Bar")
+ .ShouldHaveChildNodesCount(2);
+
+ optionNodes[0].ShouldBeUnSelectedOption(items[0].Price, items[0].Title);
+ optionNodes[1].ShouldBeSelectedOption(items[1].Price, items[1].Title);
+ }
+
[Test]
public void select_option_null_renders_with_no_options()
{
@@ -171,13 +189,27 @@ public void select_option_of_enumerable_select_list_item_renders_options()
public void select_with_lambda_selector_for_options_should_render()
{
var items = new List { new FakeModel {Price = 1, Title = "One"} };
- var html = new Select("x").Options(items, x => x.Price, x => x.Title).ToString();
-
- var element = html.ShouldHaveHtmlNode("x");
- var options = element.ShouldHaveChildNodesCount(1);
+ var options = new Select("x").Options(items, x => x.Price, x => x.Title).ToString()
+ .ShouldHaveHtmlNode("x")
+ .ShouldHaveChildNodesCount(1);
options[0].ShouldBeUnSelectedOption("1", "One");
}
+ [Test]
+ public void select_with_lambda_selector_can_called_selected_before_options()
+ {
+ var items = new List
+ {
+ new FakeModel { Price = 1, Title = "One" },
+ new FakeModel { Price = 2, Title = "Two" }
+ };
+ var options = new Select("x").Selected(2).Options(items, x => x.Price, x => x.Title).ToString()
+ .ShouldHaveHtmlNode("x")
+ .ShouldHaveChildNodesCount(2);
+ options[0].ShouldBeUnSelectedOption("1", "One");
+ options[1].ShouldBeSelectedOption("2", "Two");
+ }
+
[Test, ExpectedException(typeof(ArgumentNullException))]
public void select_options_with_null_text_field_selector_should_throw()
{
@@ -190,6 +222,17 @@ public void select_options_with_null_value_field_selector_should_throw()
new Select("x").Options(new List(), x => x.Price, null);
}
+ [Test]
+ public void select_options_with_simple_enumeration_of_objects_can_have_selected_called_first()
+ {
+ var optionNodes = new Select("foo").Selected(2).Options(new[] { 1, 2 }).ToString()
+ .ShouldHaveHtmlNode("foo")
+ .ShouldHaveChildNodesCount(2);
+
+ optionNodes[0].ShouldBeUnSelectedOption("1", "1");
+ optionNodes[1].ShouldBeSelectedOption("2", "2");
+ }
+
[Test]
public void select_options_with_simple_enumeration_of_objects_can_have_a_first_option_text_specified()
{