繁体   English   中英

如何使用Microsoft Fakes将Sharepoint对象作为参数对测试方法进行单元化

[英]How to Unit Test Methods with Sharepoint Objects as parameters with Microsoft Fakes

我试图用Microsoft Fakes为使用sp对象作为参数的方法(如SPWeb或SPEventReceiverCollection等)编写单元测试,但不知道如何模拟这些方法。 我以前用过Moq,但似乎找不到如何在Microsoft假货中进行模拟。 例如:

public List<SPEventReceiverDefinition> CheckExisting(SPEventReceiverDefinitionCollection recs)
            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}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM