AutoMocker单元测试
/// <summary> /// 测试获取所有物流 /// </summary> [TestMethod] public void TestExpressController() { var Expresss = new List<Express> { new Express{Code="01",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("01", result.Data.ElementAt(0).ExpressCode); Assert.AreEqual("测试物流", result.Data.ElementAt(0).ExpressName); }