// Showcase imperative validation from config rules just before saving
        private void ValidateFromRuleset(Model.Expense expense)
        {
            var validator             = this.ValidatorFactory.CreateValidator <Model.Expense>("ExpenseRuleset");
            ValidationResults results = validator.Validate(expense);

            if (!results.IsValid)
            {
                throw new NotifyException(results.First().Message);
            }
        }
Пример #2
0
        private void ShowDataValidateErrorCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            IUserGroup userGroup = this.GetBinding <IUserGroup>("NewUserGroup");

            ValidationResults validationResults = ValidationFacade.Validate <IUserGroup>(userGroup);

            this.ShowFieldMessage(
                "NewUserGroup.Name",
                validationResults.First().Message);
        }
Пример #3
0
        private void ValidateData(object sender, ConditionalEventArgs e)
        {
            IUserGroup userGroup = this.GetBinding <IUserGroup>("UserGroup");

            ValidationResults validationResults = ValidationFacade.Validate <IUserGroup>(userGroup);

            e.Result = validationResults.IsValid;
            if (!validationResults.IsValid)
            {
                this.ShowFieldMessage(
                    "UserGroup.Name",
                    validationResults.First().Message);
            }
        }
Пример #4
0
        public virtual string this[string columnName]
        {
            get
            {
                string message         = null;
                var    filteredResults = new ValidationResults();

                var result = _validationResults.FirstOrDefault(x => x.Key == columnName);
                if (result != null)
                {
                    filteredResults.AddResult(result);
                    message = filteredResults.First().Message;
                }
                return(message);
            }
        }
Пример #5
0
        public void PropertyStringEmptyValidatorTest()
        {
            PropertyDefine pd = new PropertyDefine();

            pd.Name = "UserName";

            PropertyValidatorDescriptor pvd = new PropertyValidatorDescriptor();

            pvd.MessageTemplate = "属性UserName不能为空";
            pvd.TypeDescription = "MCS.Library.Validation.StringEmptyValidator, MCS.Library";

            pd.Validators.Add(pvd);

            PropertyValue pv = new PropertyValue(pd);

            ValidationResults results = new ValidationResults();

            pv.Validate(results);

            Console.WriteLine(results);

            Assert.AreEqual(1, results.ResultCount);
            Assert.AreEqual(pvd.MessageTemplate, results.First().Message);
        }
Пример #6
0
		public void PropertyStringEmptyValidatorTest()
		{
			PropertyDefine pd = new PropertyDefine();

			pd.Name = "UserName";

			PropertyValidatorDescriptor pvd = new PropertyValidatorDescriptor();

			pvd.MessageTemplate = "属性UserName不能为空";
			pvd.TypeDescription = "MCS.Library.Validation.StringEmptyValidator, MCS.Library";

			pd.Validators.Add(pvd);

			PropertyValue pv = new PropertyValue(pd);

			ValidationResults results = new ValidationResults();

			pv.Validate(results);

			Console.WriteLine(results);

			Assert.AreEqual(1, results.ResultCount);
			Assert.AreEqual(pvd.MessageTemplate, results.First().Message);
		}