AutoMocker单元测试

时间:2023-03-10 06:39:53
AutoMocker单元测试
/// <summary>
/// 测试获取所有物流
/// </summary>
[TestMethod]
public void TestExpressController()
{
var Expresss = new List<Express> {
new Express{Code="",Name="测试物流"}
}.AsQueryable(); var mocker = new AutoMocker();
mocker.Use<IExpressContract>(x => x.Entities == Expresss);
var controller = mocker.CreateInstance<ExpressController>();
controller.ExpressContract = mocker.Get<IExpressContract>(); var result = controller.Get(); Assert.IsNotNull(result);
Assert.AreEqual(ReslultCode.sucess, result.code);
Assert.AreEqual("", result.Data.ElementAt().ExpressCode);
Assert.AreEqual("测试物流", result.Data.ElementAt().ExpressName);
}