Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories


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 :-

"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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

Behind the scenes, App_GlobalResources uses HttpContext.GetGlobalResourceObject

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.

There is another solution, and that is to move the RESX files out of the regular directory.

Scott Allen has a post on that here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...