我如何使用moles框架测试包含HttpConext的控制器? 我的控制器代码是ASP .net单元测试控制器使用MOLES
public ActionResult Index()
{
MyRepositoryClass myRepo = new MyRepositoryClass (System.Web.HttpContext.Current);
string fs = ipser.GetCityName();
return View();
}
My code for the controller in unit test project is
public class MyClassTest
{
[TestMethod]
[HostType("Moles")]
public void Index_Test()
{
string originalViewName="Index";
MyController myContl = new MyController();
var result =myContl.Index() as ViewResult;
Assert.IsNotNull(result, "Should return a view");
Assert.AreEqual(originalViewName, result.ViewName, "View name should have been {0}", originalViewName);
}
应该如何使用摩尔框架测试我控制器?
这可能会帮助你:http://blog.dotnetwiki.org/2010/08/24/NewUnitTestingAspNETApplicationsWithPexAndMolesTutorial.aspx – 2011-06-03 10:50:36
仅供参考0不确定你使用Unity作为你的IOC容器,而Moq作为你的隔离框架,您可以使用automocking轻松地将上下文截断。 http://www.dotnetcurry.com/ShowArticle.aspx?ID=767 – Spock 2013-06-16 12:50:08