当前位置: 首页>>代码示例>>C#>>正文


C# ModelBinderDictionary.GetBinder方法代码示例

本文整理汇总了C#中ModelBinderDictionary.GetBinder方法的典型用法代码示例。如果您正苦于以下问题:C# ModelBinderDictionary.GetBinder方法的具体用法?C# ModelBinderDictionary.GetBinder怎么用?C# ModelBinderDictionary.GetBinder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ModelBinderDictionary的用法示例。


在下文中一共展示了ModelBinderDictionary.GetBinder方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetBinderDoesNotReturnDefaultBinderIfAskedNotTo

        public void GetBinderDoesNotReturnDefaultBinderIfAskedNotTo() {
            // Proper order of precedence:
            // 1. Binder registered in the global table
            // 2. Binder attribute defined on the type
            // 3. <null>

            // Arrange
            IModelBinder registeredFirstBinder = new Mock<IModelBinder>().Object;
            ModelBinderDictionary binders = new ModelBinderDictionary() {
                { typeof(MyFirstConvertibleType), registeredFirstBinder }
            };

            // Act
            IModelBinder binder1 = binders.GetBinder(typeof(MyFirstConvertibleType), false /* fallbackToDefault */);
            IModelBinder binder2 = binders.GetBinder(typeof(MySecondConvertibleType), false /* fallbackToDefault */);
            IModelBinder binder3 = binders.GetBinder(typeof(object), false /* fallbackToDefault */);

            // Assert
            Assert.AreSame(registeredFirstBinder, binder1, "First binder should have been matched in the registered binders table.");
            Assert.IsInstanceOfType(binder2, typeof(MySecondBinder), "Second binder should have been matched on the type.");
            Assert.IsNull(binder3, "Third binder should have returned null since asked not to use default.");
        }
开发者ID:consumentor,项目名称:Server,代码行数:22,代码来源:ModelBinderDictionaryTest.cs

示例2: GetBinderConsultsProviders

        public void GetBinderConsultsProviders() {

            //Arrange
            Type modelType = typeof(string);
            IModelBinder expectedBinderFromProvider = new Mock<IModelBinder>().Object;

            Mock<IModelBinderProvider> locatedProvider = new Mock<IModelBinderProvider>();
            locatedProvider.Setup(p => p.GetBinder(modelType))
                .Returns(expectedBinderFromProvider);

            Mock<IModelBinderProvider> secondProvider = new Mock<IModelBinderProvider>();

            ModelBinderProviderCollection providers = new ModelBinderProviderCollection(new IModelBinderProvider[] { locatedProvider.Object, secondProvider.Object });
            ModelBinderDictionary binders = new ModelBinderDictionary(providers);

            //Act
            IModelBinder returnedBinder = binders.GetBinder(modelType);

            //Assert
            Assert.AreSame(expectedBinderFromProvider, returnedBinder);
        }
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:21,代码来源:ModelBinderDictionaryTest.cs

示例3: GetBinderThrowsIfModelTypeContainsMultipleAttributes

        public void GetBinderThrowsIfModelTypeContainsMultipleAttributes() {
            // Arrange
            ModelBinderDictionary binders = new ModelBinderDictionary();

            // Act & Assert
            ExceptionHelper.ExpectInvalidOperationException(
                delegate {
                    binders.GetBinder(typeof(ConvertibleTypeWithSeveralBinders), true /* fallbackToDefault */);
                },
                "The type 'System.Web.Mvc.Test.ModelBinderDictionaryTest+ConvertibleTypeWithSeveralBinders' contains multiple attributes that inherit from CustomModelBinderAttribute.");
        }
开发者ID:consumentor,项目名称:Server,代码行数:11,代码来源:ModelBinderDictionaryTest.cs

示例4: GetBinderResolvesBindersWithCorrectPrecedence

        public void GetBinderResolvesBindersWithCorrectPrecedence() {
            // Proper order of precedence:
            // 1. Binder registered in the global table
            // 2. Binder attribute defined on the type
            // 3. Default binder

            // Arrange
            IModelBinder registeredFirstBinder = new Mock<IModelBinder>().Object;
            ModelBinderDictionary binders = new ModelBinderDictionary() {
                { typeof(MyFirstConvertibleType), registeredFirstBinder }
            };

            IModelBinder defaultBinder = new Mock<IModelBinder>().Object;
            binders.DefaultBinder = defaultBinder;

            // Act
            IModelBinder binder1 = binders.GetBinder(typeof(MyFirstConvertibleType));
            IModelBinder binder2 = binders.GetBinder(typeof(MySecondConvertibleType));
            IModelBinder binder3 = binders.GetBinder(typeof(object));

            // Assert
            Assert.AreSame(registeredFirstBinder, binder1, "First binder should have been matched in the registered binders table.");
            Assert.IsInstanceOfType(binder2, typeof(MySecondBinder), "Second binder should have been matched on the type.");
            Assert.AreSame(defaultBinder, binder3, "Third binder should have been the fallback.");
        }
开发者ID:consumentor,项目名称:Server,代码行数:25,代码来源:ModelBinderDictionaryTest.cs

示例5: GetBinderThrowsIfModelTypeIsNull

        public void GetBinderThrowsIfModelTypeIsNull() {
            // Arrange
            ModelBinderDictionary binders = new ModelBinderDictionary();

            // Act & Assert
            ExceptionHelper.ExpectArgumentNullException(
                delegate {
                    binders.GetBinder(null);
                }, "modelType");
        }
开发者ID:consumentor,项目名称:Server,代码行数:10,代码来源:ModelBinderDictionaryTest.cs

示例6: GetBinderDoesNotReturnDefaultBinderIfAskedNotTo

        public void GetBinderDoesNotReturnDefaultBinderIfAskedNotTo()
        {
            // Proper order of precedence:
            // 1. Binder registered in the global table
            // 2. Binder attribute defined on the type
            // 3. <null>

            // Arrange
            IModelBinder registeredFirstBinder = new Mock<IModelBinder>().Object;
            ModelBinderDictionary binders = new ModelBinderDictionary()
            {
                { typeof(MyFirstConvertibleType), registeredFirstBinder }
            };

            // Act
            IModelBinder binder1 = binders.GetBinder(typeof(MyFirstConvertibleType), false /* fallbackToDefault */);
            IModelBinder binder2 = binders.GetBinder(typeof(MySecondConvertibleType), false /* fallbackToDefault */);
            IModelBinder binder3 = binders.GetBinder(typeof(object), false /* fallbackToDefault */);

            // Assert
            Assert.Same(registeredFirstBinder, binder1);
            Assert.IsType<MySecondBinder>(binder2);
            Assert.Null(binder3);
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:24,代码来源:ModelBinderDictionaryTest.cs

示例7: GetBinderThrowsIfModelTypeIsNull

        public void GetBinderThrowsIfModelTypeIsNull()
        {
            // Arrange
            ModelBinderDictionary binders = new ModelBinderDictionary();

            // Act & Assert
            Assert.ThrowsArgumentNull(
                delegate { binders.GetBinder(null); }, "modelType");
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:9,代码来源:ModelBinderDictionaryTest.cs

示例8: GetBinderResolvesBindersWithCorrectPrecedence

        public void GetBinderResolvesBindersWithCorrectPrecedence()
        {
            // Proper order of precedence:
            // 1. Binder registered in the global table
            // 2. Binder attribute defined on the type
            // 3. Default binder

            // Arrange
            IModelBinder registeredFirstBinder = new Mock<IModelBinder>().Object;
            ModelBinderDictionary binders = new ModelBinderDictionary()
            {
                { typeof(MyFirstConvertibleType), registeredFirstBinder }
            };

            IModelBinder defaultBinder = new Mock<IModelBinder>().Object;
            binders.DefaultBinder = defaultBinder;

            // Act
            IModelBinder binder1 = binders.GetBinder(typeof(MyFirstConvertibleType));
            IModelBinder binder2 = binders.GetBinder(typeof(MySecondConvertibleType));
            IModelBinder binder3 = binders.GetBinder(typeof(object));

            // Assert
            Assert.Same(registeredFirstBinder, binder1);
            Assert.IsType<MySecondBinder>(binder2);
            Assert.Same(defaultBinder, binder3);
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:27,代码来源:ModelBinderDictionaryTest.cs


注:本文中的ModelBinderDictionary.GetBinder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。