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.