.net 如何创建GroupCollection

.net 如何创建GroupCollection,.net,sharepoint,moles,.net,Sharepoint,Moles,我编写了以下代码,我真的很想对其进行测试: SPGroupCollection sharePointGroupCollection = contextWeb.Groups; foreach (SPGroup sharePointGroup in sharePointGroupCollection) { if (groupname == sharePointGroup.Name) { SPUserCollection sharePointUserCollection

我编写了以下代码,我真的很想对其进行测试:

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对象,但我无法将moled项集合(MSPGroup)添加到我的MSPGroupCollection集合中。有人能帮我吗?我想添加三个或四个具有某些名称的MSPGroup对象。然后我想用三个或四个有名字的MSPUser对象设置一个MSPUserCollection。我该怎么做


致以亲切的问候,Christian

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