Question

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

enter image description here

In short: There should be a shimWeb.LocaleGet available.

Was it helpful?

Solution

I figured it out. You can add diagnostics to the *.fakes settings file. This enables debugging output when generating the fakes assembly.

<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/" Diagnostic="true">

When I did this, I got this output:

unstubbable: method is abstract and could not be stubbed, type System.Globalization.CultureInfo is not available in the target framework version

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top