/// <summary> /// Retrieves the resources associated with a scope. /// </summary> /// <param name="scope">The scope.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param> /// <returns> /// A <see cref="Task"/> that can be used to monitor the asynchronous operation, /// whose result returns all the resources associated with the scope. /// </returns> public virtual Task <ImmutableArray <string> > GetResourcesAsync(OpenIdScope scope, CancellationToken cancellationToken) { if (scope == null) { throw new ArgumentNullException(nameof(scope)); } return(Task.FromResult(scope.Resources)); }
/// <summary> /// Retrieves the additional properties associated with a scope. /// </summary> /// <param name="scope">The scope.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param> /// <returns> /// A <see cref="Task"/> that can be used to monitor the asynchronous operation, whose /// result returns all the additional properties associated with the scope. /// </returns> public virtual Task <JObject> GetPropertiesAsync(OpenIdScope scope, CancellationToken cancellationToken) { if (scope == null) { throw new ArgumentNullException(nameof(scope)); } return(Task.FromResult(scope.Properties ?? new JObject())); }
/// <summary> /// Retrieves the physical identifier associated with a scope. /// </summary> /// <param name="scope">The scope.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param> /// <returns> /// A <see cref="Task"/> that can be used to monitor the asynchronous operation, /// whose result returns the physical identifier associated with the scope. /// </returns> public virtual Task <string> GetPhysicalIdAsync(OpenIdScope scope, CancellationToken cancellationToken) { if (scope == null) { throw new ArgumentNullException(nameof(scope)); } return(Task.FromResult(scope.Id.ToString(CultureInfo.InvariantCulture))); }
/// <summary> /// Retrieves the name associated with a scope. /// </summary> /// <param name="scope">The scope.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param> /// <returns> /// A <see cref="Task"/> that can be used to monitor the asynchronous operation, /// whose result returns the name associated with the specified scope. /// </returns> public virtual Task <string> GetNameAsync(OpenIdScope scope, CancellationToken cancellationToken) { if (scope == null) { throw new ArgumentNullException(nameof(scope)); } return(Task.FromResult(scope.Name)); }
/// <summary> /// Sets the resources associated with a scope. /// </summary> /// <param name="scope">The scope.</param> /// <param name="resources">The resources associated with the scope.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param> /// <returns> /// A <see cref="Task"/> that can be used to monitor the asynchronous operation. /// </returns> public virtual Task SetResourcesAsync(OpenIdScope scope, ImmutableArray <string> resources, CancellationToken cancellationToken) { if (scope == null) { throw new ArgumentNullException(nameof(scope)); } scope.Resources = resources; return(Task.CompletedTask); }
/// <summary> /// Sets the additional properties associated with a scope. /// </summary> /// <param name="scope">The scope.</param> /// <param name="properties">The additional properties associated with the scope </param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param> /// <returns> /// A <see cref="Task"/> that can be used to monitor the asynchronous operation. /// </returns> public virtual Task SetPropertiesAsync(OpenIdScope scope, JObject properties, CancellationToken cancellationToken) { if (scope == null) { throw new ArgumentNullException(nameof(scope)); } scope.Properties = properties; return(Task.CompletedTask); }
/// <summary> /// Sets the name associated with a scope. /// </summary> /// <param name="scope">The scope.</param> /// <param name="name">The name associated with the authorization.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param> /// <returns> /// A <see cref="Task"/> that can be used to monitor the asynchronous operation. /// </returns> public virtual Task SetNameAsync(OpenIdScope scope, string name, CancellationToken cancellationToken) { if (scope == null) { throw new ArgumentNullException(nameof(scope)); } scope.Name = name; return(Task.CompletedTask); }
/// <summary> /// Sets the description associated with a scope. /// </summary> /// <param name="scope">The scope.</param> /// <param name="description">The description associated with the authorization.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param> /// <returns> /// A <see cref="Task"/> that can be used to monitor the asynchronous operation. /// </returns> public virtual Task SetDescriptionAsync(OpenIdScope scope, string description, CancellationToken cancellationToken) { if (scope == null) { throw new ArgumentNullException(nameof(scope)); } scope.Description = description; return(Task.CompletedTask); }
/// <summary> /// Creates a new scope. /// </summary> /// <param name="scope">The scope to create.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param> /// <returns> /// A <see cref="Task"/> that can be used to monitor the asynchronous operation. /// </returns> public virtual Task CreateAsync(OpenIdScope scope, CancellationToken cancellationToken) { if (scope == null) { throw new ArgumentNullException(nameof(scope)); } cancellationToken.ThrowIfCancellationRequested(); _session.Save(scope); return(_session.CommitAsync()); }
public async Task OpenIdScopeCanBeUpdated() { // Arrange // Match expected with scope-recipe.json var scopeName = "test_scope"; var expected = CreateScopeDescriptor( scopeName, "A", "res1", "res2", "res3"); var actual = CreateScopeDescriptor( scopeName, "B", "res"); var dbActual = new OpenIdScope { Name = actual.Name, Resources = actual.Resources.ToImmutableArray() }; var scopeManagerMock = new Mock <IOpenIdScopeManager>(MockBehavior.Strict); scopeManagerMock.Setup(m => m.FindByNameAsync( It.IsAny <string>(), It.IsAny <CancellationToken>())) .Returns( new ValueTask <object>(dbActual)); scopeManagerMock.Setup(m => m.PopulateAsync( It.IsAny <object>(), It.IsAny <OpenIdScopeDescriptor>(), It.IsAny <CancellationToken>())) .Returns( new ValueTask()); scopeManagerMock.Setup(m => m.UpdateAsync( It.IsAny <object>(), It.IsAny <OpenIdScopeDescriptor>(), It.IsAny <CancellationToken>())) .Callback <object, OpenIddictScopeDescriptor, CancellationToken>((s, desc, c) => actual = (OpenIdScopeDescriptor)desc) .Returns( new ValueTask()); var step = new OpenIdScopeStep(scopeManagerMock.Object); var recipe = JObject.Parse(GetRecipeFileContent("scope-recipe")); var context = new RecipeExecutionContext { Name = recipe.Property("steps").Value.First.Value <string>("name"), Step = (JObject)recipe.Property("steps").Value.First, }; // Act await step.ExecuteAsync(context); // Assert scopeManagerMock.Verify(m => m.FindByNameAsync( It.Is <string>(v => v == expected.Name), It.IsAny <CancellationToken>())); scopeManagerMock.Verify(m => m.PopulateAsync( It.IsAny <object>(), It.IsAny <OpenIdScopeDescriptor>(), It.IsAny <CancellationToken>())); scopeManagerMock.Verify(m => m.UpdateAsync( It.IsAny <object>(), It.IsAny <OpenIdScopeDescriptor>(), It.IsAny <CancellationToken>())); Assert.Equal(expected.Name, actual.Name); Assert.Equal(expected.DisplayName, actual.DisplayName); Assert.Equal(expected.Description, actual.Description); Assert.Equal(expected.Resources.ToArray(), actual.Resources.ToArray()); }