Exemplo n.º 1
0
        public void ModelValue_set_should_reset_properties()
        {
            // Arrange
            var model = new NestedClass
                            {
                                Id = 1,
                                Name = "Van Thoai Nguyen"
                            };
            // Action
            var metaData = new ModelMetadata(ModelMetadataProviders.Current,
                                             null,
                                             () => model,
                                             typeof(NestedClass),
                                             null);

            // Assert
            Assert.AreEqual(1, metaData.Properties.ToList()[0].ModelValue);
            metaData.ModelValue = new NestedClass
            {
                Id = 2,
                Name = "Van Thoai Nguyen 2"
            };
            Assert.AreEqual(2, metaData.Properties.ToList()[0].ModelValue);
        }
Exemplo n.º 2
0
        public void Validate_does_not_validate_require_rule_by_default()
        {
            // Arrange
            var model = new NestedClass
            {
                Name = null
            };

            // Action
            var metaData = new ModelMetadata(ModelMetadataProviders.Current,
                                             null,
                                             () => model,
                                             typeof(NestedClass),
                                             null);

            var validator = ModelValidator.GetModelValidator(metaData);
            var result = validator.Validate(model).ToList();

            // Assert
            Assert.AreEqual(0, result.Count());
        }
Exemplo n.º 3
0
        public void Validate_can_validate_stringlength_rule()
        {
            // Arrange
            var model = new NestedClass
            {
                Name = "Van Thoai Nguyen"
            };

            // Action
            var metaData = new ModelMetadata(ModelMetadataProviders.Current,
                                             null,
                                             () => model,
                                             typeof(NestedClass),
                                             null);

            var validator = ModelValidator.GetModelValidator(metaData);
            var result = validator.Validate(model).ToList();

            // Assert
            Assert.AreEqual(1, result.Count());
            Assert.AreEqual("NestedClass.Name", result[0].MemberName);
            Assert.AreEqual("The field Name must be a string with a maximum length of 5.", result[0].Message);
        }