/// <inheritdoc />
        public async ValueTask <UserId> GetIdentityServiceUserId(Models.User user, CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();
            if (userIdCache.TryGetValue(user.Id, out var cachedId))
            {
                return(cachedId);
            }

            var result = await loginProvidersClient.GetUserByLoginProviderKey("discord", user.Id, cancellationToken);

            var userId = GetUserId(result, "discord");

            userIdCache.Add(user.Id, userId);
            return(userId);
        }
Beispiel #2
0
            public async Task ShouldRetrieveUserIdFromCacheIfPresent(
                Models.User user,
                UserId expectedId,
                [Frozen, Substitute] IUserIdCache userIdCache,
                [Frozen, Substitute] ILoginProvidersClient loginProvidersClient,
                [Target] DefaultUserService service,
                CancellationToken cancellationToken
                )
            {
                userIdCache.TryGetValue(Any <Snowflake>(), out Any <UserId>()).Returns(x =>
                {
                    x[1] = expectedId;
                    return(true);
                });

                var result = await service.GetIdentityServiceUserId(user, cancellationToken);

                result.Should().Be(expectedId);
                await loginProvidersClient.DidNotReceive().GetUserByLoginProviderKey(Is("discord"), Is(user.Id.Value.ToString()), Is(cancellationToken));
            }