コード例 #1
0
        /// <summary>
        /// Recycles the current access key as an asynchronous operation.
        /// </summary>
        /// <returns>
        /// A <see cref="Task{TResult}"/> representing the asynchronous operation to recycle the access key which returns the new and old access keys.
        /// </returns>
        /// <remarks>
        /// The credentials used by the current instance are automatically updated if successful.
        /// </remarks>
        public virtual async Task <RecycleAccessKeyResult> RecycleAccessKeyAsync()
        {
            var value = new { };
            var json  = SerializeAsJson(value);

            using (var client = CreateClient())
            {
                using (var content = new StringContent(json, Encoding.UTF8, "application/json"))
                {
                    using (var response = await client.PutAsync("recycle_key.json", content))
                    {
                        await EnsureSuccessAsync(response);

                        RecycleAccessKeyResult result = await DeserializeAsync <RecycleAccessKeyResult>(response);

                        if (result != null)
                        {
                            SetAuthorization(UserName, result.NewKey);
                        }

                        return(result);
                    }
                }
            }
        }
        public static async Task Can_Recycle_BrowserStack_Api_Key()
        {
            // Arrange
            string expected = Environment.GetEnvironmentVariable("BrowserStack_AccessKey");
            BrowserStackAutomateClient target = CreateAuthenticatedClient();

            // Act
            RecycleAccessKeyResult actual = await target.RecycleAccessKeyAsync();

            // Assert
            actual.Should().NotBeNull();
            actual.OldKey.Should().Be(expected);
            actual.NewKey.Should().NotBe(expected);
        }