public void BinderPropertyThrowsIfMultipleBinderAttributesFound()
        {
            // Arrange
            ParameterInfo pInfo = typeof(MyController).GetMethod("ParameterHasMultipleModelBinderAttributes").GetParameters()[0];
            ReflectedParameterBindingInfo bindingInfo = new ReflectedParameterBindingInfo(pInfo);

            // Act & assert
            Assert.Throws <InvalidOperationException>(
                delegate { IModelBinder binder = bindingInfo.Binder; },
                "The parameter 'p1' on method 'Void ParameterHasMultipleModelBinderAttributes(System.Object)' contains multiple attributes that inherit from CustomModelBinderAttribute.");
        }
        public void BinderPropertyThrowsIfMultipleBinderAttributesFound()
        {
            // Arrange
            ParameterInfo pInfo = typeof(MyController).GetMethod("ParameterHasMultipleModelBinderAttributes").GetParameters()[0];
            ReflectedParameterBindingInfo bindingInfo = new ReflectedParameterBindingInfo(pInfo);

            // Act & assert
            Assert.Throws<InvalidOperationException>(
                delegate { IModelBinder binder = bindingInfo.Binder; },
                "The parameter 'p1' on method 'Void ParameterHasMultipleModelBinderAttributes(System.Object)' contains multiple attributes that inherit from CustomModelBinderAttribute.");
        }
        public void BinderProperty()
        {
            // Arrange
            ParameterInfo pInfo = typeof(MyController).GetMethod("ParameterHasSingleModelBinderAttribute").GetParameters()[0];
            ReflectedParameterBindingInfo bindingInfo = new ReflectedParameterBindingInfo(pInfo);

            // Act
            IModelBinder binder = bindingInfo.Binder;

            // Assert
            Assert.IsType<MyModelBinder>(binder);
        }
        public void PrefixPropertyReturnsNullIfNoBindAttributeSpecified()
        {
            // Arrange
            ParameterInfo pInfo = typeof(MyController).GetMethod("ParameterHasNoBindAttributes").GetParameters()[0];
            ReflectedParameterBindingInfo bindingInfo = new ReflectedParameterBindingInfo(pInfo);

            // Act
            string prefix = bindingInfo.Prefix;

            // Assert
            Assert.Null(prefix);
        }
        public void BinderProperty()
        {
            // Arrange
            ParameterInfo pInfo = typeof(MyController).GetMethod("ParameterHasSingleModelBinderAttribute").GetParameters()[0];
            ReflectedParameterBindingInfo bindingInfo = new ReflectedParameterBindingInfo(pInfo);

            // Act
            IModelBinder binder = bindingInfo.Binder;

            // Assert
            Assert.IsType <MyModelBinder>(binder);
        }
        public void PrefixProperty()
        {
            // Arrange
            ParameterInfo pInfo = typeof(MyController).GetMethod("ParameterHasBindAttribute").GetParameters()[0];
            ReflectedParameterBindingInfo bindingInfo = new ReflectedParameterBindingInfo(pInfo);

            // Act
            string prefix = bindingInfo.Prefix;

            // Assert
            Assert.Equal("some prefix", prefix);
        }
        public void ExcludePropertyReturnsEmptyArrayIfNoBindAttributeSpecified()
        {
            // Arrange
            ParameterInfo pInfo = typeof(MyController).GetMethod("ParameterHasNoBindAttributes").GetParameters()[0];
            ReflectedParameterBindingInfo bindingInfo = new ReflectedParameterBindingInfo(pInfo);

            // Act
            ICollection<string> excludes = bindingInfo.Exclude;

            // Assert
            Assert.NotNull(excludes);
            Assert.Empty(excludes);
        }
        public void IncludePropertyReturnsEmptyArrayIfNoBindAttributeSpecified()
        {
            // Arrange
            ParameterInfo pInfo = typeof(MyController).GetMethod("ParameterHasNoBindAttributes").GetParameters()[0];
            ReflectedParameterBindingInfo bindingInfo = new ReflectedParameterBindingInfo(pInfo);

            // Act
            ICollection <string> includes = bindingInfo.Include;

            // Assert
            Assert.NotNull(includes);
            Assert.Empty(includes);
        }
        public void IncludeProperty()
        {
            // Arrange
            ParameterInfo pInfo = typeof(MyController).GetMethod("ParameterHasBindAttribute").GetParameters()[0];
            ReflectedParameterBindingInfo bindingInfo = new ReflectedParameterBindingInfo(pInfo);

            // Act
            ICollection<string> includes = bindingInfo.Include;

            // Assert
            Assert.IsType<ReadOnlyCollection<string>>(includes);

            string[] includesArray = includes.ToArray();
            Assert.Equal(2, includesArray.Length);
            Assert.Equal("incl_a", includesArray[0]);
            Assert.Equal("incl_b", includesArray[1]);
        }
        public void IncludeProperty()
        {
            // Arrange
            ParameterInfo pInfo = typeof(MyController).GetMethod("ParameterHasBindAttribute").GetParameters()[0];
            ReflectedParameterBindingInfo bindingInfo = new ReflectedParameterBindingInfo(pInfo);

            // Act
            ICollection <string> includes = bindingInfo.Include;

            // Assert
            Assert.IsType <ReadOnlyCollection <string> >(includes);

            string[] includesArray = includes.ToArray();
            Assert.Equal(2, includesArray.Length);
            Assert.Equal("incl_a", includesArray[0]);
            Assert.Equal("incl_b", includesArray[1]);
        }
Ejemplo n.º 11
0
        public void ExcludeProperty()
        {
            // Arrange
            ParameterInfo pInfo = typeof(MyController).GetMethod("ParameterHasBindAttribute").GetParameters()[0];
            ReflectedParameterBindingInfo bindingInfo = new ReflectedParameterBindingInfo(pInfo);

            // Act
            ICollection <string> excludes = bindingInfo.Exclude;

            // Assert
            Assert.IsInstanceOfType(excludes, typeof(ReadOnlyCollection <string>));

            string[] excludesArray = excludes.ToArray();
            Assert.AreEqual(2, excludesArray.Length);
            Assert.AreEqual("excl_a", excludesArray[0]);
            Assert.AreEqual("excl_b", excludesArray[1]);
        }
        public void PrefixPropertyReturnsNullIfNoBindAttributeSpecified()
        {
            // Arrange
            ParameterInfo pInfo = typeof(MyController).GetMethod("ParameterHasNoBindAttributes").GetParameters()[0];
            ReflectedParameterBindingInfo bindingInfo = new ReflectedParameterBindingInfo(pInfo);

            // Act
            string prefix = bindingInfo.Prefix;

            // Assert
            Assert.Null(prefix);
        }
        public void PrefixProperty()
        {
            // Arrange
            ParameterInfo pInfo = typeof(MyController).GetMethod("ParameterHasBindAttribute").GetParameters()[0];
            ReflectedParameterBindingInfo bindingInfo = new ReflectedParameterBindingInfo(pInfo);

            // Act
            string prefix = bindingInfo.Prefix;

            // Assert
            Assert.Equal("some prefix", prefix);
        }