Search code examples
visual-studiounit-testingvisual-studio-2013microsoft-fakes

ShimNotImplementedException after upgrading Visual Studio 2013 and Microsoft Fakes v12


We are utilizing Microsoft Fakes with Visual Studio 2013. After updating to Visual Studio 2013 Update-4 or Update-5, we are getting ShimNotImplementedException's in our tests.

We have followed instructions found in other SOF questions and turned off the SpecificVersion of our Microsoft.QualityTools.Testing.Fakes references. This allows a compile but the tests still fail when run.


Solution

  • The hint we needed to solve this was found in MSDN forums.

    The underlying issue is that the legacy tests did not define specific methods on the ShimXXX object that the code based is using. Under version 11 all is well; version 12 is a different matter.

    The stack trace for the ShimNotImplementedException gave the needed information on the missing property/method:

    Microsoft.QualityTools.Testing.Fakes.Shims.ShimNotImplementedException
    at $Func`2NotImplementedf5b9281e-32b0-4bf3-9079-6a54470670de.Invoke(SiteContext arg1)
    at Sitecore.Sites.SiteContext.get_Database() //THIS IS THE PROBLEM PROPERTY
    at Sitecore.Ecommerce.ShopContext..ctor(SiteContext innerSite)
    at ActiveCommerce.UnitTest.ProductStockManagerTests.get_MockShopContext()
    at ActiveCommerce.UnitTest.ProductStockManagerTests.GetAvailability_AlwaysInStock()
    

    Adding the missing property to our shim construction solved the issue:

            return new Sitecore.Ecommerce.ShopContext(new ShimSiteContext
            {
                PropertiesGet = () => new NameValueCollection(),
                DatabaseGet = () => null //ADDING THIS SOLVED THE ISSUE
            });