public void TestMapConstantString() { string payloadTemplate = @" { 'name' : 'name1' }"; XjsltTemplate template = GetProvider(payloadTemplate); string payloadSource = @"{ 'name' : 'name111' }"; StringBuilder sb2 = new StringBuilder(payloadSource.Replace('\'', '"')); var result = template.Transform(sb2); Assert.AreEqual(result.Item1["name"], "name1"); }
public void TestCompositeMapValue() { string payloadTemplate = @" { 'person': { 'name' : 'jpath:{$.person.identity.name}' } }"; XjsltTemplate template = GetProvider(payloadTemplate); string payloadSource = @"{ 'person': { 'identity': { 'name' : 'name111' } } }"; StringBuilder sb2 = new StringBuilder(payloadSource.Replace('\'', '"')); var result = template.Transform(sb2); Assert.AreEqual(result.Item1["person"]["name"], "name111"); }
public void TestEmptyTemplate() { string payloadTemplate = @""; XjsltTemplate template = GetProvider(payloadTemplate); string payloadSource = @"{ 'name' : 'name111' }"; StringBuilder sb2 = new StringBuilder(payloadSource.Replace('\'', '"')); var result = template.Transform(sb2); Assert.AreEqual(result.Item1.ToString(Newtonsoft.Json.Formatting.None), @"{""name"":""name111""}"); }
public void TestCompositeMapArray3() { string payloadTemplate = @"{ 'persons': [{'$source' : 'jpath:{$.persons[?(@.n == §name2§)]}', 'name' : 'jpath:{$.n}'}] }"; XjsltTemplate template = GetProvider(payloadTemplate); string payloadSource = @"{ 'persons': [{'n' : 'name1'}, {'n' : 'name2'}, {'n' : 'name3'}] }"; StringBuilder sb2 = new StringBuilder(payloadSource.Replace('\'', '"')); var result = template.Transform(sb2); Assert.AreEqual(result.Item1["persons"][0]["name"], "name2"); }
public void TestCompositeMapArrayIndiceLast2Value() { string payloadTemplate = @"{ 'person': { 'name' : 'jpath:{$.persons[-1:].name}' } }"; XjsltTemplate template = GetProvider(payloadTemplate); string payloadSource = @"{ 'persons': [{'name' : 'name1'}, {'name' : 'name2'}, {'name' : 'name3'}] }"; StringBuilder sb2 = new StringBuilder(payloadSource.Replace('\'', '"')); var result = template.Transform(sb2); Assert.AreEqual(result.Item1["person"]["name"], "name3"); }
public void TestCompositeExecuteCustomRuleOnType2() { string payloadTemplate = @"{ '$source':'data1', '$id':'jpath:{$.id}' }"; XjsltTemplate template = GetProvider(payloadTemplate, ("data1", new DataClass()) ); string payloadSource = @"{ 'Event':'e1', 'id':'FR345' }"; StringBuilder sb2 = new StringBuilder(payloadSource.Replace('\'', '"')); var result = template.Transform(sb2); Assert.AreEqual(result.Item1["Uuid"], "FR345"); }
public void TestCompositeExecuteCustomRule() { string payloadTemplate = @"{ 'prices': 'jpath:{$..n} | sum:{}' }"; XjsltTemplate template = GetProvider(payloadTemplate, ("sum", new ServiceSum()) ); string payloadSource = @"{ 'prices': [{'n' : 1}, {'n' : 2}, {'n' : 3}] }"; StringBuilder sb2 = new StringBuilder(payloadSource.Replace('\'', '"')); var result = template.Transform(sb2); Assert.AreEqual(result.Item1["prices"], 6); }
public XjsltTemplate GetTemplate(StringBuilder sb) { JObject obj = null; if (sb.Length > 0) { obj = JObject.Parse(sb.ToString()); } TranformJsonTemplateReader reader = new TranformJsonTemplateReader(obj, this._configuration); var tree = reader.Tree(); XjsltTemplate result = new XjsltTemplate() { Rule = sb, Configuration = this._configuration, Template = tree, Rules = reader.Get(tree) }; return(result); }