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); } } } } }
/// <summary> /// Prepare and send an HTTP API call to obtain information about a particular version of the API available at /// the current endpoint for the service. /// </summary> /// <param name="service">The <see cref="IBaseIdentityService"/> instance.</param> /// <param name="apiVersionId">The unique ID of the API version.</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 an <see cref="ApiVersion"/> instance describing the /// specified version of the API. /// </returns> /// <exception cref="ArgumentNullException"> /// <para>If <paramref name="service"/> is <see langword="null"/>.</para> /// <para>-or-</para> /// <para>If <paramref name="apiVersionId"/> is <see langword="null"/>.</para> /// </exception> /// <exception cref="HttpWebException"> /// If an error occurred during an HTTP request while preparing or sending the HTTP API call. /// </exception> /// <seealso cref="BaseIdentityServiceExtensions.GetApiVersionAsync"/> /// <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 <ApiVersion> GetApiVersionAsync(this IBaseIdentityService service, ApiVersionId apiVersionId, CancellationToken cancellationToken) { if (service == null) { throw new ArgumentNullException("service"); } if (apiVersionId == null) { throw new ArgumentNullException("apiVersionId"); } return(TaskBlocks.Using( () => service.PrepareGetApiVersionAsync(apiVersionId, cancellationToken), task => task.Result.SendAsync(cancellationToken).Select(innerTask => innerTask.Result.Item2.Version))); }
public async Task TestGetApiVersion2() { using (CancellationTokenSource cancellationTokenSource = new CancellationTokenSource()) { cancellationTokenSource.CancelAfter(TestTimeout(TimeSpan.FromSeconds(10))); using (IBaseIdentityService service = CreateService()) { ApiVersionId version2 = new ApiVersionId("v2.0"); // test using the simple extension method ApiVersion version = await service.GetApiVersionAsync(version2, cancellationTokenSource.Token); Assert.IsNotNull(version); Assert.AreEqual(version2, version.Id); } } }
public async Task TestListApiVersionsSimple() { using (CancellationTokenSource cancellationTokenSource = new CancellationTokenSource()) { cancellationTokenSource.CancelAfter(TestTimeout(TimeSpan.FromSeconds(10))); using (IBaseIdentityService service = CreateService()) { // test using the simple extension method ReadOnlyCollectionPage <ApiVersion> versions = await service.ListApiVersionsAsync(cancellationTokenSource.Token); Assert.IsNotNull(versions); Assert.AreNotEqual(0, versions.Count); Assert.IsFalse(versions.CanHaveNextPage); Assert.IsFalse(versions.Contains(null)); } } }
/// <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))); }