Exemplo n.º 1
0
 public UserDto(User user)
     : base(user)
 {
     FirstName = user.FirstName;
     LastName = user.LastName;
     Email = user.Email;
 }
        public UserSession CreateUserSession(User user, string host)
        {
            var accessToken = Guid.NewGuid();

            var userSession = new UserSession
            {
                IsActive = true,
                SessionStart = DateTime.UtcNow,
                User = user,
                UserId = user.Id,
                AccessToken = accessToken
            };

            return _userSessionRepository.Create(userSession);
        }
Exemplo n.º 3
0
        public OperationResult Create(CreateUserDto createUserDto)
        {
            var user = new User
            {
                FirstName = createUserDto.FirstName,
                LastName = createUserDto.LastName,
                Email = createUserDto.Email,
                Password = CalculatePasswordHash(createUserDto.Password)
            };
            user = _userRepository.Create(user);

            TeamSetupEnum teamSetup = TeamSetupEnum.Unknown;
            if(!TeamSetupEnum.TryParse(createUserDto.TeamSetup, true, out teamSetup))
            {
                return new OperationResult { IsSuccess = false, ErrorMessage = $"Team setup '{createUserDto.TeamSetup}' not exists." };
            }

            var team = new Team
            {
                Name = createUserDto.TeamName,
                TeamSetup = teamSetup,
                User = user,
                UserId = user.Id
            };
            team = _teamService.Create(team);

            var stadium = new Stadium
            {
                Name = createUserDto.StadiumName,
                Capacity = 5000,
                Team = team,
                TeamId = team.Id
            };
            stadium = _stadiumRepository.Create(stadium);

            return new OperationResult { IsSuccess = true, Data = user };;
        }
        public void SignInMustReturnAccessTokenAfterSuccessfullSignIn()
        {
            CreateUserControllerMocks();
            var user = new User { Id = 1, FirstName = "John", LastName = "Smith" };
            var userSession = new UserSession { AccessToken = Guid.Parse("09d7ab22-a936-4ac9-8fb8-4ba7dc95815e"), User = user, IsActive = true };
            _userService.Setup(x => x.FindByCredentials(It.IsAny<string>(), It.IsAny<string>())).Returns((string email, string password) => user);
            _userSessionService.Setup(x => x.CreateUserSession(It.IsAny<User>(), It.IsAny<string>())).Returns((User userData, string host) => userSession);
            var signInDto = new SignInDto { Email = "*****@*****.**", Password = "******" };

            var actionResult = _usersController.SignIn(signInDto) as JsonResult;

            Assert.NotNull(actionResult);
            dynamic data = actionResult.Value;
            Assert.Equal("09d7ab22-a936-4ac9-8fb8-4ba7dc95815e", data.AccessToken);
            Assert.Equal(true, data.IsSuccess);
        }