Exemplo n.º 1
0
        public void IsReadOnly_ReturnsFalse_ForPublicSetProperty()
        {
            // Arrange
            var detailsProvider = new EmptyCompositeMetadataDetailsProvider();
            var provider        = new DefaultModelMetadataProvider(detailsProvider);

            var key   = ModelMetadataIdentity.ForType(typeof(TypeWithProperties));
            var cache = new DefaultMetadataDetails(key, new ModelAttributes(new object[0]));

            var metadata = new DefaultModelMetadata(provider, detailsProvider, cache);

            // Act
            var isReadOnly = metadata.Properties["PublicGetPublicSetProperty"].IsReadOnly;

            // Assert
            Assert.False(isReadOnly);
        }
        public void ValidateChildren_ComplexAndEnumerableTypes(Type modelType)
        {
            // Arrange
            var detailsProvider = new EmptyCompositeMetadataDetailsProvider();
            var provider        = new DefaultModelMetadataProvider(detailsProvider);

            var key   = ModelMetadataIdentity.ForType(typeof(TypeWithProperties));
            var cache = new DefaultMetadataDetails(key, new ModelAttributes(new object[0]));

            var metadata = new DefaultModelMetadata(provider, detailsProvider, cache);

            // Act
            var validateChildren = metadata.ValidateChildren;

            // Assert
            Assert.True(validateChildren);
        }
Exemplo n.º 3
0
        public void IsReadOnly_ReturnsFalse_ForType()
        {
            // Arrange
            var detailsProvider = new EmptyCompositeMetadataDetailsProvider();
            var provider        = new DefaultModelMetadataProvider(detailsProvider);

            var key   = ModelMetadataIdentity.ForType(typeof(int[]));
            var cache = new DefaultMetadataDetails(key, new ModelAttributes(new object[0]));

            cache.BindingMetadata = new BindingMetadata()
            {
                IsReadOnly = true, // Will be ignored.
            };

            var metadata = new DefaultModelMetadata(provider, detailsProvider, cache);

            // Act
            var isReadOnly = metadata.IsReadOnly;

            // Assert
            Assert.False(isReadOnly);
        }
        public void ValidateChildren_OverrideFalse()
        {
            // Arrange
            var detailsProvider = new EmptyCompositeMetadataDetailsProvider();
            var provider        = new DefaultModelMetadataProvider(detailsProvider);

            var key   = ModelMetadataIdentity.ForType(typeof(XmlDocument));
            var cache = new DefaultMetadataDetails(key, new ModelAttributes(new object[0]));

            cache.ValidationMetadata = new ValidationMetadata()
            {
                ValidateChildren = false,
            };

            var metadata = new DefaultModelMetadata(provider, detailsProvider, cache);

            // Act
            var validateChildren = metadata.ValidateChildren;

            // Assert
            Assert.False(validateChildren);
        }