开发者

How to mole SPGroupCollection

开发者 https://www.devze.com 2023-03-20 01:30 出处:网络
I wrote the following code and I really would like to test it: SPGroupCollection sharePointGroupCollection = contextWeb.Groups;

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

精彩评论

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

关注公众号