using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using MVCDomain.Abstract;
using MVCDomain;
using System.Collections.Generic;
using MvcDemo.Controllers;
using System.Linq;
namespace MvcDemo.Tests
{
[TestClass]
public class UnitTest
{
[TestMethod]
public void TestMethod()
{
//Moq对象创建模拟器
Mock<IProductRepository> mock = new Mock<IProductRepository>();
mock.Setup(s => s.Products).Returns(new List<Product>
{
new Product {ProductID=1, Name="Football",Price=25,Description="足球"},
new Product {ProductID=3, Name="Surf board",Price=179,Description="板球"},
new Product {ProductID=2, Name="Running shoes",Price=95,Description="跑步鞋"},
new Product {ProductID=4, Name="Rub shoes",Price=150,Description="轮滑鞋"},
new Product {ProductID=6, Name="Tom shoes",Price=190,Description="休闲鞋"},
new Product {ProductID=5, Name="LiNing shoes",Price=100,Description="李宁鞋"}
});
ProductController controller = new ProductController(mock.Object);
controller.pageSize = 5;
//动作
IEnumerable<Product> result = (IEnumerable<Product>)controller.List(2).Model;
//断言
var list = result.ToList();
Assert.IsTrue(list.Count==1);
Assert.AreEqual(list[0].Name, "Tom shoes");
}
}
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。