如何摩尔 SPGroupCollection
我编写了以下代码,我真的很想测试它:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 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.