Beispiel #1
0
        public override bool IsPropertyValid(string propertyName, object value,
                                             bool forceValidation = false)
        {
            // check if we want to force the validation of the entity
            if (forceValidation)
            {
                Invalidate();
                return(HasValidationErrors);
            }

            // check if there is an invalid property for this particular
            // property
            var results = DataErrorInfoHelper.GetValidationResults(propertyName);

            if (results == null ||
                results.Count == 0)
            {
                ClearValidationError(propertyName);
                return(true);
            }
            foreach (var result in results)
            {
                SetValidationError(result);
            }
            return(false);
        }
        public void MessageForValidPropertyIsEmptyString()
        {
            var instance = new ValidatedClass { ValidatedIntProperty = 17 };
            var helper = new DataErrorInfoHelper(instance);

            var message = helper["ValidatedIntProperty"];

            Assert.AreEqual("", message);
        }
        public void MessageForNonExistingPropertyIsEmptyString()
        {
            var instance = new ValidatedClass();
            var helper = new DataErrorInfoHelper(instance);

            var message = helper["NonExisting"];

            Assert.AreEqual("", message);
        }
        public void MessageForEntireObjectIsEmpty()
        {
            var instance = new ValidatedClass();
            var helper = new DataErrorInfoHelper(instance);

            var message = helper.Error;

            Assert.AreEqual("", message);
        }
        public void MessageForNonValidatedPropertyIsEmptyString()
        {
            var instance = new ValidatedClass();
            var helper   = new DataErrorInfoHelper(instance);

            var message = helper["IntProperty"];

            Assert.AreEqual("", message);
        }
        public void MessageForEntireObjectIsEmpty()
        {
            var instance = new ValidatedClass();
            var helper   = new DataErrorInfoHelper(instance);

            var message = helper.Error;

            Assert.AreEqual("", message);
        }
        public void MessageForInvalidPropertyAccordingToOneRuleContainsTheMessageInTheRule()
        {
            var instance = new ValidatedClass { ValidatedIntProperty = 10 };
            var helper = new DataErrorInfoHelper(instance);

            var message = helper["ValidatedIntProperty"];

            Assert.IsFalse(message.Contains("invalid1"));
            Assert.IsTrue(message.Contains("invalid2"));
        }
Beispiel #8
0
 public NewProductionBatchViewModel(Services.EveProfiteerRepository eveProfiteerRepository)
 {
     _eveProfiteerRepository = eveProfiteerRepository;
     DisplayName             = "New production batch";
     ProductionDate          = DateTime.UtcNow;
     Blueprints           = _eveProfiteerRepository.GetBlueprints().AsNoTracking().ToList();
     PropertyChanged     += OnPropertyChanged;
     Blueprint            = Blueprints.First();
     _dataErrorInfoHelper = new DataErrorInfoHelper(this);
     Runs = 1;
 }
        public void MessageForInvalidPropertyAccordingToMultipleRulesContainsTheMessageInTheRules()
        {
            var instance = new ValidatedClass {
                ValidatedIntProperty = 5
            };
            var helper = new DataErrorInfoHelper(instance);

            var message = helper["ValidatedIntProperty"];

            Assert.IsTrue(message.Contains("invalid1"));
            Assert.IsTrue(message.Contains("invalid2"));
        }
        public void MessageForInvalidPropertyAccordingToRuleInRulesetContainsTheMessageInTheRule()
        {
            var instance = new ValidatedClass {
                ValidatedIntProperty = 5
            };
            var helper = new DataErrorInfoHelper(instance, ValidationSpecificationSource.All, "ruleset");

            var message = helper["ValidatedIntProperty"];

            Assert.IsFalse(message.Contains("invalid1"));
            Assert.IsFalse(message.Contains("invalid2"));
            Assert.IsTrue(message.Contains("invalid-ruleset"));
        }
        public void MessageForInvalidPropertyAccordingToRuleInRulesetContainsTheMessageInTheRule()
        {
            var instance = new ValidatedClass { ValidatedIntProperty = 5 };
            var helper = new DataErrorInfoHelper(instance, ValidationSpecificationSource.All, "ruleset");

            var message = helper["ValidatedIntProperty"];

            Assert.IsFalse(message.Contains("invalid1"));
            Assert.IsFalse(message.Contains("invalid2"));
            Assert.IsTrue(message.Contains("invalid-ruleset"));
        }
Beispiel #12
0
 string IDataErrorInfo.this[string columnName]
 {
     get { return(DataErrorInfoHelper.ValidateProperty(columnName, this)); }
 }
Beispiel #13
0
 /// <summary>
 /// カラムを検証する
 /// </summary>
 /// <param name="columnName"></param>
 /// <returns>エラーの場合エラーを表す文字列。エラーがない場合null</returns>
 protected virtual string ValidateProperty(string columnName)
 {
     return(DataErrorInfoHelper.ValidateProperty(columnName, this));
 }