예제 #1
0
        public void TestNew()
        {
            DeliveryRule dr = new DeliveryRule();

            Assert.IsNotNull(dr.TargetEndpoints);
            Assert.IsNotNull(dr.ValidationFailures);
        }
예제 #2
0
        public IActionResult AddRule(DeliveryRule dr)
        {
            dr.Initialize();

            Router.Instance.DeliveryRules.Add(dr);

            return(new JsonResult(""));
        }
예제 #3
0
 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()
     });
 }
예제 #4
0
        public IActionResult removeRule(DeliveryRule dr)
        {
            Router.Instance.DeliveryRules.Remove(Router.Instance.DeliveryRules.Find((rule) =>
            {
                return(dr.Name == rule.Name);
            }));

            return(new JsonResult(""));
        }
예제 #5
0
        public void TestInitalizationFailureRequiredFields()
        {
            DeliveryRule dr = new DeliveryRule();

            Assert.Throws <Exception>(() => {
                dr.Initialize();
            });

            Assert.AreEqual(3, dr.ValidationFailures.Count);
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
        }
예제 #8
0
        //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);
        }
예제 #9
0
        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);
        }
예제 #10
0
        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);
        }
예제 #11
0
        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);
        }
예제 #12
0
        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;
            }
        }