I follow Pro ASP.Net MVC2, and literally 90% of everything is new to me. I feel like a kid in a candy store! :)
Unit testing, dependency injection and other things are really new and very foreign to the typical CRUD applications that I create.
Now I am having problems with the test that the book requests from us.
[Test]
public void Can_Generate_Links_To_Other_Pages()
{
HtmlHelper html = null;
PagingInfo pagingInfo = new PagingInfo
{
CurrentPage = 2,
TotalItems = 28,
ItemsPerPage = 10
};
Func<int, string> pageUrl = i => "Page" + i;
MvcHtmlString result = html.PageLinks(pagingInfo, pageUrl);
result.ToString().ShouldEqual(@"<a href=""Page1"">1</a>
<a class=""selected"" href=""Page2"">2</a>
<a href=""Page3"">3</a>");
}
My html variable is an HtmlHelper variable. The PageLinks () extension method seems to be incorrectly registered.
Where can I check this out? I understand that this question can be a little vague, but any help would be great.
EDIT:
Obviously, this is where I registered the extension method. Although it does not seem to expand anything. At least intellisnse doesn't show it when I inject it into the code above.
public static class PagingHelpers
{
public static MvcHtmlString PageLinks(this HtmlHelper html, PagingInfo pagingInfo, Func<int, string> pageUrl)
{
StringBuilder result = new StringBuilder();
for (int i = 1; i <= pagingInfo.TotalPages; i++)
{
TagBuilder tag = new TagBuilder("a");
tag.MergeAttribute("href", pageUrl(i));
tag.InnerHtml = i.ToString();
if (i == pagingInfo.CurrentPage)
tag.AddCssClass("selected");
result.AppendLine(tag.ToString());
}
return MvcHtmlString.Create(result.ToString());
}
}
, - , Visual Studio, ?
2:
Woops! :
1 'System.Web.Mvc.HtmlHelper' "PageLinks" "PageLinks" "System.Web.Mvc.HtmlHelper" ( ?) C:\Users\Sergio\documents\visual 2010\Projects\SportsStore\SportsStore.UnitTests\DisplayingPageLinks.cs 35 41 SportsStore.UnitTests