Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

VS11 ShimNotSupportedException when using Shimming from Microsoft Fakes
RichCzyzewski
#1 Posted : Saturday, May 5, 2012 11:53:47 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 5/5/2012(UTC)
Posts: 1
Location: Jacksonville, FL

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
I'm using Microsoft Fakes, see http://msdn.microsoft.com/en-us/library/hh549175(v=vs.110).aspx for more info.

Whenever I assign the delegate for a Shim, NCrunch reports a Microsoft.QualityTools.Testing.Fakes.Shims.ShimNotSupportedException when trying to run. Using the following code:

Quote:
public class Grill
{
private ICook _cook;

public Grill(ICook cook) { _cook = cook; }

public ISandwich OrderSandwich() { return _cook.MakeSandwich(); }
}

public interface ICook { ISandwich MakeSandwich(); }

public interface ISandwich { bool IsTasty { get; } }


With the following test, in a test project, with a reference to the original project and "Add Fakes Assembly" selected when right clicking on the reference.

Quote:
[TestMethod]
public void TestSandwichOrder()
{
using (ShimsContext.Create())
{
var stubbedCook = new MicrosoftFakesAndNCrunch.Fakes.StubICook();
var stubbedSandwich = new MicrosoftFakesAndNCrunch.Fakes.StubISandwich();
var shimmedGrill = new MicrosoftFakesAndNCrunch.Fakes.ShimGrill();

var realGrill = new Grill(cook);
stubbedCook.MakeSandwich = () => stubbedSandwich;

grill.OrderSandwich = () => stubbedSandwich;
}
}


NCrunch fails on
Quote:
grill.OrderSandwich = () => stubbedSandwich;

Instantiation of Shims and a Stubs works fine as well as assigning the Stub delegate, but once I assign a Shim delegate the ShimNotSupportedException appears.

Here's the stack trace:
Quote:
Microsoft.QualityTools.Testing.Fakes.Shims.ShimNotSupportedException: MicrosoftFakesAndNCrunch.Grill
at Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationRuntime.InvokeEvent[T](T value, Action`1 eh)
at Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationRuntime.OnAttachedUnsupportedMethod(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 MicrosoftFakesAndNCrunch.Fakes.ShimGrill.set_OrderSandwich(Func`1 value)
at MicrosoftFakesAndNCrunch.Tests.CookTests.TestSandwichOrder() in C:\Project Root\BugRepros\MicrosoftFakesAndNCrunch\MicrosoftFakesAndNCrunch.Tests\CookTests.cs:line 23


I have an example project that I can provide if necessary.
1 user thanked RichCzyzewski for this useful post.
stuartleitch on 5/6/2012(UTC)
Remco
#2 Posted : Sunday, May 6, 2012 12:19:34 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi, thanks for posting!

My first thought on reading this is that NCrunch's instrumentation is interfering with Fakes at a runtime level. There are other mocking frameworks that work in a similar way, and NCrunch has specific catch-points to deal with their logic. In the current version of NCrunch (1.38b), MS Fakes is not yet considered.

I'll make a note to see if I can get this fixed.

A way you can likely work around this issue is by turning off the 'instrument output assembly' setting in your NCrunch configuration for your test project. This will also mean that you won't have test covering showing in your test project.

Thanks for reporting this problem!


Cheers,

Remco
2 users thanked Remco for this useful post.
RichCzyzewski on 5/6/2012(UTC), stuartleitch on 5/6/2012(UTC)
Imi
#3 Posted : Tuesday, September 4, 2012 9:00:59 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 9/4/2012(UTC)
Posts: 1

I am experiencing the same problem. Unfortunately, this makes NCrunch almost impossible to use for us, since we rely on the Shimming methods of the new Fakes library.

The Problem does not go away when I disable the output assembly instrumentation.

Any other ideas how to quick fix this? Could you reproduce the problem?
Remco
#4 Posted : Tuesday, September 4, 2012 10:18:12 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi Imi -

Unfortunately there is no quick fix for this. Fakes relies on a custom profiler that will require considerable effort in order for NCrunch to integrate with it. A fix for this is still quite a way out. Sorry.


Cheers,

Remco
lancehilliard
#5 Posted : Tuesday, October 2, 2012 8:20:31 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 10/2/2012(UTC)
Posts: 1

Looking forward to the day that NCrunch supports an inexpensive mocking option with Fakes' power.
Remco
#6 Posted : Tuesday, October 2, 2012 9:18:04 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Still working on this one :)
NoneError
#7 Posted : Saturday, November 24, 2012 5:29:32 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 11/24/2012(UTC)
Posts: 3
Location: Canada

Thanks: 1 times
I just ran into this as well. Has this been addressed since the last post? By the way. I just love NCrunch!!!
Cheers,

Jeremy.
Remco
#8 Posted : Saturday, November 24, 2012 10:49:55 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi Jeremy,

Thanks for posting and I'm glad you're enjoying NCrunch!

Introduction of support for Fakes is currently on the backlog for NCrunch V2, so I'm afraid that this one looks like it will be quite a way out. Sorry.


Cheers,

Remco
nanderto
#9 Posted : Wednesday, February 27, 2013 4:23:47 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 2/27/2013(UTC)
Posts: 1
Location: United States of America

Any update on this. I have recommended this to my team but we are building a SharePoint site and we are using the SharePoint emulator which is built on the fakes framework, and the shims functionality.
Remco
#10 Posted : Wednesday, February 27, 2013 9:19:30 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi, sorry but support for fakes will not be added until at least V2 of NCrunch.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.092 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download