locked
Can I test this method using Moles? RRS feed

  • Question

  • Hi All,

    I have written some static methods to identify users in a SharePoint application. One of the methods is as below that checks if a user is part of a SharePoint security group or not:

    public static bool CheckIfUserInSPSecurityGroup(string userLogOnName, string groupName)
        {
          bool isUserMember = false;
    
          SPGroup objGroup = SPContext.Current.Site.RootWeb.SiteGroups[groupName];
    
          if (objGroup != null)
          {
            foreach (SPUser user in objGroup.Users)
            {
              if (string.Compare(userLogOnName, user.LoginName, true) == 0)
              {
                isUserMember = true;
                break;
              }
            }
          }
    
          return isUserMember;
        }
    
    Since I test library can not connect to SharePoint context, is it possible to test this methods using Moles? Please suggest as soon as possible.


    Thanks, Himanshu.
    Thursday, February 17, 2011 4:53 PM

All replies

  • Not sure why you couldn't.

     

    Mole SPContext [Current, erase static constructor probably], SPSite [RootWeb, ctor probably] , SPWeb [ SiteGroups, ctor?] and possibly SPGroup and whatever the group collection is (possibly its ctor and indexer).

     

     

     

    Thursday, February 24, 2011 5:42 PM
  • Yes you should be able to use Moles to test this code.
    Jonathan "Peli" de Halleux - Try Pex online at www.pexforfun.com!
    Friday, February 25, 2011 7:03 PM