gpt4 book ai didi

asp.net-mvc - MVC 中模拟 RouteTable.Routes.GetVirtualPath

转载 作者:行者123 更新时间:2023-12-02 03:56:47 27 4
gpt4 key购买 nike

我有一个分页 Controller ,其方法调用

RouteTable.Routes.GetVirtualPath(this.viewContext.RequestContext, valueDictionary)

我正在尝试使用 Rhino 模拟来测试此方法,但我不确定如何模拟 GetVirtualPath 以返回除 null 之外的路由。我正在 mock RequestContext,但我不确定需要 stub 哪些方法/属性。

通过适本地 stub mockRequestContext,GetVirtualPath应该返回一个非空路径,如果是这样,需要 stub 什么才能使其工作?

非常感谢任何建议。

最佳答案

不确定我是否理解你的问题,但它看起来像这样:

IRouteTable routeTableMock = RhinoMocks.CreateMock<IRouteTable>();

// assuming that IRouteTable.Routes is of type IRoutes.
IRoutes routes = RhinoMocks.CreateMock<IRoutes>();

// return the routes with the mock
routeTableMock.Stub(x => x.Routes).Return(routes);

// setup the mock for GetVirtualPath
routes.Stub(
x => x.GetVirtualPath(
Arg<RequestContext>.Is.Anything,
Arg<IDictionary>.Is.Anything)
.Return(/* whatever */);

如果这不是您想要的,您必须详细介绍您的类(class)以及您想要测试的内容。

关于asp.net-mvc - MVC 中模拟 RouteTable.Routes.GetVirtualPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/792883/

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