2021-09-07 23:40:58 +10:00
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
|
using System;
|
2021-09-08 15:02:07 +10:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Moq;
|
|
|
|
|
using SportsStore.Domain.Abstract;
|
|
|
|
|
using SportsStore.Domain.Entities;
|
|
|
|
|
using SportsStore.WebUI.Controllers;
|
2021-09-07 23:40:58 +10:00
|
|
|
|
|
|
|
|
|
namespace SportsStore.UnitTests
|
|
|
|
|
{
|
|
|
|
|
[TestClass]
|
|
|
|
|
public class UnitTest1
|
|
|
|
|
{
|
|
|
|
|
[TestMethod]
|
2021-09-08 15:02:07 +10:00
|
|
|
|
public void Can_Paginate()
|
2021-09-07 23:40:58 +10:00
|
|
|
|
{
|
2021-09-08 15:02:07 +10:00
|
|
|
|
// Arrange
|
|
|
|
|
Mock<IProductRepository> mock = new Mock<IProductRepository>();
|
|
|
|
|
mock.Setup(m => m.Products).Returns(new Product[] {
|
|
|
|
|
new Product {ProductID = 1, Name = "P1"},
|
|
|
|
|
new Product {ProductID = 2, Name = "P2"},
|
|
|
|
|
new Product {ProductID = 3, Name = "P3"},
|
|
|
|
|
new Product {ProductID = 4, Name = "P4"},
|
|
|
|
|
new Product {ProductID = 5, Name = "P5"}
|
|
|
|
|
});
|
|
|
|
|
ProductController controller = new ProductController(mock.Object);
|
|
|
|
|
controller.PageSize = 3;
|
|
|
|
|
// Act
|
|
|
|
|
IEnumerable<Product> result =
|
|
|
|
|
(IEnumerable<Product>)controller.List(2).Model;
|
|
|
|
|
// Assert
|
|
|
|
|
Product[] prodArray = result.ToArray();
|
|
|
|
|
Assert.IsTrue(prodArray.Length == 2);
|
|
|
|
|
Assert.AreEqual(prodArray[0].Name, "P4");
|
|
|
|
|
Assert.AreEqual(prodArray[1].Name, "P5");
|
2021-09-07 23:40:58 +10:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|