Repository navigation
[PM-32100] Implement Multi-Provider Ability Lookup #7552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JimmyVo16
merged 9 commits into
main
from
ac/pm-32100/implement-multi-provider-ability-lookup
May 4, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4a4ab72
[PM-32100] Implement Multi-Provider Ability Lookup
JimmyVo16 b3224d2
Merge branch 'main' into ac/pm-32100/implement-multi-provider-abilityβ¦
JimmyVo16 64eed98
Merge branch 'main' into ac/pm-32100/implement-multi-provider-abilityβ¦
JimmyVo16 6b88bac
[PM-32100] Add unit tests
JimmyVo16 5af11fd
Merge branch 'main' into ac/pm-32100/implement-multi-provider-abilityβ¦
JimmyVo16 487d87c
[PM-32100] Address code review feedback
JimmyVo16 5e0f1e2
Merge branch 'main' into ac/pm-32100/implement-multi-provider-abilityβ¦
JimmyVo16 1d03047
[PM-32100] Fix test and address code review
JimmyVo16 25e9a80
[PM-32100] Fix test arrangement
JimmyVo16 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
test/Core.Test/AdminConsole/AbilitiesCache/ExtendedProviderAbilityCacheServiceTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| ο»Ώusing Bit.Core.AdminConsole.AbilitiesCache; | ||
| using Bit.Core.AdminConsole.Models.Data.Provider; | ||
| using Bit.Core.AdminConsole.Repositories; | ||
| using Bit.Test.Common.AutoFixture; | ||
| using Bit.Test.Common.AutoFixture.Attributes; | ||
| using NSubstitute; | ||
| using Xunit; | ||
| using ZiggyCreatures.Caching.Fusion; | ||
|
|
||
| namespace Bit.Core.Test.AdminConsole.AbilitiesCache; | ||
|
|
||
| [SutProviderCustomize] | ||
| public class ExtendedProviderAbilityCacheServiceTests | ||
| { | ||
| [Theory, BitAutoData] | ||
| public async Task GetProviderAbilitiesAsync_ReturnsAvailableAbilitiesForRequestedIds( | ||
| SutProvider<ExtendedProviderAbilityCacheService> sutProvider, | ||
| ProviderAbility requestedAbility1, | ||
| ProviderAbility requestedAbility2, | ||
| ProviderAbility nonRequestedAbility, | ||
| ProviderAbility nonExistAbility) | ||
| { | ||
| // Arrange | ||
| SetupCacheReturns(sutProvider, requestedAbility1, requestedAbility2, nonRequestedAbility); | ||
|
|
||
| // Act | ||
| var result = await sutProvider.Sut.GetProviderAbilitiesAsync([requestedAbility1.Id, requestedAbility2.Id, nonExistAbility.Id]); | ||
|
|
||
| // Assert | ||
| Assert.Equal(2, result.Count); | ||
| Assert.Equal(requestedAbility1, result[requestedAbility1.Id]); | ||
| Assert.Equal(requestedAbility2, result[requestedAbility2.Id]); | ||
| Assert.DoesNotContain(nonRequestedAbility.Id, result.Keys); | ||
| Assert.DoesNotContain(nonExistAbility.Id, result.Keys); | ||
| } | ||
|
|
||
| [Theory, BitAutoData] | ||
| public async Task GetProviderAbilitiesAsync_WhenProviderNotFound_ExcludesNullAbilities( | ||
| SutProvider<ExtendedProviderAbilityCacheService> sutProvider, | ||
| ProviderAbility ability, | ||
| Guid missingProviderId) | ||
| { | ||
| // Arrange | ||
| SetupCacheReturns(sutProvider, ability); | ||
| sutProvider.GetDependency<IFusionCache>() | ||
| .GetOrSetAsync<ProviderAbility?>( | ||
| $"{missingProviderId}", | ||
| Arg.Any<Func<FusionCacheFactoryExecutionContext<ProviderAbility?>, CancellationToken, Task<ProviderAbility?>>>(), | ||
| token: Arg.Any<CancellationToken>()) | ||
| .Returns((ProviderAbility?)null); | ||
|
|
||
| // Act | ||
| var result = await sutProvider.Sut.GetProviderAbilitiesAsync([ability.Id, missingProviderId]); | ||
|
|
||
| // Assert | ||
| Assert.Single(result); | ||
| Assert.Equal(ability, result[ability.Id]); | ||
| } | ||
|
|
||
| [Theory, BitAutoData] | ||
| public async Task GetProviderAbilitiesAsync_WhenDuplicateIdsProvided_DoesNotThrowAndReturnsSingleEntry( | ||
| SutProvider<ExtendedProviderAbilityCacheService> sutProvider, | ||
| ProviderAbility ability) | ||
| { | ||
| // Arrange | ||
| SetupCacheReturns(sutProvider, ability); | ||
|
|
||
| // Act | ||
| var result = await sutProvider.Sut.GetProviderAbilitiesAsync([ability.Id, ability.Id, ability.Id]); | ||
|
|
||
| // Assert | ||
| Assert.Single(result); | ||
| Assert.Equal(ability, result[ability.Id]); | ||
| await sutProvider.GetDependency<IFusionCache>() | ||
| .Received(1) | ||
| .GetOrSetAsync<ProviderAbility?>( | ||
| $"{ability.Id}", | ||
| Arg.Any<Func<FusionCacheFactoryExecutionContext<ProviderAbility?>, CancellationToken, Task<ProviderAbility?>>>(), | ||
| token: Arg.Any<CancellationToken>()); | ||
| } | ||
|
|
||
| [Theory, BitAutoData] | ||
| public async Task GetProviderAbilitiesAsync_WhenEmptyList_ReturnsEmptyDictionary( | ||
| SutProvider<ExtendedProviderAbilityCacheService> sutProvider) | ||
| { | ||
| // Act | ||
| var result = await sutProvider.Sut.GetProviderAbilitiesAsync([]); | ||
|
|
||
| // Assert | ||
| Assert.Empty(result); | ||
| await sutProvider.GetDependency<IProviderRepository>() | ||
| .DidNotReceiveWithAnyArgs() | ||
| .GetAbilityAsync(default); | ||
| } | ||
|
|
||
| [Theory, BitAutoData] | ||
| public async Task GetProviderAbilitiesAsync_WhenAllProvidersNotFound_ReturnsEmptyDictionary( | ||
| SutProvider<ExtendedProviderAbilityCacheService> sutProvider, | ||
| Guid missingId1, | ||
| Guid missingId2) | ||
| { | ||
| // Arrange | ||
| sutProvider.GetDependency<IFusionCache>() | ||
| .GetOrSetAsync<ProviderAbility?>( | ||
| Arg.Any<string>(), | ||
| Arg.Any<Func<FusionCacheFactoryExecutionContext<ProviderAbility?>, CancellationToken, Task<ProviderAbility?>>>(), | ||
| token: Arg.Any<CancellationToken>()) | ||
| .Returns((ProviderAbility?)null); | ||
|
|
||
| // Act | ||
| var result = await sutProvider.Sut.GetProviderAbilitiesAsync([missingId1, missingId2]); | ||
|
|
||
| // Assert | ||
| Assert.Empty(result); | ||
| } | ||
|
|
||
| private static void SetupCacheReturns( | ||
| SutProvider<ExtendedProviderAbilityCacheService> sutProvider, | ||
| params ProviderAbility[] abilities) | ||
| { | ||
| foreach (var ability in abilities) | ||
| { | ||
| sutProvider.GetDependency<IFusionCache>() | ||
| .GetOrSetAsync<ProviderAbility?>( | ||
| $"{ability.Id}", | ||
| Arg.Any<Func<FusionCacheFactoryExecutionContext<ProviderAbility?>, CancellationToken, Task<ProviderAbility?>>>(), | ||
| token: Arg.Any<CancellationToken>()) | ||
| .Returns(ability); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.