Exemplo n.º 1
0
        protected ValidatableViewModel(IErrorsContainer <ValidationError> errorsContainer, ArrayFormat errorFormat = ArrayFormat.First)
        {
            ErrorsContainer = errorsContainer;
            ErrorsContainer.ErrorsChanged += OnErrorsChanged;

            dataErrorInfoProvider = new DataErrorInfoProvider(ErrorsContainer, errorFormat, ObjectErrorPropertyName);
        }
Exemplo n.º 2
0
        protected ValidatableViewModel(IMessenger messenger, ArrayFormat errorFormat = ArrayFormat.First)
            : base(messenger)
        {
            ErrorsContainer = new ErrorsContainer();
            ErrorsContainer.ErrorsChanged += OnErrorsChanged;

            dataErrorInfoProvider = new DataErrorInfoProvider(ErrorsContainer, errorFormat, ObjectErrorPropertyName);
        }
Exemplo n.º 3
0
        private void Initialize()
        {
            ErrorsContainer = new ErrorsContainer();
            ErrorsContainer.ErrorsChanged += OnErrorsChanged;

            dataErrorInfoProvider = new DataErrorInfoProvider(ErrorsContainer);

            validationOnPropertyChangedEnabled = true;
        }
        public void OnPropertyValidatedRecordsErrorIfPropertyImplementsIDataErrorInfoAndIsInvalid() {
            // Arrange
            DataErrorInfoProvider model = new DataErrorInfoProvider();
            model.Errors["readwriteproperty"] = "Some error message.";

            ModelBindingContext bindingContext = new ModelBindingContext() {
                Model = model,
                ModelName = "theModel"
            };

            PropertyDescriptor property = TypeDescriptor.GetProperties(typeof(MyModel))["ReadWriteProperty"];
            DefaultModelBinderHelper helper = new DefaultModelBinderHelper();

            // Act
            helper.PublicOnPropertyValidated(null, bindingContext, property, 42);

            // Assert
            Assert.AreEqual("Some error message.", bindingContext.ModelState["themodel.readwriteproperty"].Errors[0].ErrorMessage);
        }
        public void OnPropertyValidatedDoesNothingIfPropertyImplementsIDataErrorInfoAndIsValid() {
            // Arrange
            DataErrorInfoProvider model = new DataErrorInfoProvider();
            ModelBindingContext bindingContext = new ModelBindingContext() {
                Model = model,
                ModelName = "theModel"
            };

            PropertyDescriptor property = TypeDescriptor.GetProperties(typeof(MyModel))["ReadWriteProperty"];
            DefaultModelBinderHelper helper = new DefaultModelBinderHelper();

            // Act
            helper.PublicOnPropertyValidated(null, bindingContext, property, 42);

            // Assert
            Assert.IsTrue(bindingContext.ModelState.IsValidField("themodel.readwriteproperty"), "ModelState should not have been changed.");
        }
        public void OnModelUpdatedRecordsErrorIfModelImplementsIDataErrorInfoAndIsInvalid() {
            // Arrange
            DataErrorInfoProvider model = new DataErrorInfoProvider() { ErrorText = "Some error message." };

            ModelBindingContext bindingContext = new ModelBindingContext() {
                Model = model,
                ModelName = "theModel"
            };

            DefaultModelBinderHelper helper = new DefaultModelBinderHelper();

            // Act
            helper.PublicOnModelUpdated(null, bindingContext);

            // Assert
            Assert.AreEqual("Some error message.", bindingContext.ModelState["themodel"].Errors[0].ErrorMessage);
        }
        public void OnModelUpdatedDoesNothingIfModelImplementsIDataErrorInfoAndIsValid() {
            // Arrange
            DataErrorInfoProvider model = new DataErrorInfoProvider();
            ModelBindingContext bindingContext = new ModelBindingContext() {
                Model = model,
                ModelName = "theModel"
            };

            DefaultModelBinderHelper helper = new DefaultModelBinderHelper();

            // Act
            helper.PublicOnModelUpdated(null, bindingContext);

            // Assert
            Assert.IsTrue(bindingContext.ModelState.IsValidField("themodel"), "ModelState should not have been changed.");
        }