/// <summary> /// constructor /// </summary> /// <param name="workingArguments"></param> public ArgumentProvider(WorkingArguments workingArguments) { if (workingArguments != null) { WorkingArguments = workingArguments; } }
public void TestChangeArguments() { var arguments = new WorkingArguments(); Assert.IsTrue(arguments.Inserted); Assert.IsFalse(arguments.Updated); arguments.AcceptChanges(); arguments.PrivateArguments.Add("now", $"{DateTime.UtcNow}"); Assert.IsFalse(arguments.Inserted); Assert.IsTrue(arguments.Updated); }
public void TestEventBody() { WorkingArguments workingArguments = new WorkingArguments(); ArgumentProvider argProvider = new ArgumentProvider(workingArguments); argProvider.PutPrivate("lastCheckResult", "{\"data\":null,\"success\":false,\"code\":null,\"message\":\"Cannot get any products by style number: [20200122].\",\"exception\":null}"); argProvider.PutPrivate("now", "2019/12/11T09:00:00.000Z"); argProvider.PutPrivate("input.merchantOrderId", "merchantOrderId"); var targetStr = "{\"message\":\"{\\\"name\\\":\\\"InvalidOrder\\\",\\\"time\\\":\\\"2019/12/11T09:00:00.000Z\\\",\\\"data\\\":{\\\"orderId\\\":\\\"merchantOrderId\\\",\\\"messages\\\":{\\\"data\\\":null,\\\"success\\\":false,\\\"code\\\":null,\\\"message\\\":\\\"Cannot get any products by style number: [20200122].\\\",\\\"exception\\\":null}}}\"}"; var setProcessor = new SetValueProcessor(); var setSetting1 = new SetValueActionSetting { Set = new Dictionary <string, string> { { "orderId", "{{input.merchantOrderId}}" }, { "messages", "{{lastCheckResult}}" } } }; var res1 = setProcessor.Execute(JsonConvert.SerializeObject(setSetting1), argProvider).Result; argProvider.PutPrivate("event_msg_data", res1.Data); var setSetting2 = new SetValueActionSetting { Set = new Dictionary <string, string> { { "name", "InvalidOrder" }, { "time", "{{now}}" }, { "data", "{{event_msg_data}}" } } }; var res2 = setProcessor.Execute(JsonConvert.SerializeObject(setSetting2), argProvider).Result; argProvider.PutPrivate("event_msg", res2.Data); var setSetting3 = new SetValueActionSetting { Set = new Dictionary <string, string> { { "message", "{{event_msg}}" } }, AsString = true }; var res3 = setProcessor.Execute(JsonConvert.SerializeObject(setSetting3), argProvider).Result; argProvider.PutPrivate("event_body", res3.Data); var resultStr = argProvider.Format("{{event_body}}"); Assert.AreEqual(targetStr, resultStr); }
public void TestSetValueOfObject() { WorkingArguments workingArguments = new WorkingArguments(); ArgumentProvider argProvider = new ArgumentProvider(workingArguments); argProvider.PutPrivate("lastCheckResult", "{\"data\":null,\"success\":false,\"code\":null,\"message\":\"Cannot get any products by style number: [20200122].\",\"exception\":null}"); argProvider.PutPrivate("data", "{\"data\":null}"); var targetStr = "{\"lastCheckResult\":\"{\\\"data\\\":{\\\"data\\\":null},\\\"success\\\":false,\\\"code\\\":null,\\\"message\\\":\\\"Cannot get any products by style number: [20200122].\\\",\\\"exception\\\":null}\"}"; var processor = new SetValueProcessor(); var setting = new SetValueActionSetting { Set = new Dictionary <string, string> { { "lastCheckResult.data", "{{data}}" } } }; var res = processor.Execute(JsonConvert.SerializeObject(setting), argProvider).Result; Assert.AreEqual(targetStr, res.Data); }
public void TestGroupListProcessor() { var processor = new GroupListProcessor(); var setting = new GroupListActionSetting { Source = "{{data.items}}", Key = "{{loopItem.type}}", Output = new Dictionary <string, string> { { "key", "{{groupKey}}" }, { "items", "{{groupItems}}" } } }; var data = new { key = "data-key", items = new List <dynamic> { new { id = "1", type = "a" }, new { id = "2", type = "a" }, new { id = "3", type = "b" }, new { id = "4", type = "b" }, } }; var workingArgument = new WorkingArguments(publicArguments: new Dictionary <string, string> { { "data", JsonConvert.SerializeObject(data) } }); var argumentProvider = new ArgumentProvider(workingArgument); var result = processor.Execute(JsonConvert.SerializeObject(setting), argumentProvider).Result; Assert.IsNotNull(result); Assert.IsTrue(result.Success); Assert.IsFalse(result.Fail); Assert.IsTrue(string.IsNullOrEmpty(result.Message)); Assert.IsFalse(string.IsNullOrEmpty(result.Data)); Assert.AreEqual(1, result.Output.Count); Assert.IsTrue(result.Output.ContainsKey("result")); var resultObj = JsonConvert.DeserializeObject <JArray>(result.Output["result"]); Assert.IsNotNull(resultObj); Assert.AreEqual(2, resultObj.Count); Assert.IsNotNull(resultObj[0]); var obj1 = JsonConvert.DeserializeObject <dynamic>(JsonConvert.SerializeObject(resultObj[0])); Assert.IsNotNull(obj1); Assert.IsNotNull(obj1.key); Assert.IsNotNull(obj1.items); Assert.AreEqual("a", obj1.key.ToString()); List <dynamic> items1 = JsonConvert.DeserializeObject <List <dynamic> >(obj1.items.ToString()); Assert.AreEqual(2, items1.Count); Assert.IsTrue(items1?.Any(x => x.id == "1")); Assert.IsTrue(items1?.Any(x => x.id == "2")); Assert.IsNotNull(resultObj[1]); var obj2 = JsonConvert.DeserializeObject <dynamic>(JsonConvert.SerializeObject(resultObj[1])); Assert.IsNotNull(obj2); Assert.IsNotNull(obj2.key); Assert.IsNotNull(obj2.items); Assert.AreEqual("b", obj2.key.ToString()); List <dynamic> items2 = JsonConvert.DeserializeObject <List <dynamic> >(obj2.items.ToString()); Assert.AreEqual(2, items2.Count); Assert.IsTrue(items2?.Any(x => x.id == "3")); Assert.IsTrue(items2?.Any(x => x.id == "4")); }