0

我写了以下代码,我真的很想测试它:

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 鼹鼠对象,但我无法将鼹鼠项 (MSPGroup) 集合添加到我的 MSPGroupCollection 集合中。谁能帮我解决这个问题?我想添加三个或四个具有某些名称的 MSPGroup 对象。比我想用三个或四个具有某些名称的 MSPUser 对象设置一个 MSPUserCollection。我怎样才能做到这一点?

亲切的问候,克里斯蒂安

4

1 回答 1

1

查看 Moles 文档(位于开始 > Microsoft Moles)。特别是,文档“使用行为对 SharePoint Foundation 进行单元测试”包含一些有关如何模拟 SharePoint 集合的示例。

于 2011-07-13T01:10:12.173 回答