Exemplo n.º 1
0
        public void RemoveMemberAsync_RemoveMemberAsync()
        {
            var role = new AppUserRoleDto {
                Id = 1
            };
            var res = _memberController.RemoveMemberAsync(It.IsAny <int>(), It.IsAny <string>()).Result;

            _blMock.Verify(b => b.RemoveMemberAsync(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <string>()));
        }
Exemplo n.º 2
0
        public void ChangeMemberRoleAsync_CallsChangeUserRoleAsync()
        {
            var role = new AppUserRoleDto {
                Id = 1
            };
            var res = _memberController.ChangeMemberRoleAsync(It.IsAny <int>(), It.IsAny <string>(), role).Result;

            _blMock.Verify(b => b.ChangeUserRoleAsync(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <string>(), role));
        }
Exemplo n.º 3
0
        public void CheckThatItIsNotPossibleToChangeRoleFromOwner()
        {
            string callerId = "user-that-owner";

            _mpur.Setup(r => r.GetRoleOfMember(callerId, It.IsAny <int>())).ReturnsAsync(AppUserRole.Owner);

            var            bl      = getMemberBl();
            AppUserRoleDto roleDto = new AppUserRoleDto {
                Id = AppUserRole.None.Id
            };

            Assert.ThrowsAsync <ForbiddenResponseException>(async()
                                                            => await bl.ChangeUserRoleAsync(callerId, It.IsAny <int>(), callerId, roleDto)).Wait();
        }
Exemplo n.º 4
0
        public void CheckThatScrumMasterHasNotPermissionsToResetScrumMaster()
        {
            string callerId = "user-that-master";

            _mpur.Setup(r => r.GetRoleOfMember(callerId, It.IsAny <int>())).ReturnsAsync(AppUserRole.ScrumMaster);
            _mpur.Setup(r => r.DoesExistScrumMasterInProjectAsync(It.IsAny <int>())).ReturnsAsync(true);

            var            bl      = getMemberBl();
            AppUserRoleDto roleDto = new AppUserRoleDto {
                Id = AppUserRole.Developer.Id
            };

            Assert.ThrowsAsync <ForbiddenResponseException>(async()
                                                            => await bl.ChangeUserRoleAsync(callerId, It.IsAny <int>(), callerId, roleDto)).Wait();
        }
Exemplo n.º 5
0
        public void CheckThatOwnerCanNotMakeNewScrumMasterIfItAlreadyExists()
        {
            string callerId = "user-that-owner", userId = "user-dev";

            _mpur.Setup(r => r.GetRoleOfMember(callerId, It.IsAny <int>())).ReturnsAsync(AppUserRole.Owner);
            _mpur.Setup(r => r.GetRoleOfMember(userId, It.IsAny <int>())).ReturnsAsync(AppUserRole.Developer);
            _mpur.Setup(r => r.DoesExistScrumMasterInProjectAsync(It.IsAny <int>())).ReturnsAsync(true);

            var            bl      = getMemberBl();
            AppUserRoleDto roleDto = new AppUserRoleDto {
                Id = AppUserRole.ScrumMaster.Id
            };

            Assert.ThrowsAsync <ForbiddenResponseException>(async()
                                                            => await bl.ChangeUserRoleAsync(callerId, It.IsAny <int>(), userId, roleDto)).Wait();
        }
Exemplo n.º 6
0
        public void CheckThatCannotAddMemberWithOwnerRole()
        {
            string callerId = "user-owner", userId = "user-x";

            _mpur.Setup(r => r.GetRoleOfMember(callerId, It.IsAny <int>())).ReturnsAsync(AppUserRole.Owner);
            _mur.Setup(r => r.ExistsWithId(userId)).ReturnsAsync(true);
            _mpur.Setup(r => r.GetRoleOfMember(userId, It.IsAny <int>())).ReturnsAsync(AppUserRole.None);

            var            bl      = getMemberBl();
            AppUserRoleDto roleDto = new AppUserRoleDto {
                Id = AppUserRole.Owner.Id
            };

            Assert.ThrowsAsync <BadRequestResponseException>(async()
                                                             => await bl.AddMemberAsync(callerId, It.IsAny <int>(), userId, roleDto)).Wait();
        }
Exemplo n.º 7
0
        public void CheckThatOwnerCanMakeScrumMasterFromMember()
        {
            string callerId = "user-that-owner", userId = "user-dev";

            _mpur.Setup(r => r.GetRoleOfMember(callerId, It.IsAny <int>())).ReturnsAsync(AppUserRole.Owner);
            _mpur.Setup(r => r.GetRoleOfMember(userId, It.IsAny <int>())).ReturnsAsync(AppUserRole.Developer);
            _mpur.Setup(r => r.DoesExistScrumMasterInProjectAsync(It.IsAny <int>())).ReturnsAsync(false);

            var            bl      = getMemberBl();
            AppUserRoleDto roleDto = new AppUserRoleDto {
                Id = AppUserRole.ScrumMaster.Id
            };

            bl.ChangeUserRoleAsync(callerId, It.IsAny <int>(), userId, roleDto).Wait();

            _mpur.Verify(r => r.UpdateRecordAsync(It.IsAny <ProjectUser>()));
        }
Exemplo n.º 8
0
        public void CheckThatOwnerCanAddScrumMasterIfItIsNotAlreadyInProject()
        {
            string callerId = "user-owner", userId = "user-x";

            _mpur.Setup(r => r.GetRoleOfMember(callerId, It.IsAny <int>())).ReturnsAsync(AppUserRole.Owner);
            _mur.Setup(r => r.ExistsWithId(userId)).ReturnsAsync(true);
            _mpur.Setup(r => r.GetRoleOfMember(userId, It.IsAny <int>())).ReturnsAsync(AppUserRole.None);
            _mpur.Setup(r => r.DoesExistScrumMasterInProjectAsync(It.IsAny <int>())).ReturnsAsync(false);

            var            bl      = getMemberBl();
            AppUserRoleDto roleDto = new AppUserRoleDto {
                Id = AppUserRole.ScrumMaster.Id
            };

            bl.AddMemberAsync(callerId, It.IsAny <int>(), userId, roleDto).Wait();

            _mpur.Verify(r => r.CreateRecordAsync(It.IsAny <ProjectUser>()));
        }
Exemplo n.º 9
0
        public void CheckThatOwnerCanAddMemberToProject()
        {
            string userOwnerId = "user-owner", userId = "user-x";

            _mpur.Setup(r => r.GetRoleOfMember(userOwnerId, It.IsAny <int>())).ReturnsAsync(AppUserRole.Owner);
            _mur.Setup(r => r.ExistsWithId(userId)).ReturnsAsync(true);
            _mpur.Setup(r => r.GetRoleOfMember(userId, It.IsAny <int>())).ReturnsAsync(AppUserRole.None);


            var            bl      = getMemberBl();
            AppUserRoleDto roleDto = new AppUserRoleDto {
                Id = AppUserRole.Observer.Id
            };

            bl.AddMemberAsync(userOwnerId, It.IsAny <int>(), userId, roleDto).Wait();

            _mpur.Verify(r => r.CreateRecordAsync(It.IsAny <ProjectUser>()), Times.Once);
        }
Exemplo n.º 10
0
        public void CheckThatItIsNotPossibleToChangeRoleWhenNewRoleIsTheSameAsOldRole(string userId)
        {
            string callerId = "user-that-owner";

            _mpur.Setup(r => r.GetRoleOfMember(callerId, It.IsAny <int>())).ReturnsAsync(AppUserRole.Owner);
            _mpur.Setup(r => r.GetRoleOfMember("user-that-master", It.IsAny <int>())).ReturnsAsync(AppUserRole.ScrumMaster);
            _mpur.Setup(r => r.GetRoleOfMember("user-that-dev", It.IsAny <int>())).ReturnsAsync(AppUserRole.Developer);
            _mpur.Setup(r => r.GetRoleOfMember("user-that-observer", It.IsAny <int>())).ReturnsAsync(AppUserRole.Observer);

            var bl = getMemberBl();
            IProjectUserRepository puRepo  = _mpur.Object;
            AppUserRole            role    = puRepo.GetRoleOfMember(userId, It.IsAny <int>()).Result;
            AppUserRoleDto         roleDto = new AppUserRoleDto {
                Id = role.Id
            };

            Assert.ThrowsAsync <ForbiddenResponseException>(async()
                                                            => await bl.ChangeUserRoleAsync(callerId, It.IsAny <int>(), userId, roleDto)).Wait();
        }
Exemplo n.º 11
0
        public async Task ChangeUserRoleAsync(string senderUserId, int projectId, string userId, AppUserRoleDto newRoleDto)
        {
            AppUserRole senderRole = await GetRoleIfMember(senderUserId, projectId);

            if (!senderRole.HasPermissionsToChangeRoleOfMember())
            {
                throw new ForbiddenResponseException("You haven't permissions to change roles of members in this project");
            }

            AppUserRole currRole = await _puRepo.GetRoleOfMember(userId, projectId);

            AppUserRole newRole = _mapper.Map <AppUserRoleDto, AppUserRole>(newRoleDto);

            if (!senderRole.CanChangeRoleOfMember(currRole, newRole))
            {
                throw new ForbiddenResponseException($"You cannot change role from {currRole.Name} to {newRole.Name}.");
            }

            if (newRole.IsScrumMaster() && await _puRepo.DoesExistScrumMasterInProjectAsync(projectId))
            {
                throw new ForbiddenResponseException("Only one Scrum Master can be on project");
            }

            ProjectUser pu = new ProjectUser()
            {
                ProjectId  = projectId,
                UserId     = userId,
                UserRoleId = newRole.Id
            };
            await _puRepo.UpdateRecordAsync(pu);
        }
Exemplo n.º 12
0
        public async Task AddMemberAsync(string senderUserId, int projectId, string userId, AppUserRoleDto roleDto)
        {
            AppUserRole senderRole = await GetRoleIfMember(senderUserId, projectId);

            if (!senderRole.CanAddNewMember())
            {
                throw new ForbiddenResponseException("You haven't permissions to add members to this project");
            }

            if (!await _userRepo.ExistsWithId(userId))
            {
                throw new NotFoundResponseException("Cannot find user to add into project.");
            }

            if (!((await _puRepo.GetRoleOfMember(userId, projectId)).IsNone()))
            {
                throw new BadRequestResponseException("This user already exists in project.");
            }

            AppUserRole role = _mapper.Map <AppUserRoleDto, AppUserRole>(roleDto);

            if (role.IsNone())
            {
                throw new BadRequestResponseException("Given role is bad.");
            }

            if (role.IsOwner())
            {
                throw new BadRequestResponseException("Cannot add Owner to project.");
            }

            if (role.IsScrumMaster() && await _puRepo.DoesExistScrumMasterInProjectAsync(projectId))
            {
                throw new BadRequestResponseException("Scrum Master already exists in project.");
            }

            var pu = new ProjectUser()
            {
                ProjectId  = projectId,
                UserId     = userId,
                UserRoleId = role.Id
            };
            await _puRepo.CreateRecordAsync(pu);
        }