Skip to content

Commit

Permalink
Added some tests to verify you can call Selected before Options on se…
Browse files Browse the repository at this point in the history
…lect in FluentHtml
  • Loading branch information
timscott committed Oct 24, 2009
1 parent cb5a13e commit 96c3a1c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 12 deletions.
1 change: 1 addition & 0 deletions MvcContrib
Submodule MvcContrib added at 8e205a
7 changes: 2 additions & 5 deletions src/MVCContrib.4.5.resharper
Expand Up @@ -18,7 +18,6 @@
<INDENT_EMBRACED_INITIALIZER_BLOCK>False</INDENT_EMBRACED_INITIALIZER_BLOCK>
<INDENT_SIZE>4</INDENT_SIZE>
<INITIALIZER_BRACES>NEXT_LINE</INITIALIZER_BRACES>
<INSERT_TABS>True</INSERT_TABS>
<MODIFIERS_ORDER IsNull="False">
<Item>public</Item>
<Item>protected</Item>
Expand Down Expand Up @@ -75,10 +74,8 @@
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="StaticReadonly" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="EnumMember" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="Other" />
<PredefinedRule Inspect="True" Prefix="_" Suffix="" Style="aaBb" ElementKind="PrivateInstanceFields" />
<PredefinedRule Inspect="True" Prefix="_" Suffix="" Style="aaBb" ElementKind="PrivateStaticFields" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="PrivateConstants" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="PrivateStaticReadonly" />
<PredefinedRule Inspect="True" Prefix="_" Suffix="" Style="aaBb" ElementKind="NotPublicStaticFields" />
<PredefinedRule Inspect="True" Prefix="_" Suffix="" Style="aaBb" ElementKind="NotPublicInstanceFields" />
</Naming2>
</CodeStyleSettings>
</Configuration>
57 changes: 50 additions & 7 deletions src/MVCContrib.UnitTests/FluentHtml/SelectTests.cs
Expand Up @@ -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<FakeModel>
{
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()
{
Expand Down Expand Up @@ -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<FakeModel> { 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<FakeModel>
{
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()
{
Expand All @@ -190,6 +222,17 @@ public void select_options_with_null_value_field_selector_should_throw()
new Select("x").Options(new List<FakeModel>(), 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()
{
Expand Down

0 comments on commit 96c3a1c

Please sign in to comment.