예제 #1
0
        private static async Task <CreateRefreshTokenDto> SeedRefreshToken(
            IAccountsService accountsService,
            string userName,
            DateTime creationDate,
            DateTime?revocationDate    = default,
            string revokedByIp         = default,
            string replacedByTokenHash = default)
        {
            try
            {
                var user = await accountsService.FindUserByUserNameAsync(userName);

                if (user == default)
                {
                    throw new Exception("User not found.");
                }

                var newRefreshToken = accountsService.BuildRefreshToken(userName: userName,
                                                                        ipAddress: "127.0.0.1",
                                                                        creationDate: creationDate,
                                                                        revocationDate: revocationDate,
                                                                        revokedByIp: revokedByIp,
                                                                        replacedByTokenHash: replacedByTokenHash);

                if (!await accountsService.SaveRefreshTokenAsync(user.Id, newRefreshToken))
                {
                    throw new Exception("Error saving the refresh token into the database.");
                }

                return(newRefreshToken);
            }
            catch (Exception ex)
            {
                throw new Exception($"Exception thrown on the test helper method 'SeedRefreshToken' with the message: {ex.Message}");
            }
        }