Пример #1
0
        /// <summary>
        /// Adds the user.
        /// </summary>
        /// <param name="s">The s.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        protected void AddUser(Object s, EventArgs e)
        {
            //The users must be added to a list first becuase the collection can not
            //be modified while we iterate through it.
            var usersToAdd = new List <ListItem>();

            foreach (ListItem item in lstAllUsers.Items)
            {
                if (item.Selected)
                {
                    usersToAdd.Add(item);
                }
            }


            foreach (var item in usersToAdd)
            {
                if (ProjectManager.AddUserToProject(item.Value, ProjectId))
                {
                    lstSelectedUsers.SelectedIndex = -1;
                    lstSelectedUsers.Items.Add(item);
                    lstAllUsers.Items.Remove(item);
                }
            }

            lstSelectedUsers.SelectedIndex = -1;
            RebindProjectMembers();
        }
        public void AddUserToProjectActingUserNotInProjectThrowsException()
        {
            var pm = new ProjectManager {
                DocumentStore = _embeddedDocStore
            };
            string exceptionMessage = string.Format("{0} is not authorised to add new users to Project {1}.", _notInProjectUser.Username, _existingProject.Name);

            Assert.That(() => pm.AddUserToProject(_existingProject.Name, _newActiveUser.Username, _notInProjectUser.Username), Throws.ArgumentException.With.Message.EqualTo(exceptionMessage));
        }
        public void AddInactiveUserToProjectThrowsException()
        {
            var pm = new ProjectManager {
                DocumentStore = _embeddedDocStore
            };
            var exceptionMessage = string.Format("{0} is not currently an active user, please reactivate and try again", _newInactiveUser.Username);

            Assert.That(() => pm.AddUserToProject(_existingProject.Name, _newInactiveUser.Username, _existingUser.Username), Throws.ArgumentException.With.Message.EqualTo(exceptionMessage));
        }
        public void AddUserToProject_ProjectNotFoundThrowsException()
        {
            var pm = new ProjectManager {
                DocumentStore = _embeddedDocStore
            };
            var    notExistingProjectName = "notExistingProject";
            string exceptionMessage       = string.Format("Could not find Project {0}.", notExistingProjectName);

            Assert.That(() => pm.AddUserToProject(notExistingProjectName, _newActiveUser.Username, _existingUser.Username), Throws.ArgumentException.With.Message.EqualTo(exceptionMessage));
        }
        public void AddNonExistentUserToProjectThrowsException()
        {
            var pm = new ProjectManager {
                DocumentStore = _embeddedDocStore
            };
            const string userToAdd        = "doesntexist";
            var          exceptionMessage = string.Format("Could not find UserAccount {0}.", userToAdd);

            Assert.That(() => pm.AddUserToProject(_existingProject.Name, userToAdd, _existingUser.Username), Throws.ArgumentException.With.Message.EqualTo(exceptionMessage));
        }
        public void AddUserToProjectAlreadyExistingSuccess()
        {
            var pm = new ProjectManager {
                DocumentStore = _embeddedDocStore
            };

            pm.AddUserToProject(_existingProjectWithExtraUser.Name, _existingUserAlreadyAddedToProject.Username, _existingUser.Username);
            var session        = _embeddedDocStore.OpenSession();
            var updatedProject = session.Query <Project>().Where(p => p.Name == _existingProjectWithExtraUser.Name).First();

            Assert.IsTrue(updatedProject.Users.Contains(_existingUserAlreadyAddedToProject.Username));
        }
        public void AddUserToProjectSuccess()
        {
            var pm = new ProjectManager {
                Session = _embeddedDocStore.OpenSession()
            };

            pm.AddUserToProject(_existingProject.Name, _newActiveUser.Username, _existingUser.Username);
            var session        = _embeddedDocStore.OpenSession();
            var updatedProject = session.Query <Project>().Where(p => p.Name == _existingProject.Name).First();

            Assert.IsTrue(updatedProject.Users.Contains(_newActiveUser.Username));
        }