asp.net mvc 自动化测试工具
1var controllerOfMvc = Activator.CreateInstance(controllerDescription.ControllerType) as Controller;2
3 IHttpRouteData routeData = GlobalContext.config.Routes.GetRouteData(requestMessage);
4 var mvcRouteData = new RouteData();
5 var paras = new Dictionary<string, object>();
6 foreach (var item in routeData.Values)
7 {
8 mvcRouteData.Values.Add(item.Key, item.Value);
9 paras.Add(item.Key, item.Value);
10 }
11 var ctrlContext = new ControllerContext(httpContextBase, mvcRouteData, controllerOfMvc);
12 var actionDescription = controllerDescription.FindAction(ctrlContext, actionName);
13
14 if (null != actionDescription)
15 {
16 var actionResult = actionDescription.Execute(ctrlContext, paras) as ActionResult;
17
18 string resultText = string.Empty;
19 if (actionResult is JsonResult)
20 {
21 var data = (actionResult as JsonResult).Data;
22 resultText = JsonConvert.SerializeObject(data);//序列化数据
23
24 }
25 else if (actionResult is ViewResult || actionResult is PartialViewResult)
26 {
27 //解析模板实现的核心就是视图文件虚拟化 VirtualPathProvider and 动态编译 var clientBuildManager = new ClientBuildManager(rootVirtualPath, GlobalContext.SitePhysicDir);
28 /*
29 如果有需要可以尝试开发出来。参考资料:
30 http://blog.rebuildall.net/2009/11/17/asp_net_mvc_and_virtual_views
31 https://blog.falafel.com/how-to-load-views-from-assembly-in-mvc/
32 https://msdn.microsoft.com/en-us/library/system.web.hosting.virtualpathprovider(v=vs.110).aspx
33 http://www.binaryintellect.net/articles/e544d1d3-e47e-4ced-bd4d-8c1eaefbdc31.aspx
34 http://www.danielroot.info/2013/07/reuse-mvc-views-using-virtual-path.html
35 https://github.com/aspnet/Mvc/issues/3750
36 http://www.chrisvandesteeg.nl/2010/11/22/embedding-pre-compiled-razor-views-in-your-dll/
37 https://stackoverflow.com/questions/236972/using-virtualpathprovider-to-load-asp-net-mvc-views-from-dlls
38 https://stackoverflow.com/questions/24341336/is-it-possible-to-access-mvc-views-located-in-another-project
39 http://ericsowell.com/blog/2007/4/3/the-asp-net-virtual-path-provider-an-example-implementation
40 http://tech.trailmax.info/2014/02/attempt-to-do-view-compilation-for-azure-web-role/
41 http://aspnetwebstack.codeplex.com/SourceControl/latest#src/System.Web.Mvc/BuildManagerCompiledView.cs
42 http://aspnetwebstack.codeplex.com/SourceControl/latest#src/System.Web.Mvc/BuildManagerCompiledView.cs
43 */
44 throw new NotImplementedException();
45
46 string viewName = RenderHelper.ViewNameFromActionResult(actionResult);
47 if (string.IsNullOrEmpty(viewName))
48 {
49 viewName = actionName;
50 }
51 //定制 路径 不基于mvc标准
52 string viewPath = System.IO.Path.Combine( "~/Views", controllerName, string.Concat(actionName, ".aspx")).Replace("\\","/");//暂时没有ascx
53 //
54 resultText = RenderHelper.RenderWebFormViewToString(ctrlContext, actionResult, viewPath);//RenderHelper.RenderActionResultToString(ctrlContext, actionResult, mvcRouteData, controllerOfMvc);
55
56 } 金币不够,回帖来凑
页:
[1]