升级 Visual Studio 2013 和 Microsoft Fakes v12 后的 ShimNotImplementedException
我们将 Microsoft Fakes 与 Visual Studio 2013 结合使用.更新到 Visual Studio 2013 Update-4 或 Update-5 后,我们在测试中遇到 ShimNotImplementedException
.
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.
我们有遵循其他中的说明SOF 问题 并关闭了我们的 Microsoft.QualityTools.Testing.Fakes
引用的 SpecificVersion
.这允许编译,但运行时测试仍然失败.
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.
我们需要解决这个问题的提示可以在 MSDN 论坛.
The hint we needed to solve this was found in MSDN forums.
潜在的问题是遗留测试没有定义特定的方法在基于代码使用的 ShimXXX 对象上.在版本 11 下一切都很好;版本 12 是另一回事.
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.
ShimNotImplementedException
的堆栈跟踪提供了有关缺少的属性/方法的所需信息:
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()
将缺失的属性添加到我们的 shim 构造中解决了这个问题:
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
});