7.5.1.2 Adding the HTML Helper Method; UNIT TEST: CREATING PAGE LINKS

This commit is contained in:
Jason Zhu 2021-08-21 17:10:54 +10:00
parent 2ddc93b2a9
commit 002318dd2d
2 changed files with 30 additions and 0 deletions

View File

@ -63,6 +63,7 @@
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.Web" />
<Reference Include="System.Web.Helpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.Helpers.dll</HintPath>
</Reference>

View File

@ -3,9 +3,12 @@ using Moq;
using SportsStore.Domain.Abstract;
using SportsStore.Domain.Entities;
using SportsStore.WebUI.Controllers;
using SportsStore.WebUI.HtmlHelpers;
using SportsStore.WebUI.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
namespace SportsStore.UnitTests
{
@ -40,5 +43,31 @@ namespace SportsStore.UnitTests
Assert.AreEqual(prodArray[1].Name, "P5");
}
[TestMethod]
public void Can_Generate_Page_Links()
{
// Arrange - define an HTML helper - we need to do this
// in order to apply the extension method
HtmlHelper myHelper = null;
// Arrange - create PagingInfo data
PagingInfo pagingInfo = new PagingInfo
{
CurrentPage = 2,
TotalItems = 28,
ItemsPerPage = 10
};
// Arrange - set up the delegate using a lambda expression
Func<int, string> pageUrlDelegate = i => "Page" + i;
// Act
MvcHtmlString result = myHelper.PageLinks(pagingInfo, pageUrlDelegate);
// Assert
Assert.AreEqual(result.ToString(), @" < a href = ""Page1"" > 1 </ a >< a class=""selected""
href=""Page2"">2</a><a href = ""Page3"">3</a>");
}
}
}