public virtual string handle(IRunnerVariablesProvider variablesProvider, Config config, RestResponse response, object expressionContext, string expression) { IDictionary <string, string> namespaceContext = (IDictionary <string, string>)expressionContext; string contentTypeString = response.ContentType; string charset = response.Charset; ContentType contentType = ContentType.parse(contentTypeString); BodyTypeAdapter bodyTypeAdapter = (new BodyTypeAdapterFactory(variablesProvider, config)).getBodyTypeAdapter(contentType, charset); string body = bodyTypeAdapter.toXmlString(response.Body); if (body == null) { return(null); } string val = null; try { val = XmlTools.GetNodeValue(namespaceContext, expression, body); } catch (System.ArgumentException) { // ignore - may be that it's evaluating to a string val = (string)XmlTools.extractXPath(namespaceContext, expression, body, XPathEvaluationReturnType.String); } if (val != null) { val = val.Trim(); } return(val); }
public void Should_Evaluate_Large_Json_Text() { // Arrange. IRunnerVariablesProvider variablesProvider = GetVariablesProvider(); StringBuilder sb = new StringBuilder("{ \"content\" : \""); int size = 1024 * 1024 * 10; for (int i = 0; i < size; i++) { sb.Append("A"); } sb.Append("\"}"); string jsonBodyText = sb.ToString(); RestResponse response = CreateResponse(ContentType.JSON, jsonBodyText); JavascriptWrapper jswrapper = new JavascriptWrapper(variablesProvider); int expectedResult = size; // Act. string javascriptText = "response.jsonbody.content.length"; object rawResult = jswrapper.evaluateExpression(response, javascriptText); int actualResult = Convert.ToInt32(rawResult); // Assert. Assert.AreEqual(expectedResult, actualResult); }
public string handle(IRunnerVariablesProvider variablesProvider, Config config, RestResponse response, object expressionContext, string expression) { IList <string> content = new List <string>(); if (response != null) { foreach (RestData.Header e in response.Headers) { string @string = StringTools.convertEntryToString(e.Name, e.Value, ":"); content.Add(@string); } } string value = null; if (content.Count > 0) { Regex regex = new Regex(expression); foreach (string c in content) { Match match = regex.Match(c); if (match.Success) { int cc = match.Groups.Count; value = match.Groups[cc - 1].Value; break; } } } return(value); }
private IRunnerVariablesProvider GetVariablesProvider(FitVariables variables) { IRunnerVariablesProvider variablesProvider = Mock.Of <IRunnerVariablesProvider>(varProv => varProv.CreateRunnerVariables() == variables); return(variablesProvider); }
private void ReadResponsePropertyInJavaScript(string javascriptText, string expectedResult, RestResponse response) { // Arrange. IRunnerVariablesProvider variablesProvider = GetVariablesProvider(); JavascriptWrapper jswrapper = new JavascriptWrapper(variablesProvider); // Act. object rawResult = jswrapper.evaluateExpression(response, javascriptText); string actualResult = rawResult.ToString(); // Assert. Assert.AreEqual(expectedResult, actualResult); }
public virtual string handle(IRunnerVariablesProvider variablesProvider, Config config, RestResponse response, object expressionContext, string expression) { IDictionary <string, string> namespaceContext = (IDictionary <string, string>)expressionContext; XPathNavigator node = XmlTools.extractXPath(namespaceContext, expression, response.Body); string val = XmlTools.xPathResultToXmlString(node); int pos = val.IndexOf("?>", StringComparison.Ordinal); if (pos >= 0) { val = val.Substring(pos + 2); } return(val); }
public virtual string handle(IRunnerVariablesProvider variablesProvider, Config config, RestResponse response, object expressionContext, string expression) { JavascriptWrapper js = new JavascriptWrapper(variablesProvider); IDictionary <string, string> urlMap = config.getAsMap("restfixture.javascript.imports.map", new Dictionary <string, string>()); object result = js.evaluateExpression(response, expression, urlMap); if (result == null) { return(null); } return(result.ToString()); }
public void Should_Return_Null_For_Null_JavaScript_And_Null_JsonString() { // Arrange. IRunnerVariablesProvider variablesProvider = GetVariablesProvider(); RestResponse response = null; JavascriptWrapper jswrapper = new JavascriptWrapper(variablesProvider); string expectedResult = null; // Act. string javascriptText = "null"; object rawResult = jswrapper.evaluateExpression(response, javascriptText); string actualResult = (string)rawResult; // Assert. Assert.AreEqual(expectedResult, actualResult); }
public void Should_Handle_Null_ResponseObject() { // Arrange. IRunnerVariablesProvider variablesProvider = GetVariablesProvider(); RestResponse response = null; JavascriptWrapper jswrapper = new JavascriptWrapper(variablesProvider); string expectedResult = "response is null: true"; // Act. string javascriptText = "'response is null: ' + (response == null)"; object rawResult = jswrapper.evaluateExpression(response, javascriptText); string actualResult = rawResult.ToString(); // Assert. Assert.AreEqual(expectedResult, actualResult); }
public void Should_Read_Symbols_From_JavaScript() { // Arrange. FitVariables initialVariables = new FitVariables(); initialVariables.put("my_sym", "98"); IRunnerVariablesProvider variablesProvider = GetVariablesProvider(initialVariables); RestResponse response = new RestResponse(); JavascriptWrapper jswrapper = new JavascriptWrapper(variablesProvider); string expectedResult = "my sym is: 98"; // Act. string javascriptText = "'my sym is: ' + symbols['my_sym']"; object rawResult = jswrapper.evaluateExpression(response, javascriptText); string actualResult = rawResult.ToString(); // Assert. Assert.AreEqual(expectedResult, actualResult); }
public BodyTypeAdapterFactory(IRunnerVariablesProvider variablesProvider, Config config) { this.variablesProvider = variablesProvider; this.config = config; }
public void SetupVariablesProvider() { VariablesProvider = Mock.Of <IRunnerVariablesProvider>(varProv => varProv.CreateRunnerVariables() == new FitVariables()); }
public PartsFactory(IRunnerVariablesProvider variablesProvider, Support.Config config) { this.bodyTypeAdapterFactory = new BodyTypeAdapterFactory(variablesProvider, config); }
/// <summary> /// def ctor /// </summary> /// <param name="variablesProvider"> used for substitutions </param> /// <param name="config"> the config </param> public JSONBodyTypeAdapter(IRunnerVariablesProvider variablesProvider, Config config) { wrapper = new JavascriptWrapper(variablesProvider); imports = config.getAsMap("restfixture.javascript.imports.map", new Dictionary <string, string>()); }
public JavascriptWrapper(IRunnerVariablesProvider variablesProvider) { this.variablesProvider = variablesProvider; }
public virtual string handle(IRunnerVariablesProvider variablesProvider, Config cOnfig, RestResponse response, object expressionContext, string expression) { return(expression); }