Tell me more ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm trying to use the SharePoint Emulators package for unit testing SharePoint WebParts.

However, even the simplest unit test throws the following exception:

Test Name:  TestMethod1
Test FullName:  UnitTestProject1.UnitTest1.TestMethod1
Test Source:    c:\tmp\UnitTestProject1\UnitTestProject1\UnitTest1.cs : line 12
Test Outcome:   Failed
Test Duration:  0:00:01.1328681

Result Message: 
Test method UnitTestProject1.UnitTest1.TestMethod1 threw exception: 
Microsoft.QualityTools.Testing.Fakes.Shims.ShimNotSupportedException:     System.Web.HttpContext
Result StackTrace:  
   at Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationRuntime.InvokeEvent[T](T value, Action`1 eh)
   at Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationRuntime.OnAttachedUn    supportedMethod(MethodBase method)
   at Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationRuntime.CheckInstrumentation(MethodBase method)
   at Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationRuntime.InternalAttachDetour(Object optionalReceiver, MethodBase method, Delegate detourDelegate)
   at Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationRuntime.AttachDetour(Object optionalReceiver, MethodBase method, Delegate detourDelegate)
   at Microsoft.QualityTools.Testing.Fakes.Shims.ShimRuntime.SetShimMethod(Delegate optionalStub, Object optionalReceiver, MethodBase method)
   at Microsoft.QualityTools.Testing.Fakes.Shims.ShimRuntime.SetShim(Delegate optionalStub, Type receiverType, Object optionalReceiver, String name, ShimBinding flags, Type returnType, Type[] parameterTypes)
   at Microsoft.QualityTools.Testing.Fakes.Shims.ShimRuntime.SetShimPublicInstance(Delegate optionalStub, Type receiverType, Object optionalReceiver, String name, Type returnType, Type[] parameterTypes)
   at System.Web.Fakes.ShimHttpContext.set_RequestGet(Func`1 value)
   at System.Web.Emulators.EmHttpContext..ctor(HttpContext instance)
   at System.Web.Emulators.EmHttpContext..ctor()
   at System.Web.Emulators.EmHttpContext.SetCurrent()
   at System.Web.Emulators.EmHttpContext.Prepare()
   at Microsoft.SharePoint.Emulators.SharePointEmulationScope..ctor(EmulationMode emulationMode)
   at UnitTestProject1.UnitTest1.TestMethod1() in c:\tmp\UnitTestProject1\UnitTestProject1\UnitTest1.cs:line 13

I've read on MSDN social that using code instrumentation additional to the Fakes framework (like Code Coverage or ReSharper test runner) can result in this error. But I've disabled ReSharper's unit test addons (and had the error before installing ReSharper) and I don't use Code Coverage.

Here are my steps to the error:

  1. Create new solution (Unit Test Project, .NET 3.5)
  2. Use NuGet to get Microsoft.SharePoint.Emulators package
  3. Add using Microsoft.SharePoint.Emulators; to top of file
  4. Add block to unit test method: using (new SharePointEmulationScope(Microsoft.QualityTools.Testing.Emulators.EmulationMode.Enabled))

Then execute, results in exception.

What am I doing wrong?

share|improve this question

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.