public async Task CreateAsync()
        {
            //Arrange

            var input = new IdentityUserCreateDto
            {
                UserName       = Guid.NewGuid().ToString(),
                Email          = CreateRandomEmail(),
                LockoutEnabled = true,
                PhoneNumber    = CreateRandomPhoneNumber(),
                Password       = "******",
                RoleNames      = new[] { "moderator" }
            };

            //Act

            var result = await _userAppService.CreateAsync(input);

            //Assert

            result.Id.ShouldNotBe(Guid.Empty);
            result.UserName.ShouldBe(input.UserName);
            result.Email.ShouldBe(input.Email);
            result.LockoutEnabled.ShouldBe(input.LockoutEnabled);
            result.PhoneNumber.ShouldBe(input.PhoneNumber);

            var user = await _userRepository.GetAsync(result.Id);

            user.Id.ShouldBe(result.Id);
            user.UserName.ShouldBe(input.UserName);
            user.Email.ShouldBe(input.Email);
            user.LockoutEnabled.ShouldBe(input.LockoutEnabled);
            user.PhoneNumber.ShouldBe(input.PhoneNumber);
        }
Пример #2
0
        public async Task SetTitle(Guid userId, string title)
        {
            var user = await _identityUserRepository.GetAsync(userId);

            user.SetProperty("Title", title);
            await _identityUserRepository.UpdateAsync(user);
        }
Пример #3
0
        private async Task AddLinkUsers()
        {
            var john = await _userRepository.GetAsync(_testData.UserJohnId);

            var david = await _userRepository.GetAsync(_testData.UserDavidId);

            var neo = await _userRepository.GetAsync(_testData.UserNeoId);

            await _identityLinkUserManager.LinkAsync(new IdentityLinkUserInfo(john.Id, john.TenantId),
                                                     new IdentityLinkUserInfo(david.Id, david.TenantId));

            await _identityLinkUserManager.LinkAsync(new IdentityLinkUserInfo(david.Id, david.TenantId),
                                                     new IdentityLinkUserInfo(neo.Id, neo.TenantId));
        }
Пример #4
0
        public virtual async Task <PlayerDto> CreateAsync(PlayerCreateDto input)
        {
            Player player = new Player(
                GuidGenerator.Create(),
                input.FirstName,
                input.LastName);

            if (input.UserId.HasValue)
            {
                IdentityUser user = await _identityUserRepository.GetAsync(input.UserId.Value);

                await _playerManager.LinkUserToPlayer(player, user);
            }
            else if (!string.IsNullOrEmpty(input.Email))
            {
                IdentityUser user = await _identityUserRepository.FindByNormalizedEmailAsync(input.Email);

                if (user == null)
                {
                    user = new IdentityUser(
                        GuidGenerator.Create(),
                        input.Email.ToLower(),
                        input.Email.ToLower());
                    await _identityUserManager.CreateAsync(user, input.Password);
                }

                await _playerManager.LinkUserToPlayer(player, user);
            }

            player = await _playerRepository.InsertAsync(player, autoSave : true);

            return(ObjectMapper.Map <Player, PlayerDto>(player));
        }