public void OnEvaluateDependency() { var dep = new DependencyDetector(); var jsonReader = new JsonReader.JsonReaderBody(); var testResult = new Entity.Test.TestResult("call1", new Validation(), new Response(200, jsonReader.Read("{ id: 1314, name: \"Robson\", childrens: { name: \"Cleyton\", age: 14 } }"), new Cookies(), new Header())); Assert.AreEqual("1314", dep.Evaluate("${call1.response.body.id}", testResult)); Assert.AreEqual("Robson", dep.Evaluate("${call1.response.body.name}", testResult)); Assert.AreEqual("Cleyton", dep.Evaluate("${call1.response.body.childrens.name}", testResult)); Assert.AreEqual("14", dep.Evaluate("${call1.response.body.childrens.age}", testResult)); }
public async Task Replace(RequestConfig requestConfig) { if (_dependencyDetector.IsDependency(requestConfig.Url)) { string name = _dependencyDetector.GetDependencyName(requestConfig.Url); if (_dict.TryGetValue(name, out var result)) { var valueToReplace = _dependencyDetector.Evaluate(requestConfig.Url, await result); requestConfig.Url = Regex.Replace(requestConfig.Url, @"\$\{.*\}", valueToReplace); } } }
public async Task ReplaceDependecy(JsonObject jsonObject) { foreach (var item in jsonObject.Keys) { var jsonItem = jsonObject[item]; if (jsonItem is JsonObject) { await ReplaceDependecy(jsonItem as JsonObject); } if (jsonItem is JsonString) { var value = jsonItem.GetValue().ToString(); if (_dependencyDetector.IsDependency(value)) { string name = _dependencyDetector.GetDependencyName(value); if (_dict.TryGetValue(name, out var result)) { var valueToReplace = _dependencyDetector.Evaluate(value, await result); (jsonItem as JsonString).Value = valueToReplace; } } } } }