开发者

How to mole SPGroupCollection

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)
    {
        SPU开发者_JAVA技巧serCollection 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜