" App_GlobalResources文件"在单元测试的情况下不加载 [英] "App_GlobalResources" not loading in a Unit test case
问题描述
结果
我有一个测试控制器的操作方法单元测试方法。操作方法使用的资源文件,以获得一个静态消息。
I have a unit test method which tests a controller action method. The action method uses resource file to get a static message.
message = Resources.MyResource.MemberNotVerified;
然而,在这条线抛出的异常是: -
However at this line the exception thrown is :-
无法加载文件或程序集'App_GlobalResources文件或它的一个依赖系统找不到指定的文件。:App_GlobalResources文件System.IO.IOException {} System.IO.FileNotFoundException
"Could not load file or assembly 'App_GlobalResources' or one of its dependencies. The system cannot find the file specified.":"App_GlobalResources" System.IO.IOException {System.IO.FileNotFoundException}
我试过在应付我的测试项目整个资源文件,但它是不成功的。结果
任何想法的朋友。
I tried coping the whole resource file in my Test project, but it was unsuccessful.
Any idea friends.
推荐答案
在幕后, App_GlobalResources文件使用 <一个href=\"http://msdn.microsoft.com/en-us/library/system.web.httpcontext.getglobalresourceobject.aspx\">HttpContext.GetGlobalResourceObject
Behind the scenes, App_GlobalResources uses HttpContext.GetGlobalResourceObject
当然,还有在单元测试中没有的HttpContext(除非你的嘲讽吧)
Of course, there is no HttpContext in unit tests (unless your mocking it).
如果你是如此倾斜嘲笑它,菲尔哈克上有一个体面的职位的这里。
If you were so inclined to mock it, Phil Haack has a decent post on it here.
有另一种解决方案,这是对RESX文件移出常规目录的
There is another solution, and that is to move the RESX files out of the regular directory.
斯科特 - 阿伦设在该<一后href=\"http://odeto$c$c.com/Blogs/scott/archive/2009/07/16/resource-files-and-asp-net-mvc-projects.aspx\">here.
这篇关于&QUOT; App_GlobalResources文件&QUOT;在单元测试的情况下不加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!