Exemple #1
0
        public async Task RefreshToken_ReturnsTokenInfo()
        {
            if (!File.Exists(TokenSettingFilePath))
            {
                await GetToken_ReturnsTokenInfo();
            }

            var content       = File.ReadAllText(TokenSettingFilePath);
            var tokenSettings = JsonConvert.DeserializeObject <TokenSettings>(content);

            var requestModel = new RefreshTokenRequestModel()
            {
                RefreshToken = tokenSettings.RefreshToken,
            };

            TokenResponseModel result = await ApiFactory.CreateAuthClient()
                                        .RefreshToken(requestModel)
                                        .Retry(3, TimeSpan.FromSeconds(2))
                                        .WhenCatch <HttpStatusFailureException>(ex => ex.StatusCode == System.Net.HttpStatusCode.RequestTimeout);

            Assert.NotNull(result);
            Assert.NotEmpty(result.AccessToken);

            WriteTokenSettings(result);
        }
Exemple #2
0
        public async Task GetToken_ReturnsTokenInfo()
        {
            var requestModel = XiaoAiGlobal.GlobalConfig.DefaultXiaoAiClientSettings.CreateGetTokenRequestModel();

            TokenResponseModel result = await ApiFactory.CreateAuthClient()
                                        .GetToken(requestModel)
                                        .Retry(3, TimeSpan.FromSeconds(2))
                                        .WhenCatch <HttpStatusFailureException>(ex => ex.StatusCode == System.Net.HttpStatusCode.RequestTimeout);

            Assert.NotNull(result);
            Assert.NotEmpty(result.AccessToken);

            WriteTokenSettings(result);
        }