コード例 #1
0
        public void AddUserToGroup_CallsCRUD_AddUserToGroup_PassingTheCorrectIDs_ExactlyOnce_WhenCalled_IfUserIsNotAlreadyInTheGroup()
        {
            //Arrange
            int TestUserID        = 1;
            int TestAccessGroupID = 1;

            User TestUser = new User {
                UserID = 2
            };
            UserAccessGroup TestAccessGroup = new UserAccessGroup
            {
                UserAccessGroupID = TestAccessGroupID,
                Users             = new List <User> {
                    TestUser
                }
            };
            List <UserAccessGroup> TestAccessGroups = new List <UserAccessGroup> {
                TestAccessGroup
            };

            Mock <ICRUD_Operations> MockCRUD = new Mock <ICRUD_Operations>();

            MockCRUD.Setup(x => x.GetAllAccessGroups()).Returns(TestAccessGroups);
            MockCRUD.Setup(x => x.AddUserToGroup(It.IsAny <int>(), It.IsAny <int>())).Verifiable();

            UserManagementService UserMgmtService = new UserManagementService(MockCRUD.Object);

            //Act
            UserMgmtService.AddUserToGroup(TestUserID, TestAccessGroupID);

            //Assert
            MockCRUD.Verify(x => x.AddUserToGroup(TestUserID, TestAccessGroupID), Times.Once);
        }
コード例 #2
0
        public void AddUserToGroup_CallsGetAllAccessGroups_ExactlyOnce_WhenCalled()
        {
            //Arrange
            int TestUserID        = 1;
            int TestAccessGroupID = 1;

            User TestUser = new User {
                UserID = TestUserID
            };
            UserAccessGroup TestAccessGroup = new UserAccessGroup
            {
                UserAccessGroupID = TestAccessGroupID,
                Users             = new List <User> {
                    TestUser
                }
            };
            List <UserAccessGroup> TestAccessGroups = new List <UserAccessGroup> {
                TestAccessGroup
            };

            Mock <ICRUD_Operations> MockCRUD = new Mock <ICRUD_Operations>();

            MockCRUD.Setup(x => x.GetAllAccessGroups()).Returns(TestAccessGroups);

            UserManagementService UserMgmtService = new UserManagementService(MockCRUD.Object);

            //Act
            UserMgmtService.AddUserToGroup(TestUserID, TestAccessGroupID);

            //Assert
            MockCRUD.Verify(x => x.GetAllAccessGroups(), Times.Once);
        }
コード例 #3
0
        public void AddUserToGroup_DoesNotCallCRUD_AddUserToGroup_WhenCalled_IfUserIsAlreadyInTheGroup()
        {
            //Arrange
            int TestUserID        = 1;
            int TestAccessGroupID = 1;

            User TestUser = new User {
                UserID = TestUserID
            };
            UserAccessGroup TestAccessGroup = new UserAccessGroup
            {
                UserAccessGroupID = TestAccessGroupID,
                Users             = new List <User> {
                    TestUser
                }
            };
            List <UserAccessGroup> TestAccessGroups = new List <UserAccessGroup> {
                TestAccessGroup
            };

            Mock <ICRUD_Operations> MockCRUD = new Mock <ICRUD_Operations>();

            MockCRUD.Setup(x => x.GetAllAccessGroups()).Returns(TestAccessGroups);

            UserManagementService UserMgmtService = new UserManagementService(MockCRUD.Object);

            //Act
            UserMgmtService.AddUserToGroup(TestUserID, TestAccessGroupID);

            //Assert
            MockCRUD.Verify(x => x.AddUserToGroup(It.IsAny <int>(), It.IsAny <int>()), Times.Never());
        }
コード例 #4
0
        private void AddUserToGroupbutton_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count != 0)
            {
                int UserAccessGroupID;

                DataGridViewRow row = this.dataGridView1.SelectedRows[0];
                UserAccessGroupID = Convert.ToInt32(row.Cells["UserAccessGroupID"].Value);

                UserMgmt.AddUserToGroup(UserID, UserAccessGroupID);
                MessageBox.Show("The selected user was successfully added to the selected access group.");
                logonMenu.Reload();
                this.Close();
            }
        }