public void TestNew() { DeliveryRule dr = new DeliveryRule(); Assert.IsNotNull(dr.TargetEndpoints); Assert.IsNotNull(dr.ValidationFailures); }
public IActionResult AddRule(DeliveryRule dr) { dr.Initialize(); Router.Instance.DeliveryRules.Add(dr); return(new JsonResult("")); }
public static PSDeliveryRule ToPsDeliveryRule(this DeliveryRule deliveryRule) { return(new PSDeliveryRule { Order = deliveryRule.Order, Actions = deliveryRule.Actions.Select(action => action.ToPsDeliveryRuleAction()).ToList(), Conditions = deliveryRule.Conditions.Select(condition => condition.ToPsDeliveryRuleCondition()).ToList() }); }
public IActionResult removeRule(DeliveryRule dr) { Router.Instance.DeliveryRules.Remove(Router.Instance.DeliveryRules.Find((rule) => { return(dr.Name == rule.Name); })); return(new JsonResult("")); }
public void TestInitalizationFailureRequiredFields() { DeliveryRule dr = new DeliveryRule(); Assert.Throws <Exception>(() => { dr.Initialize(); }); Assert.AreEqual(3, dr.ValidationFailures.Count); }
public void TestValidationSuccess() { DeliveryRule dr = new DeliveryRule(); //the required field for the object. dr.Name = "my-delivery-test"; dr.TargetEndpoints.Add(new Uri("http://test.dev.42n.co")); dr.TypeExpression = "/sample-delivery-rule/g"; Assert.IsTrue(dr.IsValid); }
public static bool Deliver(Message msg, bool wait) { DeliveryRule dr = Router.IsMatch(msg); if (dr == null) { return(false); } return(DeliveryManager.Deliver(msg, dr, wait).Result); }
//Handles inspection of the Rules public static DeliveryRule IsMatch(Message msg) { DeliveryRule rule = Router.Instance.rules.Find((r) => { return(r.IsMatch(msg)); }); if (rule != null && !rule.Enabled) { rule = null; } return(rule); }
public void TestRuleMatch() { string rules = File.ReadAllText("tests/sample-data/valid-delivery-rules.json"); Router.LoadRules(rules); Message m = new Message(); m.Type = "valid-test-1"; DeliveryRule dr = Router.IsMatch(m); Assert.IsNotNull(dr); Assert.AreEqual("valid-test-delivery-1", dr.Name); }
public void TestInitalizationFailureRulesExpressionError() { DeliveryRule dr = new DeliveryRule(); //the required field for the object. dr.Name = "my-name"; dr.TargetEndpoints.Add(new Uri("http://test.dev.42n.co")); dr.TypeExpression = @"\b[a\t]\w+\\\"; Assert.Throws <Exception>(() => { dr.Initialize(); }); Assert.AreEqual(1, dr.ValidationFailures.Count); }
public void TestMessageMatchSuccess() { DeliveryRule dr = new DeliveryRule(); Message m = new Message(); m.Type = "my-name-2"; m.Payload = new ExpandoObject(); //the required field for the object. dr.Name = "my-rule"; dr.TargetEndpoints.Add(new Uri("http://test.dev.42n.co")); dr.TypeExpression = @"^my-name-2"; dr.Initialize(); bool result = dr.IsMatch(m); Assert.IsTrue(result); }
public static async Task <dynamic> DeliverAsync(Message msg) { DeliveryRule dr = Router.IsMatch(msg); try { await Router.Instance.deliverySemaphore.WaitAsync().ConfigureAwait(false); return(DeliveryManager.DeliverAsync(msg, dr).ContinueWith((result) => { Router.Instance.deliverySemaphore.Release(); }).ConfigureAwait(false)); } catch (Exception ex) { Router.Instance.deliverySemaphore.Release(); throw ex; } }