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

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

asp.net mvc - "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 :-

"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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...