Exemplo n.º 1
0
        public UserWithToken GetUserByToken(string token)
        {
            var user = _userQueryProcessor.GetByToken(token);
            // log this user in so that we can change the password or by bypass the login process on activation.

            var expiryPeriod = DateTime.Now.ToLocalTime() + TokenAuthOption.ExpiresSpan;
            var genToken     = _tokenBuilder.Build(user.Email, user.Roles.Select(r => r.Role.RoleName).ToArray(),
                                                   expiryPeriod);

            return(new UserWithToken
            {
                ExpiresAt = expiryPeriod,
                Token = genToken,
                User = user
            });
        }
        public void GetByTokenShouldReturnValidUser()
        {
            // arrange
            var user = new UserEntity {
                Id = Guid.NewGuid(), Email = "*****@*****.**", UserToken = _random.Next().ToString()
            };

            _userList.Add(user);
            _userList.Add(new UserEntity {
                Id = Guid.NewGuid(), UserToken = _random.Next().ToString()
            });
            _userList.Add(new UserEntity {
                Id = Guid.NewGuid(), UserToken = _random.Next().ToString()
            });

            // act
            var result = _userQueryProcessor.GetByToken(user.UserToken);

            // assert
            result.Id.Should().Be(user.Id);
            result.UserToken.Should().Be(user.UserToken);
        }