public void OnDependencyDetector_GetDependencyNameFromUrl()
        {
            var dep = new DependencyDetector();

            Assert.AreEqual("call1", dep.GetDependencyName("http://localhost:59635/api/UserCrud/${call1.response}"));
            Assert.AreEqual("call2", dep.GetDependencyName("http://localhost:59635/api/UserCrud/${call2.request}/resource"));
        }
        public void OnDependencyDetector_GetDependencyName()
        {
            var dep = new DependencyDetector();

            Assert.AreEqual("call1", dep.GetDependencyName("${call1.response}"));
            Assert.AreEqual("call2", dep.GetDependencyName("${call2.response}"));

            try
            {
                // throw exception on not recognized a dependency
                dep.GetDependencyName("${ANY}");
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("value is not a dependency", ex.Message);
                return;
            }
            Assert.Fail();
        }
Example #3
0
 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;
                 }
             }
         }
     }
 }