如何摩尔 SPGroupCollection

发布于 2024-11-19 22:15:21 字数 750 浏览 3 评论 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 。我该怎么做?

亲切的问候,克里斯蒂安

I wrote the following code and I really would like to test it:

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;
            }
        }
    }
}

The problem is that I don't know how to mole the SPGroupCollection object. I know that there exist the MSPGroupCollection mole object, but I am not able to add a collection of moled Items (MSPGroup) to my MSPGroupCollection collection. Can anyone help me out with that? I would like to add three or four MSPGroup objects with some name. Than I would like to setup a MSPUserCollection with three or four MSPUser objects with some name. How can I do this?

Kind regards, Christian

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

春风十里 2024-11-26 22:15:21

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

Take a look at the Moles documentation (located at Start > Microsoft Moles). In particular, the document "Unit Testing SharePoint Foundation with Behaviors" contains some examples of how to mock SharePoint collections.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文