【发布时间】:2010-08-10 03:11:02
【问题描述】:
在尝试关注article on mocking the htmlhelper with Moq 时,我遇到了以下问题。创建 htmlhelper 时会引发异常。我只是猜测城堡温莎正在被使用(通过查看错误消息)。
例外:
发生MissingMethodException
找不到类型“Castle.Proxies.ViewContextProxy”的构造函数。
堆栈跟踪:
在 System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfoculture, Object[] activationAttributes)
代码:
public static HtmlHelper CreateHtmlHelper(ViewDataDictionary vd)
{
Mock<ViewContext> mockViewContext = new Mock<ViewContext>(
new ControllerContext(
new Mock<HttpContextBase>().Object,
new RouteData(),
new Mock<ControllerBase>().Object),
new Mock<IView>().Object,
vd,
new TempDataDictionary());
Mock<IViewDataContainer> mockViewDataContainer = new Mock<IViewDataContainer>();
mockViewDataContainer.Setup(v => v.ViewData).Returns(vd);
return new HtmlHelper(mockViewContext.Object, mockViewDataContainer.Object);
}
我正在使用 ASP MVC 2、Moq 4.0 beta 3、VS2010,使用 IDE 的测试框架。
如何解决问题并返回 HtmlHelper 实例?
【问题讨论】:
标签: asp.net-mvc unit-testing mocking moq