When attempting to follow the article on mocking the htmlhelper with Moq I ran in to the following problem. The exception is thrown on creation of the htmlhelper. I am only guessing that castle windsor is being used (by seeing the error message).
The exception:
MissingMethodException occurred
Constructor on type 'Castle.Proxies.ViewContextProxy' not found.
Stack Trace:
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
The Code:
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);
}
I am using ASP MVC 2, Moq 4.0 beta 3, VS2010, using the IDE's testing framework.
How do I resolve the issue and return an instance of HtmlHelper?