I've been starting to look into the new feature in VisualStudio 2012 where you can add a fake assembly of a dll for unit testing purpose. I'm working with SharePoint 2010 and we all now it is a pain to unit test code that depend on the SharePoint API.
I added a fake assembly for Microsoft.SharePoint and that worked fine, but I came to a point where I need to override the method SPWeb.Locale
. I thought that would be easy. I thought there would be a method like ShimSPWeb.LocaleGet
but there is not.
This is the only options I have regarding Locale
on my ShimSPWeb
In short: There should be a shimWeb.LocaleGet
available.
I figured it out. You can add diagnostics to the *.fakes settings file. This enables debugging output when generating the fakes assembly.
When I did this, I got this output:
SharePoint 2010 targets .Net version 3.5. My unit test was set to target framework .Net 4.0. I changed the target of my unit test project to 3.5, regenerated the fake assembly and voila! It worked!