Mocking ResourceManager in .NET

We have a small wrapper class that uses ResourceManager to load string resources from assemblies.

We also have some unit tests that check it loads the correct details from the correct assemblies for different cultures, assemblies etc. Our tests are therefore currently dependant upon resources we have constructed for the test.

Is there an easy way of mocking the ResourceManager class, other than coming up with our own interface which is then implemented by forwarding calls to the propert ResourceManager (and feels somewhat convoluted). Mocking the interface would be easy, but the overall solution just doesn't feed right.

We are currently using Moq.

13.10.2009 16:35:26
1 ОТВЕТ
РЕШЕНИЕ

I think you answered your own question. If you really need to test the business logic concerning how to choose which culture, assembly, etc is chosen, then you should use an adaptor interface that removes the direct dependency on ResourceManager and can be mocked with Moq.

3
13.10.2009 16:40:35
+1. You might consider contributing the code to systemwrapper.codeplex.com as well.
TrueWill 13.10.2009 17:48:16
Nice link TrueWill. A project that seeks to make the .NET Framework testable for everyone is great.
Anderson Imes 14.10.2009 19:05:00