コード例 #1
0
        public void BinderTypeProperty() {
            // Arrange
            Type binderType = typeof(GoodConverter);
            ModelBinderAttribute attr = new ModelBinderAttribute(binderType);

            // Act & Assert
            Assert.AreSame(binderType, attr.BinderType);
        }
コード例 #2
0
        public void GetBinder() {
            // Arrange
            Type binderType = typeof(GoodConverter);
            ModelBinderAttribute attr = new ModelBinderAttribute(binderType);

            // Act
            IModelBinder binder = attr.GetBinder();

            // Assert
            Assert.IsInstanceOfType(binder, binderType);
        }
コード例 #3
0
        public void GetBinderWithBadConstructorThrows() {
            // Arrange
            Type binderType = typeof(BadConverter);
            ModelBinderAttribute attr = new ModelBinderAttribute(binderType);

            // Act & Assert
            ExceptionHelper.ExpectInvalidOperationException(
                delegate {
                    attr.GetBinder();
                },
                "An error occurred when trying to create the IModelBinder 'System.Web.Mvc.Test.ModelBinderAttributeTest+BadConverter'. Make sure that the binder has a public parameterless constructor.");
        }
コード例 #4
0
        public void GetBinderWithBadConstructorThrows() {
            // Arrange
            Type binderType = typeof(BadConverter);
            ModelBinderAttribute attr = new ModelBinderAttribute(binderType);

            // Act & Assert
            ExceptionHelper.ExpectInvalidOperationException(
                delegate {
                    attr.GetBinder();
                },
                "There was an error creating the IModelBinder 'System.Web.Mvc.Test.ModelBinderAttributeTest+BadConverter'."
                + " Check that it has a public parameterless constructor.");
        }