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 CreateAsync()
        {
            // Arrange
            PlayerCreateDto input = new PlayerCreateDto
            {
                FirstName = "John",
                LastName = "Doe"
            };

            // Act
            PlayerDto serviceResult = await _playersAppService.CreateAsync(input);

            // Assert
            Player result = await _playerRepository.FindAsync(c => c.Id == serviceResult.Id);

            result.ShouldNotBe(null);
            result.FirstName.ShouldBe("John");
            result.LastName.ShouldBe("Doe");
            result.UserId.ShouldBeNull();
        }