Beispiel #1
0
        public async Task InitializeAsync()
        {
            await using var container = new Container();
            var http = container.Resolve <IHttpClientFactory>().CreateClient("GW2SDK");

            var subtokenService = new SubtokenService(http);

            SubtokenPermissions = Enum.GetValues(typeof(Permission)).Cast <Permission>().ToList();

            var exp = DateTimeOffset.Now.AddDays(1);

            // Truncate to seconds: API probably doesn't support milliseconds
            ExpiresAt = DateTimeOffset.FromUnixTimeSeconds(exp.ToUnixTimeSeconds());

            Urls = new List <string> {
                "/v2/tokeninfo", "/v2/account", "/v2/characters/My Cool Character"
            };

            var createdSubtoken = await subtokenService.CreateSubtoken(ConfigurationManager.Instance.ApiKeyFull, SubtokenPermissions, ExpiresAt, Urls);

            // All tests that use this fixture are flaky: GetTokenInfo occassionally fails right after the subtoken is created
            // Adding a delay seems to help, possibly because of clock skew?
            await Task.Delay(1000);

            var request = new TokenInfoRequest(createdSubtoken.Subtoken);

            using var response = await http.SendAsync(request);

            response.EnsureSuccessStatusCode();
            CreatedSubtokenDate = response.Headers.Date.GetValueOrDefault(DateTimeOffset.Now);
            SubtokenInfoJson    = await response.Content.ReadAsStringAsync();
        }
Beispiel #2
0
        public async Task InitializeAsync()
        {
            await using var container = new Container();
            var http = container.Resolve <IHttpClientFactory>().CreateClient("GW2SDK");

            var subtokenService = new SubtokenService(http);

            SubtokenBasic = await subtokenService.CreateSubtoken(ConfigurationManager.Instance.ApiKeyBasic);

            // GetTokenInfo occassionally fails right after the subtoken is created
            // Adding a delay seems to help, possibly because of clock skew?
            await Task.Delay(1000);
        }
Beispiel #3
0
        public async Task Create_a_subtoken_from_default_authorization()
        {
            await using var services = new Container();

            var http = services.Resolve <IHttpClientFactory>().CreateClient("GW2SDK");

            http.UseAccessToken(ConfigurationManager.Instance.ApiKeyFull);
            var sut = new SubtokenService(http);


            var actual = await sut.CreateSubtoken(null);

            Assert.IsType <CreatedSubtoken>(actual);
        }