如何骚扰SPGroupCollection

时间:2011-07-11 22:01:34

标签: .net sharepoint moles

我编写了以下代码,我真的想测试一下:

SPGroupCollection sharePointGroupCollection = contextWeb.Groups;
foreach (SPGroup sharePointGroup in sharePointGroupCollection)
{
    if (groupname == sharePointGroup.Name)
    {
        SPUserCollection sharePointUserCollection = sharePointGroup.Users;
        foreach (SPUser sharePointUser in sharePointUserCollection)
        {
            if (username == sharePointUser.Name)
            {
                return true;
            }
        }
    }
}

问题是我不知道如何诋毁SPGroupCollection对象。我知道存在MSPGroupCollection mole对象,但是我无法将mledGroup(MSPGroup)的集合添加到我的MSPGroupCollection集合中。任何人都可以帮我解决这个问题吗?我想添加三个或四个具有某个名称的MSPGroup对象。比我想设置一个带有三个或四个带有某个名称的MSPUser对象的MSPUserCollection。我怎么能这样做?

亲切的问候,基督徒

1 个答案:

答案 0 :(得分:1)

查看Moles文档(位于开始> Microsoft Moles)。特别是,文档“单元测试SharePoint Foundation with Behaviors”包含一些如何模拟SharePoint集合的示例。