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 ); }
public void AddSingleStringWithNumberCasts() { var rule = new AddRule("3.14"); var actual = rule.Apply(); JsonAssert.AreEquivalent(3.14, actual); }
public void AddSingleNumberDoesNothing() { var rule = new AddRule(3.14); var actual = rule.Apply(); JsonAssert.AreEquivalent(3.14, actual); }
public void AddNumbersReturnsSum() { var rule = new AddRule(4, 5); var actual = rule.Apply(); JsonAssert.AreEquivalent(9, actual); }
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); }
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(); }
public void AddSingleNullThrowsError() { var rule = new AddRule(JsonDocument.Parse("null").RootElement); Assert.Throws <JsonLogicException>(() => rule.Apply()); }
public void AddSingleFalseThrowsError() { var rule = new AddRule(false); JsonAssert.AreEquivalent(0, rule.Apply()); }
public void AddSingleTrueThrowsError() { var rule = new AddRule(true); JsonAssert.AreEquivalent(1, rule.Apply()); }
public void AddSingleObjectThrowsError() { var rule = new AddRule(JsonDocument.Parse(JsonSerializer.Serialize(new { foo = 5 })).RootElement); Assert.Throws <JsonLogicException>(() => rule.Apply()); }
public void AddSingleArrayThrowsError() { var rule = new AddRule(new[] { false.AsJsonElement(), 5.AsJsonElement() }.AsJsonElement()); Assert.Throws <JsonLogicException>(() => rule.Apply()); }
public void AddSingleStringWithJunkThrowsError() { var rule = new AddRule("foo"); Assert.Throws <JsonLogicException>(() => rule.Apply()); }
public void AddNonNumberThrowsError() { var rule = new AddRule("test", 5); Assert.Throws <JsonLogicException>(() => rule.Apply()); }