예제 #1
0
 static AttackMachine()
 {
     AddRule(
         (x, y) => true,
         (x, y) => (x.Attack, AttackMachineState.STRAIGHT_DEFENCE),
         AttackMachineState.STRAIGHT_ATTACK
         );
     AddRule(
         (x, y) => true,
         (x, y) => (x.Defence, AttackMachineState.STRAIGHT_DEALING),
         AttackMachineState.STRAIGHT_DEFENCE
         );
     AddRule(
         (x, y) => true,
         (x, y) => (1, y.First().IsResponded&& y.First().IsStackAlive ? AttackMachineState.END : AttackMachineState.RESPONSE_ATTACK),
         AttackMachineState.STRAIGHT_DEALING
         );
     AddRule(
         (x, y) => true,
         (x, y) => (y.First().Attack, AttackMachineState.RESPONSE_DEFENCE),
         AttackMachineState.RESPONSE_ATTACK
         );
     AddRule(
         (x, y) => true,
         (x, y) => (y.First().Defence, AttackMachineState.RESPONSE_DEALING),
         AttackMachineState.RESPONSE_DEFENCE
         );
     AddRule(
         (x, y) => true,
         (x, y) => (1, AttackMachineState.END),
         AttackMachineState.RESPONSE_DEALING
         );
 }
예제 #2
0
        public void AddSingleStringWithNumberCasts()
        {
            var rule = new AddRule("3.14");

            var actual = rule.Apply();

            JsonAssert.AreEquivalent(3.14, actual);
        }
예제 #3
0
        public void AddSingleNumberDoesNothing()
        {
            var rule = new AddRule(3.14);

            var actual = rule.Apply();

            JsonAssert.AreEquivalent(3.14, actual);
        }
예제 #4
0
        public void AddNumbersReturnsSum()
        {
            var rule = new AddRule(4, 5);

            var actual = rule.Apply();

            JsonAssert.AreEquivalent(9, actual);
        }
예제 #5
0
        public void AddRule()
        {
            string expected = File.ReadAllText(Path.Combine(_requestsTestDataPath, "AddRule.xml"));
            var    request  = new AddRule
            {
                SessionId    = "sid",
                Who          = "*****@*****.**",
                RuleSettings = new TRuleSettings
                {
                    Title      = "Test",
                    Active     = true,
                    RuleID     = 1,
                    Conditions = new TRuleConditions
                    {
                        Items = new List <TRuleCondition>
                        {
                            new TRuleSomeWordsCondition
                            {
                                ConditionType = TRuleConditionType.CustomHeader,
                                OperatorAnd   = true,
                                MatchFunction = TRuleSomeWordsFunctionType.Regex,
                                MatchValue    = "X-Priority: 2"
                            }
                        }
                    },
                    Actions = new TRuleActions
                    {
                        Items = new List <TRuleAction>
                        {
                            new TRuleMessageActionAction
                            {
                                Actiontype        = TRuleActionType.MessageAction,
                                MessageActionType = TRuleMessageActionType.Reject
                            },
                            new TRulePriorityAction
                            {
                                Actiontype = TRuleActionType.Priority,
                                Priority   = TRulePriorityType.Highest
                            }
                        }
                    }
                }
            };
            var xml = request.ToXml().InnerXmlFormatted();

            Assert.AreEqual(expected, xml);

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(File.ReadAllText(Path.Combine(_responsesTestDataPath, "AddRule.xml")));
            var response = request.FromHttpRequestResult(new HttpRequestResult {
                Response = doc.InnerXml
            });

            Assert.AreEqual("result", response.Type);
            Assert.True(response.Success);
        }
예제 #6
0
        private void AddRuleItem_Click(object sender, EventArgs e)
        {
            Form ar = Application.OpenForms["AddRule"];

            if (ar != null)
            {
                ar.Activate();
                return;
            }
            else
            {
                AddRule addRuleForm = new AddRule(rulesGrid);
                addRuleForm.ShowDialog();
            }
            rulesUpdater.UpdateRules();
        }
예제 #7
0
        public void AddSingleNullThrowsError()
        {
            var rule = new AddRule(JsonDocument.Parse("null").RootElement);

            Assert.Throws <JsonLogicException>(() => rule.Apply());
        }
예제 #8
0
        public void AddSingleFalseThrowsError()
        {
            var rule = new AddRule(false);

            JsonAssert.AreEquivalent(0, rule.Apply());
        }
예제 #9
0
        public void AddSingleTrueThrowsError()
        {
            var rule = new AddRule(true);

            JsonAssert.AreEquivalent(1, rule.Apply());
        }
예제 #10
0
        public void AddSingleObjectThrowsError()
        {
            var rule = new AddRule(JsonDocument.Parse(JsonSerializer.Serialize(new { foo = 5 })).RootElement);

            Assert.Throws <JsonLogicException>(() => rule.Apply());
        }
예제 #11
0
        public void AddSingleArrayThrowsError()
        {
            var rule = new AddRule(new[] { false.AsJsonElement(), 5.AsJsonElement() }.AsJsonElement());

            Assert.Throws <JsonLogicException>(() => rule.Apply());
        }
예제 #12
0
        public void AddSingleStringWithJunkThrowsError()
        {
            var rule = new AddRule("foo");

            Assert.Throws <JsonLogicException>(() => rule.Apply());
        }
예제 #13
0
        public void AddNonNumberThrowsError()
        {
            var rule = new AddRule("test", 5);

            Assert.Throws <JsonLogicException>(() => rule.Apply());
        }