Could not load file or assembly App_GlobalResources
I'm yet to find a decent solution for this problem but here's how I currently get around it in MVC apps. Here I'm replacing my dependency on Strings.resx in App_GlobalResources.
First thing to do is to create a ResourceManager property and make use of this instance within the class you're testing. Now whenever you need to make use of the resource you have to replace the normal syntax of Strings.FieldYouWant with StringsResource.GetString("FieldYouWant") as shown in the method MethodBeingTested().
public class MyController { public ResourceManager StringsResource { get; private set; } public MyController() : this(Strings.ResourceManager) {} public MyController(ResourceManager stringsResourceManager) { StringsResource = stringsResourceManager; } public object MethodBeingTested() { return new ContentResult( StringsResource.GetString("FieldYouWant") ); } }
In your test project you'll need to create a Strings.resx mirrored source file and make use of this when testing MyController class. Do this by instantiating with a resource from the calling test assembly...
var stringsResource = new ResourceManager("test.assembly.Strings", Assembly.GetExecutingAssembly()); var controller = new MyController(stringsResource);...not pretty, but at least you can run your unit tests without an exception slapping you around the face. Any one got a better solution?
Try using this attribute in the test method:
ReplyDelete[DeploymentItem(@"Project\bin\Debug\ca", "ca")]
Regards
Is this an issue with all RESX files, or just those in the App_GlobalResources?
ReplyDeleteI've been using the localisation pattern set out here: http://adamyan.blogspot.com/2010/02/aspnet-mvc-2-localization-complete.html and not had any problems with testing.