Пример #1
0
        public async Task DeleteClientPropertyAsync()
        {
            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 Property
            var clientProperty = ClientMock.GenerateRandomClientProperty();

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

            //Get new client property
            var newClientProperties = await clientRepository.GetClientPropertyAsync(clientPropertyId);

            //Asert
            newClientProperties.ShouldBeEquivalentTo(clientProperty, options => options.Excluding(o => o.Id).Excluding(x => x.Client));

            //Try delete it
            await clientRepository.DeleteClientPropertyAsync(newClientProperties);

            //Get new client property
            var deletedClientProperty = await clientRepository.GetClientPropertyAsync(clientProperty.Id);

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