如何在xunit自注册测试中获得recapcha响应

时间:2019-05-30 12:45:24

标签: c# xunit

我正在尝试通过注册表单上的xunit在集成测试中添加google recaptcha。我不知道如何从Recaptcha获得响应

[Fact]


            //Create new user registration
            /// Works with stp tenant, did not work with new tenant(need also to add new legal notice)
            {
                var url = $"{servicePath}/api/userregistration?api-version={configuration.ApiVersion}";
                var payload = new UserRegistrationSubmitFormModel()
                {
                    MailAddress = GenerateRandomString(8) + "@stp-online.de",
                    Password = "sfsfsf",
                    Language = "en-en",
                    OriginalApplication = configuration.Config["OriginalApplication"],
                    UserIPAddress = IPAddress.Parse("127.7.4.73"),
                    Google_recaptcha = Request.Equals["g-recaptcha-response"],

                };

                //add headers
                httpClient.DefaultRequestHeaders.Add("STP-SUBDOMAIN", "stp");

                var response = await httpClient.PostAsJsonAsync(url, payload);
                var test = await response.Content.ReadAsStringAsync();
                Assert.True(response.IsSuccessStatusCode);
                Assert.Equal(HttpStatusCode.OK, response.StatusCode);

                //check is recaptcha success
                var Google_recaptcha = await configuration.GetUserByEmail(payload.Google_recaptcha, true);
                Assert.NotNull(payload.Google_recaptcha);

0 个答案:

没有答案