Пример #1
0
        public void GetUser_WithData_valid()
        {
            // Mock

            var user = new User()
            {
                Id       = Guid.NewGuid(),
                UserName = "******",
                Email    = "*****@*****.**",
                Roles    = new List <Role>
                {
                    new Role()
                    {
                        Id   = Guid.NewGuid(),
                        Name = "admin"
                    }
                }
            };

            _userRepository.GetUser(Arg.Any <Guid>()).Returns(user);

            // Execute

            var result = _sut.GetUser(Guid.NewGuid());

            // Assert
            Assert.NotNull(result);
            Assert.NotNull(result.Roles);
            Assert.AreSame(user.Email, "*****@*****.**");
            Assert.AreNotEqual(0, result.Roles.Count);
            Assert.AreSame("admin", result.Roles.First().Name);
        }
Пример #2
0
        public async Task AddMember([FromRoute] string id, [FromRoute] string userId)
        {
            var user = _securityService.GetUser(userId);
            var role = _securityService.GetRole(id);

            if (user == null || role == null)
            {
                return;
            }
            await _securityService.AddUserToRole(user, role.Name);
        }
Пример #3
0
        public ApplicationUser Get(string id)
        {
            var user = _securityService.GetUser(id, true);

            return(user);
        }