Ejemplo n.º 1
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));
        }
Ejemplo n.º 2
0
    public async Task Should_Create_Admin_User_And_Role_With_TenantId()
    {
        var tenantId = Guid.NewGuid();

        await _identityDataSeeder.SeedAsync("*****@*****.**", "1q2w3E*", tenantId);

        (await _userRepository.FindByNormalizedEmailAsync(_lookupNormalizer.NormalizeEmail("*****@*****.**"))).ShouldBeNull();

        using (_currentTenant.Change(tenantId))
        {
            (await _userRepository.FindByNormalizedUserNameAsync(_lookupNormalizer.NormalizeName("admin"))).ShouldNotBeNull();
            (await _userRepository.FindByNormalizedUserNameAsync(_lookupNormalizer.NormalizeName("admin"))).Name.ShouldBe("admin");
            (await _userRepository.FindByNormalizedUserNameAsync(_lookupNormalizer.NormalizeName("admin"))).TenantId.ShouldBe(tenantId);

            (await _roleRepository.FindByNormalizedNameAsync(_lookupNormalizer.NormalizeName("admin"))).ShouldNotBeNull();
            (await _roleRepository.FindByNormalizedNameAsync(_lookupNormalizer.NormalizeName("admin"))).TenantId.ShouldBe(tenantId);
        }
    }