public async Task AddClientPropertyAsync()
        {
            using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore))
            {
                IClientRepository clientRepository = new ClientRepository(context);

                //Generate random new client without id
                var client = ClientMock.GenerateRandomClient(0);

                //Add new client
                await clientRepository.AddClientAsync(client);

                //Get new client
                var clientEntity = await clientRepository.GetClientAsync(client.Id);

                //Assert new client
                clientEntity.Should().BeEquivalentTo(client, options => options.Excluding(o => o.Id));

                //Generate random new Client property
                var clientProperty = ClientMock.GenerateRandomClientProperty(0);

                //Add new client property
                await clientRepository.AddClientPropertyAsync(clientEntity.Id, clientProperty);

                //Get new client property
                var newClientProperty = await context.ClientProperties.Where(x => x.Id == clientProperty.Id)
                                        .SingleOrDefaultAsync();

                newClientProperty.Should().BeEquivalentTo(clientProperty,
                                                          options => options.Excluding(o => o.Id).Excluding(x => x.Client));
            }
        }
        public async Task RemoveClientAsync()
        {
            using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore))
            {
                IClientRepository clientRepository = new ClientRepository(context);

                //Generate random new client without id
                var client = ClientMock.GenerateRandomClient(0);

                //Add new client
                await clientRepository.AddClientAsync(client);

                //Get new client
                var clientEntity = await context.Clients.Where(x => x.Id == client.Id).SingleAsync();

                //Assert new client
                clientEntity.Should().BeEquivalentTo(client, options => options.Excluding(o => o.Id));

                //Detached the added item
                context.Entry(clientEntity).State = EntityState.Detached;

                //Remove client
                await clientRepository.RemoveClientAsync(clientEntity);

                //Try Get Removed client
                var removeClientEntity = await context.Clients.Where(x => x.Id == clientEntity.Id)
                                         .SingleOrDefaultAsync();

                //Assert removed client - it might be null
                removeClientEntity.Should().BeNull();
            }
        }
        public async Task UpdateClientAsync()
        {
            using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore))
            {
                IClientRepository clientRepository = new ClientRepository(context);

                //Generate random new client without id
                var client = ClientMock.GenerateRandomClient(0);

                //Add new client
                await clientRepository.AddClientAsync(client);

                //Get new client
                var clientEntity = await context.Clients.Where(x => x.Id == client.Id).SingleAsync();

                //Assert new client
                clientEntity.Should().BeEquivalentTo(client, options => options.Excluding(o => o.Id));

                //Detached the added item
                context.Entry(clientEntity).State = EntityState.Detached;

                //Generete new client with added item id
                var updatedClient = ClientMock.GenerateRandomClient(clientEntity.Id);

                //Update client
                await clientRepository.UpdateClientAsync(updatedClient);

                //Get updated client
                var updatedClientEntity =
                    await context.Clients.Where(x => x.Id == updatedClient.Id).SingleAsync();

                //Assert updated client
                updatedClientEntity.Should().BeEquivalentTo(updatedClient);
            }
        }
        public async Task GetClientSecretAsync()
        {
            using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore))
            {
                IClientRepository clientRepository = new ClientRepository(context);

                //Generate random new client without id
                var client = ClientMock.GenerateRandomClient(0);

                //Add new client
                await clientRepository.AddClientAsync(client);

                //Get new client
                var clientEntity = await clientRepository.GetClientAsync(client.Id);

                //Assert new client
                clientEntity.Should().BeEquivalentTo(client, options => options.Excluding(o => o.Id));

                //Generate random new Client Secret
                var clientSecret = ClientMock.GenerateRandomClientSecret(0);

                //Add new client secret
                await clientRepository.AddClientSecretAsync(clientEntity.Id, clientSecret);

                //Get new client secret
                var newSecret = await clientRepository.GetClientSecretAsync(clientSecret.Id);

                newSecret.Should().BeEquivalentTo(clientSecret,
                                                  options => options.Excluding(o => o.Id).Excluding(x => x.Client));
            }
        }
        public async Task GetClientsAsync()
        {
            using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore))
            {
                IClientRepository clientRepository = new ClientRepository(context);

                var rnd          = new Random();
                var generateRows = rnd.Next(1, 10);

                //Generate random new clients
                var randomClients = ClientMock.GenerateRandomClients(0, generateRows);

                foreach (var client in randomClients)
                {
                    //Add new client
                    await clientRepository.AddClientAsync(client);
                }

                var clients = await clientRepository.GetClientsAsync();

                //Assert clients count
                clients.Data.Count.Should().Be(randomClients.Count);

                //Assert that clients are same
                clients.Data.Should().BeEquivalentTo(randomClients);
            }
        }
예제 #6
0
        public async Task CloneClientWithoutScopesAsync()
        {
            using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore))
            {
                //Generate random new client
                var client = ClientMock.GenerateRandomClient(0, generateClaims: true, generateProperties: true, generateSecrets: true);

                IClientRepository clientRepository = new ClientRepository(context);

                //Add new client
                client.ClientSecrets = null;
                await clientRepository.AddClientAsync(client);

                var clientToClone = await context.Clients.Where(x => x.Id == client.Id).SingleOrDefaultAsync();

                //Try clone it
                var clonedClientId = await clientRepository.CloneClientAsync(clientToClone, cloneClientScopes : false);

                var cloneClientEntity = await clientRepository.GetClientAsync(clonedClientId);

                var clientToCompare = await clientRepository.GetClientAsync(clientToClone.Id);

                ClientCloneCompare(cloneClientEntity, clientToCompare, cloneClientScopes: false);
            }
        }
        public async Task DeleteClientClaimAsync()
        {
            using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore))
            {
                IClientRepository clientRepository = new ClientRepository(context);

                //Generate random new client without id
                var client = ClientMock.GenerateRandomClient(0);

                //Add new client
                await clientRepository.AddClientAsync(client);

                //Get new client
                var clientEntity = await clientRepository.GetClientAsync(client.Id);

                //Assert new client
                clientEntity.Should().BeEquivalentTo(client, options => options.Excluding(o => o.Id));

                //Generate random new Client Claim
                var clientClaim = ClientMock.GenerateRandomClientClaim(0);

                //Add new client claim
                await clientRepository.AddClientClaimAsync(clientEntity.Id, clientClaim);

                //Get new client claim
                var newClientClaim =
                    await context.ClientClaims.Where(x => x.Id == clientClaim.Id).SingleOrDefaultAsync();

                //Asert
                newClientClaim.Should().BeEquivalentTo(clientClaim,
                                                       options => options.Excluding(o => o.Id).Excluding(x => x.Client));

                //Try delete it
                await clientRepository.DeleteClientClaimAsync(newClientClaim);

                //Get new client claim
                var deletedClientClaim =
                    await context.ClientClaims.Where(x => x.Id == clientClaim.Id).SingleOrDefaultAsync();

                //Assert
                deletedClientClaim.Should().BeNull();
            }
        }
        public async Task AddClientAsync()
        {
            using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore))
            {
                IClientRepository clientRepository = new ClientRepository(context);

                //Generate random new client
                var client = ClientMock.GenerateRandomClient(0);

                //Add new client
                await clientRepository.AddClientAsync(client);

                //Get new client
                var clientEntity = await context.Clients.Where(x => x.Id == client.Id).SingleAsync();

                //Assert new client
                clientEntity.ShouldBeEquivalentTo(client, options => options.Excluding(o => o.Id));
            }
        }