我正在寻找ac#generator,它可以生成随机单词,句子,由多个单词/段落给出的段落以及某些语法,如地址,数字,邮政编码/邮政编码,国家,电话号码,电子邮件地址.
我的目标是能够对一些自定义HtmlHelper扩展进行单元测试 - 这些扩展在内部使用RenderPartial.
http://ox.no/posts/mocking-htmlhelper-in-asp-net-mvc-2-and-3-using-moq
我尝试使用上面的方法来模拟HtmlHelper.但是,我遇到了Null值异常."参数名称:视图"
任何人都有任何想法?谢谢.
以下是代码的想法:
[TestMethod]
public void TestMethod1()
{
var helper = CreateHtmlHelper(new ViewDataDictionary());
helper.RenderPartial("Test"); // supposingly this line is within a method to be tested
Assert.AreEqual("test", helper.ViewContext.Writer.ToString());
}
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(),
new StringWriter());
var mockViewDataContainer = new Mock<IViewDataContainer>();
mockViewDataContainer.Setup(v => v.ViewData)
.Returns(vd);
return new HtmlHelper(mockViewContext.Object,
mockViewDataContainer.Object);
}
Run Code Online (Sandbox Code Playgroud) public class Parent
{
public virtual Parent me()
{
return this;
}
}
public class Child : Parent
{
}
Run Code Online (Sandbox Code Playgroud)
new Child().me()返回一个Parent对象.我需要让它返回Child对象本身(不使用扩展和泛型)?