Example #1
0
        public async Task DeleteClientSecretAsync()
        {
            IClientRepository clientRepository = new ClientDapperRepository(_configuration);

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

            //Add new client
            var clientId = await clientRepository.AddClientAsync(client);

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

            //Assert new client
            clientEntity.ShouldBeEquivalentTo(client, options => options.Excluding(o => o.Id)
                                              .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "AllowedGrantTypes\\[.+\\].Id"))
                                              .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "RedirectUris\\[.+\\].Id"))
                                              .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "PostLogoutRedirectUris\\[.+\\].Id"))
                                              .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "AllowedScopes\\[.+\\].Id"))
                                              .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "IdentityProviderRestrictions\\[.+\\].Id"))
                                              .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "AllowedCorsOrigins\\[.+\\].Id")));

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

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

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

            //Asert
            newSecret.ShouldBeEquivalentTo(clientSecret, options => options.Excluding(o => o.Id).Excluding(x => x.Client).Excluding(x => x.Expiration));

            //Try delete it
            await clientRepository.DeleteClientSecretAsync(newSecret);

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

            //Assert
            deletedSecret.Should().BeNull();
        }