ShimNotImplementedException after upgrading Visual Studio 2013 and Microsoft Fakes v12

五迷三道 提交于 2020-01-25 10:59:06

问题


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.


回答1:


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
        });



回答2:


I ran in to a similar problem after upgrading several of our projects from .NET 4 to .NET 4.5.2 using Visual Studio 2015. All the sudden several previously passing tests started failing. The common denominator was that all of the tests were using Shims to mock registry access.

What appears to have happened is that something changed in the handling of the Dispose method. Originally I had not implemented a Dispose method on the RegistryKey shims. That didn't seem to cause any trouble running under .NET 4. However after the switch to 4.5.2, it is implicitly being called all the time.

The solution was simple: I just added a stub for Dispose.

Microsoft.Win32.Fakes.ShimRegistryKey.AllInstances.Dispose = (key) => { };

The tests now pass again.

Note that setting it to NULL did not solve it for it. There has to be a method.



来源:https://stackoverflow.com/questions/31679796/shimnotimplementedexception-after-upgrading-visual-studio-2013-and-microsoft-fak

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!