/// <summary> /// Gets the API scope. /// </summary> /// <param name="apiScopeName">Name of the API scope.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> private async Task <ApiScopeDetails> GetApiScope(String apiScopeName, CancellationToken cancellationToken) { ApiScopeDetails apiScopeDetails = await this.TestingContext.DockerHelper.SecurityServiceClient.GetApiScope(apiScopeName, cancellationToken).ConfigureAwait(false); return(apiScopeDetails); }
/// <summary> /// Gets the API scope. /// </summary> /// <param name="apiScopeName">Name of the API scope.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> public async Task <ApiScopeDetails> GetApiScope(String apiScopeName, CancellationToken cancellationToken) { ApiScopeDetails response = null; String requestUri = this.BuildRequestUrl($"/api/apiscopes/{apiScopeName}"); try { // Add the access token to the client headers //this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); // Make the Http Call here HttpResponseMessage httpResponse = await this.HttpClient.GetAsync(requestUri, cancellationToken); // Process the response String content = await this.HandleResponse(httpResponse, cancellationToken); // call was successful so now deserialise the body to the response object response = JsonConvert.DeserializeObject <ApiScopeDetails>(content); } catch (Exception ex) { // An exception has occurred, add some additional information to the message Exception exception = new Exception($"Error getting api scope {apiScopeName}.", ex); throw exception; } return(response); }
public void ModelFactory_ConvertFrom_ApiScope_ModelIsNull_NullReturned() { IModelFactory modelFactory = new ModelFactory(); ApiScope apiScopeModel = null; ApiScopeDetails apiScopeDto = modelFactory.ConvertFrom(apiScopeModel); apiScopeDto.ShouldBeNull(); }
public void ModelFactory_ConvertFrom_ApiScope_ModelConverted() { IModelFactory modelFactory = new ModelFactory(); ApiScope apiScopeModel = new ApiScope { Description = SecurityServiceManagerTestData.ApiScopeDescription, Name = SecurityServiceManagerTestData.ApiScopeName, DisplayName = SecurityServiceManagerTestData.ApiScopeDisplayName, Enabled = true }; ApiScopeDetails apiScopeDto = modelFactory.ConvertFrom(apiScopeModel); apiScopeDto.Description.ShouldBe(SecurityServiceManagerTestData.ApiScopeDescription); apiScopeDto.DisplayName.ShouldBe(SecurityServiceManagerTestData.ApiScopeDisplayName); apiScopeDto.Name.ShouldBe(SecurityServiceManagerTestData.ApiScopeName); apiScopeDto.Enabled.ShouldBeTrue(); }