public async Task InvalidClientIdRaiseUnknownClientEvent(
            TestIdentityServer4TestServerFactory serverFactory,
            TestIdentityServer4TestClientFactory clientFactory,
            string clientId,
            string clientSecret,
            string apiResourceName,
            string apiResourceDisplayName,
            IdentityServerEventCapture eventCapture)
        {
            using (var server = await serverFactory
                                .WithApiResource(new ApiResource(apiResourceName, apiResourceDisplayName))
                                .WithEventCapture(eventCapture)
                                .Create())
            {
                using (var client = clientFactory
                                    .WithClientId(clientId)
                                    .WithClientSecret(clientSecret)
                                    .Create(server))
                {
                    await client.GetToken();

                    Assert.True(eventCapture.ContainsMessage("Unknown client"));
                }
            }
        }
        public async Task InvalidClientSecretRaisesInvalidClientSecretEvent(
            TestIdentityServer4TestServerFactory serverFactory,
            TestIdentityServer4TestClientFactory clientFactory,
            string clientId,
            string clientSecret,
            string invalidClientSecret,
            string apiResourceName,
            string apiResourceDisplayName,
            IdentityServerEventCapture eventCapture)
        {
            using (var server = await serverFactory
                                .WithClient(new Client
            {
                ClientId = clientId,
                ClientSecrets = new List <Secret> {
                    new Secret(clientSecret.Sha256())
                },
                AllowedGrantTypes = GrantTypes.ClientCredentials,
                AllowedScopes = new List <string> {
                    apiResourceName
                },
            })
                                .WithApiResource(new ApiResource(apiResourceName, apiResourceDisplayName))
                                .WithEventCapture(eventCapture)
                                .Create())
            {
                using (var client = clientFactory
                                    .WithClientId(clientId)
                                    .WithClientSecret(invalidClientSecret)
                                    .Create(server))
                {
                    await client.GetToken();

                    Assert.True(eventCapture.ContainsMessage("Invalid client secret"));
                }
            }
        }
 /// <summary>
 /// Adds event capture.
 /// </summary>
 /// <param name="eventCapture">The event capture.</param>
 /// <returns>The server factory.</returns>
 public TServerFactory WithEventCapture(IdentityServerEventCapture eventCapture)
 {
     this.currentEventCapture = eventCapture ?? throw new ArgumentNullException(nameof(eventCapture));
     return(this as TServerFactory);
 }