Пример #1
0
        public void ValidateObject_ModelWithComplexProperties_SomeValid()
        {
            var model = new ModelWithComplexProperty
            {
                Property1   = "Value",
                SimpleModel = new SimpleModel {
                    Name = "Some Value"
                },
            };

            var editContext = Validate(model);
            var messages    = editContext.GetValidationMessages(() => model.Property1);

            Assert.Empty(messages);

            messages = editContext.GetValidationMessages(() => model.SimpleModel);
            Assert.Empty(messages);

            messages = editContext.GetValidationMessages(() => model.SimpleModel.Age);
            Assert.Single(messages);

            messages = editContext.GetValidationMessages(() => model.SimpleModel.Name);
            Assert.Empty(messages);

            Assert.Single(editContext.GetValidationMessages());
        }
Пример #2
0
        public void ValidateObject_NullComplexProperty()
        {
            var model = new ModelWithComplexProperty();

            var editContext = Validate(model);
            var messages    = editContext.GetValidationMessages(() => model.Property1);

            Assert.Single(messages);

            Assert.Single(editContext.GetValidationMessages());
        }
Пример #3
0
        public void ValidateField_ModelWithComplexProperty()
        {
            var model = new ModelWithComplexProperty
            {
                SimpleModel = new SimpleModel {
                    Age = 1
                },
            };
            var fieldIdentifier = FieldIdentifier.Create(() => model.SimpleModel.Name);

            var editContext = ValidateField(model, fieldIdentifier);
            var messages    = editContext.GetValidationMessages(fieldIdentifier);

            Assert.Single(messages);

            Assert.Single(editContext.GetValidationMessages());
        }
Пример #4
0
        public void ValidateObject_ModelWithComplexProperties()
        {
            var model = new ModelWithComplexProperty {
                SimpleModel = new SimpleModel()
            };

            var editContext = Validate(model);
            var messages    = editContext.GetValidationMessages(() => model.Property1);

            Assert.Single(messages);

            messages = editContext.GetValidationMessages(() => model.SimpleModel);
            Assert.Empty(messages);

            messages = editContext.GetValidationMessages(() => model.SimpleModel.Age);
            Assert.Single(messages);

            messages = editContext.GetValidationMessages(() => model.SimpleModel.Name);
            Assert.Single(messages);

            Assert.Equal(3, editContext.GetValidationMessages().Count());
        }
Пример #5
0
        public void ValidateField_ModelWithComplexProperty_AfterSubmitValidation()
        {
            var model = new ModelWithComplexProperty
            {
                Property1   = "test",
                SimpleModel = new SimpleModel {
                    Age = 29, Name = "Test"
                },
            };
            var fieldIdentifier = FieldIdentifier.Create(() => model.SimpleModel.Age);

            var editContext = Validate(model);
            var messages    = editContext.GetValidationMessages(fieldIdentifier);

            Assert.Single(messages);

            model.SimpleModel.Age = 9;
            editContext.NotifyFieldChanged(fieldIdentifier);

            messages = editContext.GetValidationMessages(fieldIdentifier);
            Assert.Empty(messages);
            Assert.Empty(editContext.GetValidationMessages());
        }