Ejemplo n.º 1
0
        protected override void SetUp()
        {
            base.SetUp();

            DirectoryEntry root = new DirectoryEntry(_rootDirectory);

            DirectoryEntry newUserEntry = root.Children.Add(_newUserName, "user");

            newUserEntry.Invoke("SetPassword", _password);
            newUserEntry.CommitChanges();

            DirectoryEntry userEntry = root.Children.Add(_userName, "user");

            userEntry.Invoke("SetPassword", _password);
            userEntry.CommitChanges();

            Uri uri = new Uri(_newSPSiteServerUrl);

            SPSite site = new SPSite(uri.ToString());

            SPSite newSite = site.SelfServiceCreateSite(
                _newSPSiteUrl,
                _newSPSiteTitle,
                _newSPSiteDesc,
                site.RootWeb.Language,
                "STS",
                _newSPSiteOwnerLogin,
                _newSPSiteOwnerName,
                _newSPSiteOwnerEmail,
                _newSPSiteContactLogin,
                _newSPSiteContactName,
                _newSPSiteContactEmail);

            // Add the test user to the site.
            //    SPSite site = new SPSite(_newSPSiteUrl);
            SPRole role = newSite.RootWeb.Roles["Contributor"];

            if (role == null)
            {
                throw new Exception(string.Format(
                                        "The role '{0}' does not exist", "Contributor"));
            }
            role.AddUser(_newUserLogin, "", "", "");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Task for adding a SPUser to a site.
        /// </summary>
        protected override void ExecuteTask()
        {
            try {
                SPSite site = new SPSite(Url);
                SPRole role = site.RootWeb.Roles[Role];

                if (role == null)
                {
                    throw new BuildException(string.Format(
                                                 "The role '{0}' does not exist", Role));
                }
                role.AddUser(LoginId, "", "", "");
            }
            catch (SPException ex) {
                throw new BuildException(
                          string.Format("Cannot add user: {0} to site: {1}.",
                                        LoginId, Url), Location, ex);
            }
        }