private async Task <HttpResponseMessage> TestRequestAsync(IVerifyCaptcha verifyCaptcha, string header, string endpoint, int expectedStatusCode, bool isReCaptchaEnabled = true) { using var client = this.GetHttpClient(verifyCaptcha, isReCaptchaEnabled); if (header != null) { client.DefaultRequestHeaders.Add(header, "test"); } var response = await client.GetAsync(endpoint); Assert.Equal(expectedStatusCode, (int)response.StatusCode); return(response); }
public TestWebApplicationFactory(IVerifyCaptcha verifyCaptcha, bool isReCaptchaEnabled) { this.verifyCaptcha = verifyCaptcha ?? throw new System.ArgumentNullException(nameof(verifyCaptcha)); this.isReCaptchaEnabled = isReCaptchaEnabled; }
public ReCaptchaVerificationActionFilter(IVerifyCaptcha verifyCaptcha, bool isEnabled = true) { this.verifyCaptcha = verifyCaptcha; this.IsEnabled = isEnabled; }
private HttpClient GetHttpClient(IVerifyCaptcha verifyCaptcha, bool isReCaptchaEnabled) { var factory = new TestWebApplicationFactory(verifyCaptcha, isReCaptchaEnabled); return(factory.CreateDefaultClient()); }