【问题标题】:How to Unit Test Methods with Sharepoint Objects as parameters with Microsoft Fakes如何使用 Microsoft Fakes 将 Sharepoint 对象作为参数的单元测试方法
【发布时间】:2015-07-31 08:05:41
【问题描述】:

我正在尝试使用 Microsoft Fakes 为将 sp 对象作为参数(如 SPWeb 或 SPEventReceiverCollection 等)的方法编写单元测试,但不知道如何模拟这些。 我以前用过最小起订量,但似乎找不到如何模拟微软假货。 例如:

public List<SPEventReceiverDefinition> CheckExisting(SPEventReceiverDefinitionCollection recs)

【问题讨论】:

    标签: c# unit-testing sharepoint microsoft-fakes


    【解决方案1】:
                Microsoft.SharePoint.Fakes.ShimSPEventReceiverDefinition fakeERD = new Microsoft.SharePoint.Fakes.ShimSPEventReceiverDefinition();
    
            fakeERD.TypeGet = () => { return type; };
            fakeERD.AssemblyGet = () => { return assembly; };
            fakeERD.ClassGet = () => { return Constants.UsernameWriterPath; };
    

    想通了。使用 Fake 类的区域也需要在 ShimContext 中。 上面的例子展示了如何创建和设置对象/属性。

                using (ShimsContext.Create())
            {//testing code goes here}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-24
      • 2015-07-24
      • 2017-05-13
      相关资源
      最近更新 更多