示例#1
0
        public void ErrorMessage_should_be_equal_to_given_message()
        {
            string message            = "Empty value is not allowed";
            MandatoryRule <int?> rule = new MandatoryRule <int?>(message);

            rule.Message.Should().BeEquivalentTo(message);
        }
        private BaseRule CreateRule(string ruleName)
        {
            BaseRule baseRule = null;

            switch (ruleName)
            {
            case "DataType":
            {
                baseRule = new DataTypeRule();
                break;
            }

            case "Required":
            {
                baseRule = new MandatoryRule();
                break;
            }

            case "DataPattern":
            {
                baseRule = new DataPatternRule();
                break;
            }

            case "MaxLength":
            {
                baseRule = new DataLengthRule();
                break;
            }

            case "Reference":
            {
                baseRule = new ReferenceRule();
                break;
            }

            case "Hierarchy":
            {
                baseRule = new HierarchyRule();
                break;
            }

            case "DelimitedHierarchy":
            {
                baseRule = new DelimitedHierarchyRule();
                break;
            }

            case "List":
            {
                baseRule = new ListConstraintRule();
                break;
            }
            }
            return(baseRule);
        }
示例#3
0
        //Adds new mandatory rule
        private void AddMandatoryRule(MandatoryRule rule, int index)
        {
            // creates new labels
            Label ruleLabel  = new Label();
            Label ruleNumber = new Label();

            ruleLabel.Text     = rule.RuleText;
            ruleLabel.AutoSize = true;
            ruleNumber.Text    = (index + 1).ToString();

            AddMandatoryRuleRow(ruleNumber, ruleLabel);
        }
        // Adds a Mandatory Rule
        private void AddMandatoryRule(MandatoryRule rule, int index)
        {
            // creating new labels and buttons
            Button removeRuleButton = new Button();
            Label  ruleLabel        = new Label();
            Label  ruleNumber       = new Label();

            ruleLabel.Text        = rule.RuleText;
            ruleLabel.AutoSize    = true;
            removeRuleButton.Size = new Size(30, 25);
            removeRuleButton.Text = "x";
            ruleNumber.Text       = (index + 1).ToString();

            AddMandatoryRuleRow(ruleNumber, ruleLabel, removeRuleButton);
        }
        // Adds a rule to the mandatory rules
        private void BtnAddRule_Click(object sender, EventArgs e)
        {
            if (tbxRuleName.Text != "")
            {
                MandatoryRule NewRule = new MandatoryRule(); // create a new rule from the class

                NewRule.RuleText = tbxRuleName.Text;         // set the new ruleText from the textbox
                NewRule.ID       = _rules.AllRules.Count;    // the Id is the count of the rules.

                _rules.AllRules.Add(NewRule);                // adding the new rule to the list
                _server.UpdateMandatoryRules(_rules);


                tbxRuleName.Clear();
                Dispose(); // close form
            }
            else
            {
                MessageBox.Show("Please enter a valid rule");
            }
        }
示例#6
0
        public void Value_is_null_then_Valid_should_be_false()
        {
            MandatoryRule <string> rule = new MandatoryRule <string>(null);

            rule.Validate(null).Should().BeFalse("Value ist not null");
        }
示例#7
0
        public void Value_is_greater_than_zero_then_Valid_should_be_true()
        {
            MandatoryRule <int> rule = new MandatoryRule <int>(string.Empty);

            rule.Validate(42).Should().BeFalse("Numeric value ist not null");
        }
示例#8
0
        public void Value_is_a_nullable_int_then_Valid_should_be_false()
        {
            MandatoryRule <int?> rule = new MandatoryRule <int?>(string.Empty);

            rule.Validate(null).Should().BeFalse("Numeric value ist not null");
        }
示例#9
0
        public void Value_is_not_empty_then_Valid_should_be_true()
        {
            MandatoryRule <string> rule = new MandatoryRule <string>(string.Empty);

            rule.Validate("todo").Should().BeTrue("Value ist empty");
        }
示例#10
0
        public void Value_is_empty_then_Valid_should_be_false()
        {
            MandatoryRule <string> rule = new MandatoryRule <string>(string.Empty);

            rule.Validate(string.Empty).Should().BeFalse("Value ist not empty");
        }