/// <summary>
        /// Prepare and send an HTTP API call to obtain a list of API versions available at the current endpoint for a
        /// service.
        /// </summary>
        /// <param name="service">The <see cref="IBaseIdentityService"/> instance.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> that the task will observe.</param>
        /// <returns>
        /// A <seealso cref="Task"/> representing the asynchronous operation. When the task completes successfully, the
        /// <see cref="Task{TResult}.Result"/> property will contain the first page of results describing the API
        /// versions available at the current endpoint.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// if <paramref name="service"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="HttpWebException">
        /// If an error occurred during an HTTP request while preparing or sending the HTTP API call.
        /// </exception>
        /// <seealso cref="IBaseIdentityService.PrepareListApiVersionsAsync"/>
        /// <seealso href="http://developer.openstack.org/api-ref-identity-v2.html#identity-v2-versions">API versions (Identity API v2.0 - OpenStack Complete API Reference)</seealso>
        /// <seealso href="http://developer.openstack.org/api-ref-identity-v3.html#versions-identity-v3">API versions (Identity API v3 - OpenStack Complete API Reference)</seealso>
        public static Task <ReadOnlyCollectionPage <ApiVersion> > ListApiVersionsAsync(this IBaseIdentityService service, CancellationToken cancellationToken)
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }

            return(TaskBlocks.Using(
                       () => service.PrepareListApiVersionsAsync(cancellationToken),
                       task => task.Result.SendAsync(cancellationToken).Select(innerTask => innerTask.Result.Item2)));
        }
        public async Task TestListApiVersions()
        {
            using (CancellationTokenSource cancellationTokenSource = new CancellationTokenSource())
            {
                cancellationTokenSource.CancelAfter(TestTimeout(TimeSpan.FromSeconds(10)));

                using (IBaseIdentityService service = CreateService())
                {
                    ListApiVersionsApiCall apiCall = await service.PrepareListApiVersionsAsync(cancellationTokenSource.Token);

                    Tuple <HttpResponseMessage, ReadOnlyCollectionPage <ApiVersion> > response = await apiCall.SendAsync(cancellationTokenSource.Token);

                    Assert.IsNotNull(response);
                    Assert.IsNotNull(response.Item1);

                    ReadOnlyCollectionPage <ApiVersion> versions = response.Item2;
                    Assert.IsNotNull(versions);
                    Assert.AreNotEqual(0, versions.Count);
                    Assert.IsFalse(versions.CanHaveNextPage);
                    Assert.IsFalse(versions.Contains(null));

                    foreach (ApiVersion version in versions)
                    {
                        Assert.IsNotNull(version);
                        Assert.IsNotNull(version.Id);
                        Assert.IsNotNull(version.LastModified);
                        Assert.IsFalse(version.MediaTypes.IsDefault);
                        Assert.IsFalse(version.Links.IsDefault);
                        Assert.IsNotNull(version.Status);

                        Assert.AreNotEqual(0, version.MediaTypes.Length);
                        foreach (MediaType mediaType in version.MediaTypes)
                        {
                            Assert.IsNotNull(mediaType);
                            Assert.IsNotNull(mediaType.Base);
                            Assert.IsNotNull(mediaType.Type);
                        }

                        Assert.AreNotEqual(0, version.Links.Length);
                        foreach (Link link in version.Links)
                        {
                            Assert.IsNotNull(link);
                            Assert.IsNotNull(link.Target);
                            Assert.IsNotNull(link.Relation);
                            Assert.IsTrue(link.Target.IsAbsoluteUri);
                        }
                    }
                }
            }
        }