コード例 #1
0
        public void WhenValidatingUsingDefaultRuleset_ThenShouldValidateWithDefaultRuleset()
        {
            Validator <BaseTestDomainObject> validator
                = validationFactory.CreateValidator <BaseTestDomainObject>();

            ValidationResults validationResults = validator.Validate(new BaseTestDomainObject());

            Assert.IsFalse(validationResults.IsValid);
            Assert.AreEqual(2, validationResults.Count);
            Assert.AreEqual("message-from-config1-RuleA", validationResults.ElementAt(0).Message);
            Assert.AreEqual("message-from-config2-RuleA", validationResults.ElementAt(1).Message);
        }
コード例 #2
0
        public void WhenValidatingUsingNonDefaultRuleset_ThenShouldProduceResultsOnlyFromSpecifiedRuleset()
        {
            Validator <BaseTestDomainObject> validator
                = validationFactory.CreateValidator <BaseTestDomainObject>("RuleB");

            ValidationResults validationResults = validator.Validate(new BaseTestDomainObject());

            Assert.IsFalse(validationResults.IsValid);
            Assert.AreEqual(1, validationResults.Count);
            Assert.AreEqual("message-from-config1-RuleB", validationResults.ElementAt(0).Message);
        }
コード例 #3
0
        static void Main(string[] args)
        {
            Validator <Customer> customerValidator = ValidationFactory.CreateValidator <Customer>("Validation Ruleset");
            Customer             myCustomer        = new Customer(null);
            ValidationResults    r = customerValidator.Validate(myCustomer);

            if (!r.IsValid)
            {
                for (int i = 0; i < r.Count; i++)
                {
                    Console.WriteLine("出错{0}:" + r.ElementAt(i).Message, i + 1);
                }
            }
            else
            {
                Console.WriteLine("正确");
            }
        }
コード例 #4
0
        public bool Validate(IDataValidatable validator)
        {
            ValidationResults vr = validator.Validate();

            if (vr.IsValid)
            {
                return(true);
            }

            string errorStr = "";

            for (int i = 0; i < vr.Count; i++)
            {
                errorStr += TranslationService.Translate(vr.ElementAt(i).Message) + "\n";
            }

            var vm = ServiceLocator.Current.GetInstance <IViewModelGetSelectedView>().GetSelectedView();

            ServiceLocator.Current.GetInstance <IViewModelErrorWindow>().ErrorWindow(vm, errorStr);

            return(false);
        }