7.5.1.1 Adding the View Model; UNIT TEST: CREATING PAGE LINKS
parent
7539975905
commit
20f1cf9dec
|
@ -2,10 +2,13 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Web.Mvc;
|
||||||
using Moq;
|
using Moq;
|
||||||
using SportsStore.Domain.Abstract;
|
using SportsStore.Domain.Abstract;
|
||||||
using SportsStore.Domain.Entities;
|
using SportsStore.Domain.Entities;
|
||||||
using SportsStore.WebUI.Controllers;
|
using SportsStore.WebUI.Controllers;
|
||||||
|
using SportsStore.WebUI.HtmlHelpers;
|
||||||
|
using SportsStore.WebUI.Models;
|
||||||
|
|
||||||
namespace SportsStore.UnitTests
|
namespace SportsStore.UnitTests
|
||||||
{
|
{
|
||||||
|
@ -17,7 +20,8 @@ namespace SportsStore.UnitTests
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
Mock<IProductRepository> mock = new Mock<IProductRepository>();
|
Mock<IProductRepository> mock = new Mock<IProductRepository>();
|
||||||
mock.Setup(m => m.Products).Returns(new Product[] {
|
mock.Setup(m => m.Products).Returns(new Product[]
|
||||||
|
{
|
||||||
new Product { ProductID = 1, Name = "P1" },
|
new Product { ProductID = 1, Name = "P1" },
|
||||||
new Product { ProductID = 2, Name = "P2" },
|
new Product { ProductID = 2, Name = "P2" },
|
||||||
new Product { ProductID = 3, Name = "P3" },
|
new Product { ProductID = 3, Name = "P3" },
|
||||||
|
@ -35,5 +39,32 @@ namespace SportsStore.UnitTests
|
||||||
Assert.AreEqual(prodArray[0].Name, "P4");
|
Assert.AreEqual(prodArray[0].Name, "P4");
|
||||||
Assert.AreEqual(prodArray[1].Name, "P5");
|
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(@"<a class=""btn btn-default"" href=""Page1"">1</a>"
|
||||||
|
+ @"<a class=""btn btn-default btn-primary selected"" href=""Page2"">2</a>"
|
||||||
|
+ @"<a class=""btn btn-default"" href=""Page3"">3</a>",
|
||||||
|
result.ToString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue