本文介绍了我怎么能嘲笑Server.HtmlEn code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试以下,但我正在逐渐:对象引用不设置到对象的实例
HttpContextBase mockContext = MockRepository.GenerateMock< HttpContextBase>(); mockContext.Expect(C => c.Server.HtmlEn code())。IgnoreArguments()返回。();
mockContext.Expect(C => c.Server.HtmlDe code())返回。(); controller.ControllerContext =
新的ControllerContext(mockContext,新的RouteData(),控制器);
晨报,
感谢。这足以点我这里提供的正确的方向:
VAR mockContext = MockRepository.GenerateMock< HttpContextBase>();
VAR mockServer = MockRepository.GenerateMock<&的HttpServerUtilityBase GT;();mockServer.Expect(S = GT; s.HtmlEn code())
.IgnoreArguments()
.Repeat.AtLeastOnce()
。返回();mockContext.Expect(C => c.Server)
.IgnoreArguments()
.Repeat.AtLeastOnce()
.Return(mockServer);controller.ControllerContext =
新的ControllerContext(mockContext,新的RouteData(),控制器);
解决方案
在这里纯粹猜测:
VAR mockServer = MockRepository.GenerateMock<&的HttpServerUtilityBase GT;();
mockServer.Expect(X => x.HtmlEn code(。))IgnoreArguments()返回();
I am trying the following, but I am getting : Object reference not set to an instance of an object.
HttpContextBase mockContext = MockRepository.GenerateMock<HttpContextBase>();
mockContext.Expect(c => c.Server.HtmlEncode("")).IgnoreArguments().Return("");
mockContext.Expect(c => c.Server.HtmlDecode("")).Return("");
controller.ControllerContext =
new ControllerContext(mockContext, new RouteData(), controller);
Matin,
Thanks. That was enough to point me in the right direction provided here:
var mockContext = MockRepository.GenerateMock<HttpContextBase>();
var mockServer = MockRepository.GenerateMock<HttpServerUtilityBase>();
mockServer.Expect(s => s.HtmlEncode(""))
.IgnoreArguments()
.Repeat.AtLeastOnce()
.Return("");
mockContext.Expect(c => c.Server)
.IgnoreArguments()
.Repeat.AtLeastOnce()
.Return(mockServer);
controller.ControllerContext =
new ControllerContext(mockContext, new RouteData(), controller);
解决方案
Pure guess here:
var mockServer = MockRepository.GenerateMock<HttpServerUtilityBase>();
mockServer.Expect(x => x.HtmlEncode("")).IgnoreArguments().Return("");
这篇关于我怎么能嘲笑Server.HtmlEn code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!