Exemplo n.º 1
0
        public void GetMetadataForProperties_WithoutBindAttribute()
        {
            // Arrange
            string[] expectedPropertyNames = new[]
            {
                "DateOfBirth",
                "DateOfDeath",
                "ValueTypeRequired",
                "FirstName",
                "LastName",
                "PropertyWithDefaultValue"
            };

            ExtensibleModelBindingContext bindingContext = new ExtensibleModelBindingContext
            {
                ModelMetadata = GetMetadataForType(typeof(Person))
            };

            TestableMutableObjectModelBinder testableBinder =
                new TestableMutableObjectModelBinder();

            // Act
            IEnumerable <ModelMetadata> propertyMetadatas =
                testableBinder.GetMetadataForPropertiesPublic(null, bindingContext);

            string[] returnedPropertyNames = propertyMetadatas
                                             .Select(o => o.PropertyName)
                                             .ToArray();

            // Assert
            Assert.Equal(expectedPropertyNames, returnedPropertyNames);
        }
        public void GetMetadataForProperties_WithBindAttribute()
        {
            // Arrange
            string[] expectedPropertyNames = new[] { "FirstName", "LastName" };

            HttpActionContext   actionContext  = ContextUtil.CreateActionContext();
            ModelBindingContext bindingContext = new ModelBindingContext
            {
                ModelMetadata = GetMetadataForType(typeof(PersonWithBindExclusion))
            };

            TestableMutableObjectModelBinder testableBinder =
                new TestableMutableObjectModelBinder();

            // Act
            IEnumerable <ModelMetadata> propertyMetadatas =
                testableBinder.GetMetadataForPropertiesPublic(actionContext, bindingContext);

            string[] returnedPropertyNames = propertyMetadatas
                                             .Select(o => o.PropertyName)
                                             .ToArray();

            // Assert
            Assert.Equal(expectedPropertyNames, returnedPropertyNames);
        }
Exemplo n.º 3
0
        public void GetMetadataForProperties_WithoutBindAttribute()
        {
            // Arrange
            var expectedPropertyNames = new[] { "DateOfBirth", "DateOfDeath", "ValueTypeRequired", "FirstName", "LastName", "PropertyWithDefaultValue" };
            var bindingContext        = new ModelBindingContext
            {
                ModelMetadata      = GetMetadataForType(typeof(Person)),
                ValidatorProviders = Enumerable.Empty <IModelValidatorProvider>()
            };

            var testableBinder = new TestableMutableObjectModelBinder();

            // Act
            var propertyMetadatas     = testableBinder.GetMetadataForPropertiesPublic(bindingContext);
            var returnedPropertyNames = propertyMetadatas.Select(o => o.PropertyName).ToArray();

            // Assert
            Assert.Equal(expectedPropertyNames, returnedPropertyNames);
        }
Exemplo n.º 4
0
        public void GetMetadataForProperties_WithBindAttribute()
        {
            // Arrange
            var expectedPropertyNames = new[] { "FirstName", "LastName" };
            var bindingContext        = new ModelBindingContext
            {
                ModelMetadata     = GetMetadataForType(typeof(PersonWithBindExclusion)),
                ValidatorProvider = Mock.Of <IModelValidatorProvider>()
            };

            var testableBinder = new TestableMutableObjectModelBinder();

            // Act
            var propertyMetadatas     = testableBinder.GetMetadataForPropertiesPublic(bindingContext);
            var returnedPropertyNames = propertyMetadatas.Select(o => o.PropertyName).ToArray();

            // Assert
            Assert.Equal(expectedPropertyNames, returnedPropertyNames);
        }
Exemplo n.º 5
0
        public void GetMetadataForProperties_WithBindAttribute()
        {
            // Arrange
            string[] expectedPropertyNames = new string[] { "FirstName", "LastName" };

            ExtensibleModelBindingContext bindingContext = new ExtensibleModelBindingContext()
            {
                ModelMetadata = GetMetadataForType(typeof(PersonWithBindExclusion))
            };

            TestableMutableObjectModelBinder testableBinder = new TestableMutableObjectModelBinder();

            // Act
            IEnumerable <ModelMetadata> propertyMetadatas = testableBinder.GetMetadataForPropertiesPublic(null, bindingContext);

            string[] returnedPropertyNames = propertyMetadatas.Select(o => o.PropertyName).ToArray();

            // Assert
            CollectionAssert.AreEquivalent(expectedPropertyNames, returnedPropertyNames);
        }
Exemplo n.º 6
0
        public void GetMetadataForProperties_ReturnsOnlyWhiteListedProperties_UsingBindAttributeInclude()
        {
            // Arrange
            var expectedPropertyNames = new[] { "IncludedExplicitly1", "IncludedExplicitly2" };
            var bindingContext        = new ModelBindingContext
            {
                ModelMetadata     = GetMetadataForType(typeof(TypeWithIncludedPropertiesUsingBindAttribute)),
                ValidatorProvider = Mock.Of <IModelValidatorProvider>(),
                MetadataProvider  = new DataAnnotationsModelMetadataProvider()
            };

            var testableBinder = new TestableMutableObjectModelBinder();

            // Act
            var propertyMetadatas     = testableBinder.GetMetadataForPropertiesPublic(bindingContext);
            var returnedPropertyNames = propertyMetadatas.Select(o => o.PropertyName).ToArray();

            // Assert
            Assert.Equal(expectedPropertyNames, returnedPropertyNames);
        }
        public void GetMetadataForProperties_WithoutBindAttribute()
        {
            // Arrange
            string[] expectedPropertyNames = new[] { "DateOfBirth", "DateOfDeath", "ValueTypeRequired", "FirstName", "LastName", "PropertyWithDefaultValue" };

            HttpActionContext actionContext = ContextUtil.CreateActionContext();
            ModelBindingContext bindingContext = new ModelBindingContext
            {
                ModelMetadata = GetMetadataForType(typeof(Person))
            };

            TestableMutableObjectModelBinder testableBinder = new TestableMutableObjectModelBinder();

            // Act
            IEnumerable<ModelMetadata> propertyMetadatas = testableBinder.GetMetadataForPropertiesPublic(actionContext, bindingContext);
            string[] returnedPropertyNames = propertyMetadatas.Select(o => o.PropertyName).ToArray();

            // Assert
            Assert.Equal(expectedPropertyNames, returnedPropertyNames);
        }
        public void GetMetadataForProperties_WithBindAttribute()
        {
            // Arrange
            string[] expectedPropertyNames = new[] { "FirstName", "LastName" };

            ExtensibleModelBindingContext bindingContext = new ExtensibleModelBindingContext
            {
                ModelMetadata = GetMetadataForType(typeof(PersonWithBindExclusion))
            };

            TestableMutableObjectModelBinder testableBinder = new TestableMutableObjectModelBinder();

            // Act
            IEnumerable<ModelMetadata> propertyMetadatas = testableBinder.GetMetadataForPropertiesPublic(null, bindingContext);
            string[] returnedPropertyNames = propertyMetadatas.Select(o => o.PropertyName).ToArray();

            // Assert
            Assert.Equal(expectedPropertyNames, returnedPropertyNames);
        }
Exemplo n.º 9
0
        public void GetMetadataForProperties_WithoutBindAttribute() {
            // Arrange
            string[] expectedPropertyNames = new string[] { "DateOfBirth", "DateOfDeath", "FirstName", "LastName", "ValueTypeRequired", "PropertyWithDefaultValue" };

            ExtensibleModelBindingContext bindingContext = new ExtensibleModelBindingContext() {
                ModelMetadata = GetMetadataForType(typeof(Person))
            };

            TestableMutableObjectModelBinder testableBinder = new TestableMutableObjectModelBinder();

            // Act
            IEnumerable<ModelMetadata> propertyMetadatas = testableBinder.GetMetadataForPropertiesPublic(null, bindingContext);
            string[] returnedPropertyNames = propertyMetadatas.Select(o => o.PropertyName).ToArray();

            // Assert
            CollectionAssert.AreEquivalent(expectedPropertyNames, returnedPropertyNames);
        }
Exemplo n.º 10
0
        public void GetMetadataForProperties_WithoutBindAttribute()
        {
            // Arrange
            var expectedPropertyNames = new[] { "DateOfBirth", "DateOfDeath", "ValueTypeRequired", "FirstName", "LastName", "PropertyWithDefaultValue" };
            var bindingContext = new ModelBindingContext
            {
                ModelMetadata = GetMetadataForType(typeof(Person)),
                ValidatorProviders = Enumerable.Empty<IModelValidatorProvider>()
            };

            var testableBinder = new TestableMutableObjectModelBinder();

            // Act
            var propertyMetadatas = testableBinder.GetMetadataForPropertiesPublic(bindingContext);
            var returnedPropertyNames = propertyMetadatas.Select(o => o.PropertyName).ToArray();

            // Assert
            Assert.Equal(expectedPropertyNames, returnedPropertyNames);
        }