public void WithXPathCondition() { // Act var conditions = StubConditionBuilder.Begin() .WithXPathCondition("XPathQuery1", new Dictionary <string, string> { { "soap1", "soap namespace1" } }) .WithXPathCondition("XPathQuery2", new Dictionary <string, string> { { "soap2", "soap namespace2" } }) .Build(); // Assert Assert.AreEqual(2, conditions.Xpath.Count()); var xpath1 = conditions.Xpath.ElementAt(0); Assert.AreEqual("XPathQuery1", xpath1.QueryString); Assert.AreEqual("soap namespace1", xpath1.Namespaces["soap1"]); var xpath2 = conditions.Xpath.ElementAt(1); Assert.AreEqual("XPathQuery2", xpath2.QueryString); Assert.AreEqual("soap namespace2", xpath2.Namespaces["soap2"]); }
public void WithHost() { // Act var conditions = StubConditionBuilder.Begin() .WithHost("httplaceholder.com") .Build(); // Assert Assert.AreEqual("httplaceholder.com", conditions.Host); }
public void WithHttpsDisabled() { // Act var conditions = StubConditionBuilder.Begin() .WithHttpsDisabled() .Build(); // Assert Assert.IsFalse(conditions.Url.IsHttps); }
public void ScenarioHasState() { // Act var conditions = StubConditionBuilder.Begin() .ScenarioHasState("new-state") .Build(); // Assert Assert.AreEqual("new-state", conditions.Scenario.ScenarioState); }
public void ScenarioHasAtLeastXHits() { // Act var conditions = StubConditionBuilder.Begin() .ScenarioHasAtLeastXHits(2) .Build(); // Assert Assert.AreEqual(2, conditions.Scenario.MinHits); }
public void ScenarioHasExactlyXHits() { // Act var conditions = StubConditionBuilder.Begin() .ScenarioHasExactlyXHits(2) .Build(); // Assert Assert.AreEqual(2, conditions.Scenario.ExactHits); }
public void WithHttpMethodAsHttpMethod() { // Act var conditions = StubConditionBuilder.Begin() .WithHttpMethod(HttpMethod.Post) .Build(); // Assert Assert.AreEqual("POST", conditions.Method); }
public void WithConditionsAsBuilder() { // Act var stub = StubBuilder.Begin() .WithConditions(StubConditionBuilder.Begin()) .Build(); // Assert Assert.IsNotNull(stub.Conditions); }
public void WithClientIp() { // Act var conditions = StubConditionBuilder.Begin() .WithClientIp("11.22.33.44") .Build(); // Assert Assert.AreEqual("11.22.33.44", conditions.ClientIp); }
public void WithIpInBlock() { // Act var conditions = StubConditionBuilder.Begin() .WithIpInBlock("127.0.0.0", "30") .Build(); // Assert Assert.AreEqual("127.0.0.0/30", conditions.ClientIp); }
public void WithFullPath() { // Act var conditions = StubConditionBuilder.Begin() .WithFullPath("/full-path") .Build(); // Assert Assert.AreEqual("/full-path", conditions.Url.FullPath); }
public void WithJsonArray() { // Act var array = new[] { new { key = "val1" }, new { key = "val2" } }; var conditions = StubConditionBuilder.Begin() .WithJsonArray(array) .Build(); // Assert Assert.AreEqual(array, conditions.Json); }
public void WithBasicAuthentication() { // Act var conditions = StubConditionBuilder.Begin() .WithBasicAuthentication("username", "password") .Build(); // Assert Assert.AreEqual("username", conditions.BasicAuthentication.Username); Assert.AreEqual("password", conditions.BasicAuthentication.Password); }
public void WithJsonObject() { // Act var obj = new { key = "val" }; var conditions = StubConditionBuilder.Begin() .WithJsonObject(obj) .Build(); // Assert Assert.AreEqual(obj, conditions.Json); }
public void WithQueryStringParameter() { // Act var conditions = StubConditionBuilder.Begin() .WithQueryStringParameter("q1", "val1") .WithQueryStringParameter("q2", "val2") .Build(); // Assert Assert.AreEqual(2, conditions.Url.Query.Count); Assert.AreEqual("val1", conditions.Url.Query["q1"]); Assert.AreEqual("val2", conditions.Url.Query["q2"]); }
public void WithRequestHeader() { // Act var conditions = StubConditionBuilder.Begin() .WithRequestHeader("X-Header-1", "val1") .WithRequestHeader("X-Header-2", "val2") .Build(); // Assert Assert.AreEqual(2, conditions.Headers.Count); Assert.AreEqual("val1", conditions.Headers["X-Header-1"]); Assert.AreEqual("val2", conditions.Headers["X-Header-2"]); }
public void WithPostedBodySubstring() { // Act var conditions = StubConditionBuilder.Begin() .WithPostedBodySubstring("val1") .WithPostedBodySubstring("val2") .Build(); // Assert Assert.AreEqual(2, conditions.Body.Count()); Assert.AreEqual("val1", conditions.Body.ElementAt(0)); Assert.AreEqual("val2", conditions.Body.ElementAt(1)); }
public void WithJsonPathCondition() { // Act var conditions = StubConditionBuilder.Begin() .WithJsonPathCondition("jsonpath1") .WithJsonPathCondition("jsonpath2", "value2") .Build(); // Assert Assert.AreEqual(2, conditions.JsonPath.Count()); Assert.AreEqual("jsonpath1", conditions.JsonPath.ElementAt(0)); var stubJsonPathModel = (StubJsonPathModel)conditions.JsonPath.ElementAt(1); Assert.AreEqual("jsonpath2", stubJsonPathModel.Query); Assert.AreEqual("value2", stubJsonPathModel.ExpectedValue); }
public void WithPostedFormValue() { // Act var conditions = StubConditionBuilder.Begin() .WithPostedFormValue("form1", "val1") .WithPostedFormValue("form2", "val2") .Build(); // Assert Assert.AreEqual(2, conditions.Form.Count()); var form1 = conditions.Form.ElementAt(0); Assert.AreEqual("form1", form1.Key); Assert.AreEqual("val1", form1.Value); var form2 = conditions.Form.ElementAt(1); Assert.AreEqual("form2", form2.Key); Assert.AreEqual("val2", form2.Value); }
private static async Task Main(string[] args) { var services = new ServiceCollection(); services.AddHttPlaceholderClient(c => { c.RootUrl = "http://*****:*****@"curl 'https://site.com/_nuxt/fonts/fa-solid-900.3eb06c7.woff2' \ -H 'sec-ch-ua: "" Not A;Brand"";v=""99"", ""Chromium"";v=""96"", ""Google Chrome"";v=""96""' \ -H 'Referer: ' \ -H 'Origin: https://site.com' \ -H 'sec-ch-ua-mobile: ?0' \ -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' \ -H 'sec-ch-ua-platform: ""Linux""' \ --compressed ; curl 'https://site.com/_nuxt/css/4cda201.css' \ -H 'authority: site.com' \ -H 'sec-ch-ua: "" Not A;Brand"";v=""99"", ""Chromium"";v=""96"", ""Google Chrome"";v=""96""' \ -H 'sec-ch-ua-mobile: ?0' \ -H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' \ -H 'sec-ch-ua-platform: ""Linux""' \ -H 'accept: text/css,*/*;q=0.1' \ -H 'sec-fetch-site: same-origin' \ -H 'sec-fetch-mode: no-cors' \ -H 'sec-fetch-dest: style' \ -H 'accept-language: en-US,en;q=0.9,nl;q=0.8' \ -H 'cookie: Consent=eyJhbmFseXRpY2FsIjpmYWxzZX0=' \ --compressed ; curl 'https://site.com/_nuxt/1d6c3a9.js' \ -H 'authority: site.com' \ -H 'sec-ch-ua: "" Not A;Brand"";v=""99"", ""Chromium"";v=""96"", ""Google Chrome"";v=""96""' \ -H 'sec-ch-ua-mobile: ?0' \ -H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' \ -H 'sec-ch-ua-platform: ""Linux""' \ -H 'accept: */*' \ -H 'sec-fetch-site: same-origin' \ -H 'sec-fetch-mode: no-cors' \ -H 'sec-fetch-dest: script' \ -H 'accept-language: en-US,en;q=0.9,nl;q=0.8' \ -H 'cookie: Consent=eyJhbmFseXRpY2FsIjpmYWxzZX0=' \ --compressed"; var curlCommandResult = await client.CreateCurlStubsAsync(commands, false); // Create stubs based on HTTP archive (HAR). var har = await File.ReadAllTextAsync("har.json"); var harResult = await client.CreateHarStubsAsync(har, false); // Create stubs based on OpenAPI definition. var openapi = await File.ReadAllTextAsync("petstore.yaml"); var openApiResult = await client.CreateOpenApiStubsAsync(openapi, false); // Execute a scheduled job. var scheduledJobResult = await client.ExecuteScheduledJobAsync("CleanOldRequestsJob"); // Get a list of scheduled job names. var scheduledJobNames = await client.GetScheduledJobNamesAsync(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }