gpt4 book ai didi

asp.net-mvc - asp.net MVC 中的单元测试,如何模拟页面请求?

转载 作者:行者123 更新时间:2023-12-02 13:30:01 25 4
gpt4 key购买 nike

如何模拟 .net MVC 页面的页面请求?

最佳答案

使用RhinoMocks:

 var httpContext = MockRepository.GenerateMock<HttpContextBase>();
var httpRequest = MockRepository.GenerateMock<HttpRequestBase>();

httpContext.Expect( c => c.Request ).Return( httpRequest ).Repeat.Any();

... set up expectations on request...

var controller = new MyController();
controller.ControllerContext = new ControllerContext( httpContext,
new RouteData(),
controller );

...invoke action, check assertions...

httpContext.VerifyAllExpectations();
httpRequest.VerifyAllExpectations();

关于asp.net-mvc - asp.net MVC 中的单元测试,如何模拟页面请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/774204/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com