Example #1
0
            public async Task ShouldReturnFalseIfLoginProvidersClientThrows(
                ulong userId,
                Guid remoteId,
                string errorMessage,
                ApiException exception,
                [Frozen, Substitute] IUserIdCache cache,
                [Frozen, Substitute] ILoginProvidersClient client,
                [Target] DefaultUserService service
                )
            {
                var user = new Models.User {
                    Id = userId
                };
                var remoteUser = new Identity.Client.User {
                    Id = remoteId
                };
                var cancellationToken = new CancellationToken(false);

                cache.ContainsKey(Any <Snowflake>()).Returns(false);
                client.GetUserByLoginProviderKey(Any <string>(), Any <string>(), Any <CancellationToken>()).Returns <Identity.Client.User>(x =>
                {
                    throw exception;
                });

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

                result.Should().BeFalse();

                await client.Received().GetUserByLoginProviderKey(Is("discord"), Is(userId.ToString()), Is(cancellationToken));
            }
Example #2
0
            public async Task ShouldReturnTrueIfUserIdNotInCacheButReturnsFromTheApi(
                ulong userId,
                Guid remoteId,
                [Frozen, Substitute] IUserIdCache cache,
                [Frozen, Substitute] ILoginProvidersClient client,
                [Target] DefaultUserService service
                )
            {
                var user = new Models.User {
                    Id = userId
                };
                var login = new UserLogin {
                    LoginProvider = "discord", Enabled = true
                };
                var remoteUser = new Identity.Client.User {
                    Id = remoteId, Logins = new List <UserLogin> {
                        login
                    }
                };
                var cancellationToken = new CancellationToken(false);

                cache.ContainsKey(Any <Snowflake>()).Returns(false);
                client.GetUserByLoginProviderKey(Any <string>(), Any <string>(), Any <CancellationToken>()).Returns(remoteUser);

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

                result.Should().BeTrue();

                await client.Received().GetUserByLoginProviderKey(Is("discord"), Is(userId.ToString()), Is(cancellationToken));
            }
Example #3
0
            public async Task ShouldCacheReturnedUserIds(
                ulong userId,
                Guid remoteId,
                [Frozen, Substitute] IUserIdCache cache,
                [Frozen, Substitute] ILoginProvidersClient client,
                [Target] DefaultUserService service
                )
            {
                var user = new Models.User {
                    Id = userId
                };
                var login = new UserLogin {
                    LoginProvider = "discord", Enabled = true
                };
                var remoteUser = new Identity.Client.User {
                    Id = remoteId, Logins = new List <UserLogin> {
                        login
                    }
                };
                var cancellationToken = new CancellationToken(false);

                cache.ContainsKey(Any <Snowflake>()).Returns(false);
                client.GetUserByLoginProviderKey(Any <string>(), Any <string>(), Any <CancellationToken>()).Returns(remoteUser);

                await service.IsUserRegistered(user, cancellationToken);

                cache.Received().Add(Is(user.Id), Is <UserId>(id => id.Id == remoteId && id.Enabled));
            }
Example #4
0
            public async Task ShouldReturnTrueIfUserIdExistsInCache(
                ulong userId,
                [Frozen, Substitute] IUserIdCache cache,
                [Target] DefaultUserService service
                )
            {
                var user = new Models.User {
                    Id = userId
                };
                var cancellationToken = new CancellationToken(false);

                cache.ContainsKey(Any <Snowflake>()).Returns(true);

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

                result.Should().BeTrue();
                cache.Received().ContainsKey(Is(user.Id));
            }