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

时间:2015-07-31 08:05:42

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

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

public List<SPEventReceiverDefinition> CheckExisting(SPEventReceiverDefinitionCollection recs)

1 个答案:

答案 0 :(得分:0)

            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}