Example #1
0
        public static async Task <Result <User> > MockRegisterUser(string userName, string password)
        {
            // Arrange
            using var scope = _scopeFactory.CreateScope();

            var userManager = scope.ServiceProvider.GetService <UserManager <AppUser> >();
            //var jwtManager = scope.ServiceProvider.GetService<JwtGenerator>();

            var jwtManager = new JwtGenerator(_configuration);

            if (jwtManager == null)
            {
                TestContext.Out.WriteLine("jwtManager is null!");
            }
            var user = new AppUser {
                UserName = userName, Email = userName, DisplayName = userName, DateJoined = DateTime.UtcNow
            };

            _currentUserId = user.Id;
            var refreshToken = jwtManager.GenerateRefreshToken();

            user.RefreshTokens.Add(refreshToken);
            var result = await userManager.CreateAsync(user, password);

            if (result.Succeeded)
            {
                return(Result <User> .Success(new User(user, jwtManager, refreshToken.Token)));
            }
            return(Result <User> .Failure("Problem creating user."));
        }